11 #include "timer.gettimeofday.c"
24 #define INDEXTYPE uint32_t
25 #ifdef SINGLEPRECISION
26 #define VALUETYPE float
28 #define VALUETYPE double
32 int main(
int argc,
char* argv[])
35 int gl_nworkers = __cilkrts_get_nworkers();
39 bool syminput =
false;
42 INDEXTYPE m = 0, n = 0, nnz = 0, forcelogbeta = 0;
46 cout <<
"Normal usage: ./a.out inputmatrix.mtx sym/nosym binary/text triples/csc" << endl;
47 cout <<
"Assuming matrix.txt is the input, matrix is unsymmetric, and stored in text(ascii) file" << endl;
48 inputname =
"matrix.txt";
52 cout <<
"Normal usage: ./a.out inputmatrix.mtx sym/nosym binary/text triples/csc" << endl;
53 cout <<
"Assuming that the matrix is unsymmetric, and stored in text(ascii) file" << endl;
58 cout <<
"Normal usage: ./a.out inputmatrix.mtx sym/nosym binary/text triples/csc" << endl;
59 cout <<
"Assuming matrix is stored in text(ascii) file" << endl;
61 string issym(argv[2]);
64 else if(issym ==
"nosym")
67 cout <<
"unrecognized option, assuming nosym" << endl;
72 string issym(argv[2]);
75 else if(issym ==
"nosym")
78 cout <<
"unrecognized option, assuming unsymmetric" << endl;
80 string isbinary(argv[3]);
81 if(isbinary ==
"text")
83 else if(isbinary ==
"binary")
86 cout <<
"unrecognized option, assuming text file" << endl;
94 cout <<
"Processing CSC binary" << endl;
99 forcelogbeta = atoi(argv[5]);
106 FILE * f = fopen(inputname.c_str(),
"r");
109 cerr <<
"Problem reading binary input file\n";
124 if (m <= 0 || n <= 0 || nnz <= 0)
126 cerr <<
"Problem with matrix size in binary input file\n";
130 cout <<
"Reading matrix with dimensions: "<< m <<
"-by-" << n <<
" having "<< nnz <<
" nonzeros" << endl;
138 size_t cols = fread(colpointers,
sizeof(
INDEXTYPE), n+1, f);
141 cerr <<
"Problem with FREAD, aborting... " << endl;
148 size_t cols = fread(colindices,
sizeof(
INDEXTYPE), nnz, f);
151 cerr <<
"Problem with FREAD, aborting... " << endl;
155 size_t rows = fread(rowindices,
sizeof(
INDEXTYPE), nnz, f);
156 size_t nums = fread(vals,
sizeof(
VALUETYPE), nnz, f);
158 if(rows != nnz || nums != nnz)
160 cerr <<
"Problem with FREAD, aborting... " << endl;
164 cout<<
"Reading matrix in binary took " << ((
VALUETYPE) (tend-tstart)) /1000 <<
" seconds" <<endl;
169 csc->
SetPointers(colpointers, rowindices, vals , nnz, m, n,
true);
175 delete [] colindices;
176 delete [] rowindices;
182 cout <<
"reading input matrix in text(ascii)... " << endl;
183 ifstream infile(inputname.c_str());
185 char c = infile.get();
188 infile.getline(line,256);
192 infile >> m >> n >> nnz;
197 if (infile.is_open())
200 while (! infile.eof() && cnz < nnz)
202 infile >> triples[cnz].
row >> triples[cnz].
col >> triples[cnz].
val;
210 cout<<
"Reading matrix in ascii took " << ((double) (tend-tstart)) /1000 <<
" seconds" <<endl;
212 cout <<
"converting to csc ... " << endl;
217 cout <<
"# workers: "<< gl_nworkers << endl;
221 cout <<
"generating vectors... " << endl;
229 cout <<
"starting SpMV ... " << endl;
230 cout <<
"Row imbalance is: " <<
RowImbalance(bicsb) << endl;
231 cout <<
"Col imbalance is: " <<
ColImbalance(bicsb) << endl;
234 bicsb_gespmv<PTDD>(bicsb, x.
getarr(), y_bicsb.
getarr());
235 double t0 = timer_seconds_since_init();
236 for(
int i=0; i <
REPEAT; ++i)
238 bicsb_gespmv<PTDD>(bicsb, x.
getarr(), y_bicsb.
getarr());
240 double t1 = timer_seconds_since_init();
242 double time = (t1-t0)/REPEAT;
243 cout<<
"BiCSB" <<
" time: " << time <<
" seconds" <<endl;
244 cout<<
"BiCSB" <<
" mflop/sec: " << flops / (1000000 * time) <<endl;
248 cout <<
"starting SpMV_T" << endl;
256 bicsb_gespmvt<PTDD>(bicsb, xt.
getarr(), yt_bicsb.
getarr());
257 t0 = timer_seconds_since_init();
258 for(
int i=0; i <
REPEAT; ++i)
260 bicsb_gespmvt<PTDD>(bicsb, xt.
getarr(), yt_bicsb.
getarr());
262 t1 = timer_seconds_since_init();
264 time = (t1-t0)/REPEAT;
265 cout<<
"BiCSB Trans" <<
" time: " << time <<
" seconds" <<endl;
266 cout<<
"BiCSB Trans" <<
" mflop/sec: " << flops / (1000000 * time) <<endl;
270 t0 = timer_seconds_since_init();
271 for(
int i=0; i <
REPEAT; ++i)
275 t1 = timer_seconds_since_init();
276 double csctime = (t1-t0)/REPEAT;
277 cout<<
"CSC" <<
" time: " << csctime <<
" seconds" <<endl;
278 cout<<
"CSC" <<
" mflop/sec: " << flops / (1000000 * csctime) <<endl;
280 Verify(y_csc, y_bicsb,
"BiCSB", m);
285 t0 = timer_seconds_since_init();
286 for(
int i=0; i <
REPEAT; ++i)
290 t1 = timer_seconds_since_init();
291 time = (t1-t0)/REPEAT;
292 cout <<
"Transposed CSC time: " << time <<
" seconds" << endl;
293 cout <<
"Transposed CSC mflop/sec: " << flops/ (1000000 * time) << endl;
295 Verify(yt_csc, yt_bicsb,
"BiCSB", n);
int main(int argc, char *argv[])
float ColImbalance(const BiCsb< NT, IT > &A)
void Verify(Spvec< NT, IT > &control, Spvec< NT, IT > &test, string name, IT m)
float RowImbalance(const CSB &A)
void SetPointers(ITYPE *colpointers, ITYPE *rowindices, T *vals, ITYPE size, ITYPE rows, ITYPE cols, bool fortran)
void csc_gaxpy_trans(const Csc< T, ITYPE > &A, T *x, T *y)