COMBINATORIAL_BLAS 1.6
 
Loading...
Searching...
No Matches
Driver.cpp
Go to the documentation of this file.
1#include <iostream>
2#include <fstream>
3#include <mpi.h>
4#include <sys/time.h>
5#include "../SpTuples.h"
6#include "../SpDCCols.h"
7#include "../SpParMat.h"
8
9using namespace std;
10using namespace combblas;
11
12int main()
13{
15 int nprocs, myrank;
19
20 if (myrank == 0)
21 {
22 ifstream inputa("matrixA.txt");
23 ifstream inputb("matrixB.txt");
24 if(!(inputa.is_open() && inputb.is_open()))
25 {
26 cerr << "One of the input files doesn't exist\n";
27 exit(-1);
28 }
29
31 inputa >> A;
32 A.PrintInfo();
33
35 inputb >> B;
36 B.PrintInfo();
37
38 // arguments (in this order): nnz, n, m, nzc
39 SpDCCols<int,double> C(0, A.getnrow(), B.getncol(), 0);
40 C.PrintInfo();
41
42 C.SpGEMM <PT> (A, B, false, false); // C = A*B
43 C.PrintInfo();
44
46 A_bool.PrintInfo();
47
48 SpTuples<int,double> * C_tuples = MultiplyReturnTuples<PT>(A_bool, B, false, false); // D = A_bool*B
49 C_tuples->PrintInfo();
50
52 C_tt->PrintInfo();
53
55 tomerge.push_back(C_tuples);
56 tomerge.push_back(C_tt);
57
59 twice.PrintInfo();
60
61 delete C_tuples;
62 delete C_tt;
63 }
64 #define BIGTEST
65 //#define MASSIVETEST
66 //#define OUTPUT
67
68 // Start big timing test
70
71 #ifdef BIGTEST
72 prefixes.push_back("largeseq");
73 #endif
74 #ifdef MASSIVETEST
75 prefixes.push_back("massiveseq");
76 #endif
77
78 for(int i=0; i< prefixes.size(); i++)
79 {
81 if(myrank == 0)
82 {
83 string inputname1 = prefixes[i] + string("/input1_0");
84 string inputname2 = prefixes[i] + string("/input2_0");
85 input1.open(inputname1.c_str());
86 input2.open(inputname2.c_str());
87 if(!(input1.is_open() && input2.is_open()))
88 {
89 cerr << "One of the input files doesn't exist\n";
90 exit(-1);
91 }
93 input1 >> bigA;
94 bigA.PrintInfo();
95
97 bigA.Split(bigA1, bigA2);
98 bigA1.PrintInfo();
99 bigA2.PrintInfo();
100
101 bigA.Merge(bigA1, bigA2);
102 bigA.PrintInfo();
103
105 input2 >> bigB;
106 bigB.PrintInfo();
107
108 // Cache warm-up
110 bigC->PrintInfo();
111
112 #ifdef OUTPUT
113 string outputnameC = prefixes[i] + string("/colbycol");
115 outputC << (*bigC);
116 outputC.close();
117 #endif
118 struct timeval tempo1, tempo2;
119
120 double elapsed_time; /* elapsed time in seconds */
121 long elapsed_seconds; /* diff between seconds counter */
122 long elapsed_useconds; /* diff between microseconds counter */
123
125 bigC = MultiplyReturnTuples<PT>(bigA, bigB, false, false);
127 elapsed_seconds = tempo2.tv_sec - tempo1.tv_sec;
128 elapsed_useconds = tempo2.tv_usec - tempo1.tv_usec;
129
131 printf("ColByCol time = %.5f seconds\n", elapsed_time);
132
133 bigB.Transpose(); // now that bigB is transposed, bigC_t will be equal to bigC
134 bigB.PrintInfo();
135
136 // Cache warm-up
138 bigC_t->PrintInfo();
139
140 #ifdef OUTPUT
141 string outputnameCT = prefixes[i] + string("/outerproduct");
143 outputCT << (*bigC_t);
144 outputCT.close();
145 #endif
146
148 bigC_t = MultiplyReturnTuples<PT>(bigA, bigB, false, true);
150 elapsed_seconds = tempo2.tv_sec - tempo1.tv_sec;
151 elapsed_useconds = tempo2.tv_usec - tempo1.tv_usec;
152
154 printf("OuterProduct time = %.5f seconds\n", elapsed_time);
155
156 input1.seekg (0, ios::beg);
157 input2.seekg (0, ios::beg);
158
160 tomerge.push_back(bigC);
161 tomerge.push_back(bigC_t);
162
164 twice.PrintInfo();
165 delete bigC;
166 delete bigC_t;
167
168 #ifdef OUTPUT
169 string outputnametwice = prefixes[i] + string("/twice");
171 outputtw << twice;
172 outputtw.close();
173 #endif
174 cerr << "Begin Parallel" << endl;
175 }
176 // ABAB: Make a macro such as "PARTYPE(it,nt,seqtype)" that just typedefs this guy !
180 cerr << "A and B constructed"<< endl;
181
182 A_par.ReadDistribute(input1, 0);
183
184 // collective calls
185 int parnnzA = A_par.getnnz();
186 int parmA = A_par.getnrow();
187 int parnA = A_par.getncol();
188 if(myrank == 0)
189 cout << "A_par has " << parnnzA << " nonzeros and " << parmA << "-by-" << parnA << " dimensions" << endl;
190
191 B_par.ReadDistribute(input2, 0);
192
193 int parnnzB = B_par.getnnz();
194 int parmB = B_par.getnrow();
195 int parnB = B_par.getncol();
196
197 if(myrank == 0)
198 cout << "B_par has " << parnnzB << " nonzeros and " << parmB << "-by-" << parnB << " dimensions" << endl;
199
201
202 // collective calls
203 int parnnzC = C_par.getnnz();
204 int parmC = C_par.getnrow();
205 int parnC = C_par.getncol();
206
207 if(myrank == 0)
208 {
209 cout << "C_par has " << parnnzC << " nonzeros and " << parmC << "-by-" << parnC << " dimensions" << endl;
210 input1.close();
211 input2.close();
212 }
213 }
214 MPI_Finalize();
215}
int main()
Definition Driver.cpp:12
Definition test.cpp:53
int nprocs
Definition comms.cpp:55
double A
double C
Definition options.h:15