-
Notifications
You must be signed in to change notification settings - Fork 0
/
strassen.java
executable file
·108 lines (103 loc) · 2.68 KB
/
strassen.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import java.util.*;
import java.io.*;
public class strassen
{
public static void main(String[] args){
int flag = Integer.parseInt(args[0]);
int dimension = Integer.parseInt(args[1]);
String input = args[2];
int[][] matrix_A = new int[dimension][dimension];
int[][] matrix_B = new int[dimension][dimension];
boolean isA = true;
//load arrays with input
File inFile = new File(input);
//flags indicate the dimensions (and randomly generated matricies) we used to experimentally find the cross-over point
if(flag == 1){
//2000x2000
Random rand = new Random(System.currentTimeMillis());
try{
FileWriter fw = new FileWriter("input1.txt");
int val = -1;
for(int i = 0; i < 8000000; i++)
{
val = rand.nextInt(2);
fw.write(val + "\n");
}
fw.close();
}
catch(IOException e){
System.out.println("Error");
}
inFile = new File("input1.txt");
}
else if(flag == 2){
//1500x1500
Random rand = new Random(System.currentTimeMillis());
try{
FileWriter fw = new FileWriter("input2.txt");
int val = -1;
for(int i = 0; i < 4500000; i++)
{
val = rand.nextInt(2);
fw.write(val + "\n");
}
fw.close();
}
catch(IOException e){
System.out.println("Error");
}
inFile = new File("input2.txt");
}
else if(flag == 3){
//1000x1000
Random rand = new Random(System.currentTimeMillis());
try{
FileWriter fw = new FileWriter("input3.txt");
int val = -1;
for(int i = 0; i < 2000000; i++)
{
val = rand.nextInt(2);
fw.write(val + "\n");
}
fw.close();
}
catch(IOException e){
System.out.println("Error");
}
inFile = new File("input3.txt");
}
try(Scanner stdin = new Scanner(inFile);){
for(int z = 0; z < 2; z++)
{
for(int x = 0; x < dimension; x++){
for(int y = 0; y < dimension; y++){
if(isA)
matrix_A[x][y] = Integer.parseInt(stdin.next());
else
matrix_B[x][y] = Integer.parseInt(stdin.next());
}
}
isA = false;
}
} catch(FileNotFoundException e){
System.out.println ("File not Found");
}
//code used to find the graphs included in the write-up
/*
long startTime = -1;
long endTime = -1;
long duration = -1;
for(int x = 20; x<500; x+= 5){
startTime = System.nanoTime();
endTime = System.nanoTime();
duration = (endTime - startTime);
System.out.print(duration + "\n");
}*/
//set the cross-over point to be the middle of the plateau as mentioned in the write-up
matrixMult s = new matrixMult(dimension, 116);
int[][] result = s.strassenMultiply(matrix_A, matrix_B, dimension);
for(int x = 0; x < dimension; x++){
System.out.println(result[x][x]);
}
}
}