11 #include "timer.gettimeofday.c"
24 #define INDEXTYPE uint32_t
25 #ifdef SINGLEPRECISION
26 #define VALUETYPE float
28 #define VALUETYPE double
37 int main(
int argc,
char* argv[])
40 int gl_nworkers = __cilkrts_get_nworkers();
44 bool syminput =
false;
47 INDEXTYPE m = 0, n = 0, nnz = 0, forcelogbeta = 0;
51 cout <<
"Normal usage: ./a.out inputmatrix.mtx sym/nosym binary/text triples/csc" << endl;
52 cout <<
"Assuming matrix.txt is the input, matrix is unsymmetric, and stored in text(ascii) file" << endl;
53 inputname =
"matrix.txt";
57 cout <<
"Normal usage: ./a.out inputmatrix.mtx sym/nosym binary/text triples/csc" << endl;
58 cout <<
"Assuming that the matrix is unsymmetric, and stored in text(ascii) file" << endl;
63 cout <<
"Normal usage: ./a.out inputmatrix.mtx sym/nosym binary/text triples/csc" << endl;
64 cout <<
"Assuming matrix is stored in text(ascii) file" << endl;
66 string issym(argv[2]);
69 else if(issym ==
"nosym")
72 cout <<
"unrecognized option, assuming nosym" << endl;
77 string issym(argv[2]);
80 else if(issym ==
"nosym")
83 cout <<
"unrecognized option, assuming unsymmetric" << endl;
85 string isbinary(argv[3]);
86 if(isbinary ==
"text")
88 else if(isbinary ==
"binary")
91 cout <<
"unrecognized option, assuming text file" << endl;
99 cout <<
"Processing CSC binary" << endl;
104 forcelogbeta = atoi(argv[5]);
111 FILE * f = fopen(inputname.c_str(),
"r");
114 cerr <<
"Problem reading binary input file\n";
129 if (m <= 0 || n <= 0 || nnz <= 0)
131 cerr <<
"Problem with matrix size in binary input file\n";
135 cout <<
"Reading matrix with dimensions: "<< m <<
"-by-" << n <<
" having "<< nnz <<
" nonzeros" << endl;
143 size_t cols = fread(colpointers,
sizeof(
INDEXTYPE), n+1, f);
146 cerr <<
"Problem with FREAD, aborting... " << endl;
153 size_t cols = fread(colindices,
sizeof(
INDEXTYPE), nnz, f);
156 cerr <<
"Problem with FREAD, aborting... " << endl;
160 size_t rows = fread(rowindices,
sizeof(
INDEXTYPE), nnz, f);
161 size_t nums = fread(vals,
sizeof(
VALUETYPE), nnz, f);
163 if(rows != nnz || nums != nnz)
165 cerr <<
"Problem with FREAD, aborting... " << endl;
169 cout<<
"Reading matrix in binary took " << ((
VALUETYPE) (tend-tstart)) /1000 <<
" seconds" <<endl;
174 csc->
SetPointers(colpointers, rowindices, vals , nnz, m, n,
true);
180 delete [] colindices;
181 delete [] rowindices;
187 cout <<
"reading input matrix in text(ascii)... " << endl;
188 ifstream infile(inputname.c_str());
190 char c = infile.get();
193 infile.getline(line,256);
197 infile >> m >> n >> nnz;
202 if (infile.is_open())
205 while (! infile.eof() && cnz < nnz)
207 infile >> triples[cnz].
row >> triples[cnz].
col >> triples[cnz].
val;
215 cout<<
"Reading matrix in ascii took " << ((double) (tend-tstart)) /1000 <<
" seconds" <<endl;
217 cout <<
"converting to csc ... " << endl;
222 cout <<
"# workers: "<< gl_nworkers << endl;
228 ofstream stats(
"stats.txt");
235 cout <<
"generating vectors... " << endl;
243 cout <<
"starting SpMV ... " << endl;
244 cout <<
"Row imbalance is: " <<
RowImbalance(bicsb) << endl;
247 bicsb_gespmv<PTDD>(bicsb, x.
getarr(), y_bicsb.
getarr());
249 double t0 = timer_seconds_since_init();
250 for(
int i=0; i <
REPEAT; ++i)
252 bicsb_gespmv<PTDD>(bicsb, x.
getarr(), y_bicsb.
getarr());
254 double t1 = timer_seconds_since_init();
256 double time = (t1-t0)/REPEAT;
257 cout<<
"BiCSB" <<
" time: " << time <<
" seconds" <<endl;
258 cout<<
"BiCSB" <<
" mflop/sec: " << flops / (1000000 * time) <<endl;
262 cout <<
"starting SpMV with BmCSB ... " << endl;
263 cout <<
"Row imbalance is: " <<
RowImbalance(bmcsb) << endl;
269 t0 = timer_seconds_since_init();
270 for(
int i=0; i <
REPEAT; ++i)
274 t1 = timer_seconds_since_init();
276 double bmtime = ((t1-t0)/REPEAT) - (prescantime/
REPEAT);
277 cout<<
"BmCSB" <<
" time: " << bmtime <<
" seconds" <<endl;
278 cout<<
"BmCSB" <<
" mflop/sec: " << (flops *
UNROLL) / (1000000 * bmtime) <<endl;
281 transform(y_bmcsb.
getarr(), y_bmcsb.
getarr() + m, y_bmcsb.
getarr(), bind2nd(divides<double>(), static_cast<double>(
UNROLL)));
282 cout <<
"Mega register blocks per second: " << (bmcsb.
numregb() *
UNROLL) / (1000000 * bmtime) << endl;
284 cout<<
"Prescan time: " << (prescantime/
REPEAT) <<
" seconds" <<endl;
290 t0 = timer_seconds_since_init();
291 for(
int i=0; i <
REPEAT; ++i)
295 t1 = timer_seconds_since_init();
296 double csctime = (t1-t0)/REPEAT;
297 cout<<
"CSC" <<
" time: " << csctime <<
" seconds" <<endl;
298 cout<<
"CSC" <<
" mflop/sec: " << flops / (1000000 * csctime) <<endl;
300 Verify(y_csc, y_bicsb,
"BiCSB", m);
302 Verify(y_csc, y_bmcsb,
"BmCSB", m);
ofstream & PrintStats(ofstream &outfile) const
int main(int argc, char *argv[])
void Verify(Spvec< NT, IT > &control, Spvec< NT, IT > &test, string name, IT m)
void bmcsb_gespmv(const BmCsb< NT, IT, TTDIM > &A, const NT *__restrict x, NT *__restrict y)
float RowImbalance(const CSB &A)
void SetPointers(ITYPE *colpointers, ITYPE *rowindices, T *vals, ITYPE size, ITYPE rows, ITYPE cols, bool fortran)