COMBINATORIAL_BLAS 1.6
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{
14 MPI_Init(NULL,NULL);
15 int nprocs, myrank;
16 MPI_Comm_size(MPI_COMM_WORLD,&nprocs);
17 MPI_Comm_rank(MPI_COMM_WORLD,&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
45 SpDCCols<int,bool> A_bool = A;
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
51 SpTuples<int,double> * C_tt = MultiplyReturnTuples<PT>(B, A_bool, false, true);
52 C_tt->PrintInfo();
53
54 vector< SpTuples<int,double> *> tomerge;
55 tomerge.push_back(C_tuples);
56 tomerge.push_back(C_tt);
57
58 SpTuples<int,double> twice = MergeAll<PT>(tomerge);
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
69 vector<string> prefixes;
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 {
80 ifstream input1, input2;
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
96 SpDCCols<int,double> bigA1, bigA2;
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
109 SpTuples<int,double> * bigC = MultiplyReturnTuples<PT>(bigA, bigB, false, false);
110 bigC->PrintInfo();
111
112 #ifdef OUTPUT
113 string outputnameC = prefixes[i] + string("/colbycol");
114 ofstream outputC(outputnameC.c_str());
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
124 gettimeofday(&tempo1, NULL);
125 bigC = MultiplyReturnTuples<PT>(bigA, bigB, false, false);
126 gettimeofday(&tempo2, NULL);
127 elapsed_seconds = tempo2.tv_sec - tempo1.tv_sec;
128 elapsed_useconds = tempo2.tv_usec - tempo1.tv_usec;
129
130 elapsed_time = (elapsed_seconds + ((double) elapsed_useconds)/1000000.0);
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
137 SpTuples<int,double> * bigC_t = MultiplyReturnTuples<PT>(bigA, bigB, false, true);
138 bigC_t->PrintInfo();
139
140 #ifdef OUTPUT
141 string outputnameCT = prefixes[i] + string("/outerproduct");
142 ofstream outputCT(outputnameCT.c_str());
143 outputCT << (*bigC_t);
144 outputCT.close();
145 #endif
146
147 gettimeofday(&tempo1, NULL);
148 bigC_t = MultiplyReturnTuples<PT>(bigA, bigB, false, true);
149 gettimeofday(&tempo2, NULL);
150 elapsed_seconds = tempo2.tv_sec - tempo1.tv_sec;
151 elapsed_useconds = tempo2.tv_usec - tempo1.tv_usec;
152
153 elapsed_time = (elapsed_seconds + ((double) elapsed_useconds)/1000000.0);
154 printf("OuterProduct time = %.5f seconds\n", elapsed_time);
155
156 input1.seekg (0, ios::beg);
157 input2.seekg (0, ios::beg);
158
159 vector< SpTuples<int,double> *> tomerge;
160 tomerge.push_back(bigC);
161 tomerge.push_back(bigC_t);
162
163 SpTuples<int,double> twice = MergeAll<PT>(tomerge);
164 twice.PrintInfo();
165 delete bigC;
166 delete bigC_t;
167
168 #ifdef OUTPUT
169 string outputnametwice = prefixes[i] + string("/twice");
170 ofstream outputtw(outputnametwice.c_str());
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 !
178 PARSPMAT A_par;
179 PARSPMAT B_par;
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
200 PARSPMAT C_par = Mult_AnXBn_Synch<PT> (A_par, B_par);
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
void PrintInfo() const
Definition: SpDCCols.cpp:1440
void Merge(SpDCCols< IT, NT > &partA, SpDCCols< IT, NT > &partB)
Definition: SpDCCols.cpp:1195
void Transpose()
Mutator version, replaces the calling object.
Definition: SpDCCols.cpp:854
void Split(SpDCCols< IT, NT > &partA, SpDCCols< IT, NT > &partB)
Definition: SpDCCols.cpp:906
void ReadDistribute(const std::string &filename, int master, bool nonum, HANDLER handler, bool transpose=false, bool pario=false)
Definition: SpParMat.cpp:4211
int nprocs
Definition: comms.cpp:55
Definition: CCGrid.h:4
double A
double C
Definition: options.h:15
double B
Definition: options.h:15