/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ /* ******** *** SparseLib++ */ /* ******* ** *** *** *** v. 1.5c */ /* ***** *** ******** ******** */ /* ***** *** ******** ******** R. Pozo */ /* ** ******* *** ** *** *** K. Remington */ /* ******** ******** A. Lumsdaine */ /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ /* */ /* */ /* SparseLib++ : Sparse Matrix Library */ /* */ /* National Institute of Standards and Technology */ /* University of Notre Dame */ /* Authors: R. Pozo, K. Remington, A. Lumsdaine */ /* */ /* NOTICE */ /* */ /* Permission to use, copy, modify, and distribute this software and */ /* its documentation for any purpose and without fee is hereby granted */ /* provided that the above notice appear in all copies and supporting */ /* documentation. */ /* */ /* Neither the Institutions (National Institute of Standards and Technology, */ /* University of Notre Dame) nor the Authors make any representations about */ /* the suitability of this software for any purpose. This software is */ /* provided ``as is'' without expressed or implied warranty. */ /* */ /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ #include #include "compcol_double.h" #include "comprow_double.h" #include "coord_double.h" #include "iohb_double.h" #include // spˇcific mac : GR #include // spˇcific mac : GR int main(int argc, char * argv[]) { argc = ccommand( &argv ); // spˇcific mac : GR if (argc < 2) { cerr << "Usage: " << argv[0] << " HBfile [-v]" << endl; exit(-1); } int verbose = 0; if (argc > 2 ) { if (argv[2][1] == 'v') verbose = 1; else { cerr << "Usage: " << argv[0] << " HBfile [-v]" << endl; exit(-1); } } /******************************************************************/ // Testing readHB functions... // /******************************************************************/ if (verbose) cout << "Testing readHB functions:" << endl << endl; CompCol_Mat_double A1; int M, N, nonzeros, nrhs; readHB_info(argv[1], &M, &N, &nonzeros, &nrhs); if (verbose) { cout << "Return values from readHB_info:" << endl; cout << "M = " << M << " N = " << N ; cout << " Nonzeros = " << nonzeros << " Nrhs = " << nrhs << endl; cout << "Output from readHB_info in verbose mode: " << endl; cout << "......................................................"< 0) { if (verbose) cout << "Reading a rhs from " << argv[1] << "..." << endl << endl; VECTOR_double b(N); readHB_rhs(argv[1], &b); } /******************************************************************/ // Generate small test matrix for testing conversions... // // // // [ 1 2 0 0 3 ] // // // // | 4 5 6 0 0 | // // // // | 0 7 8 0 9 | // // // // | 0 0 0 10 0 | // // // // [ 11 0 0 0 12 ] // // // /******************************************************************/ double val[12] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0}; int colind[12] = {0, 1, 4, 0, 1, 2, 1, 2, 4, 3, 0, 4}; int rowptr[6] = { 0, 3, 6, 9,10, 12}; double rowsum[5] = {6.0, 15.0, 24.0, 10.0, 23.0}; double colsum[5] = {16.0, 14.0, 14.0, 10.0, 24.0}; CompRow_Mat_double R(5,5,12,val,rowptr,colind); if (verbose) { cout << "Generated row-oriented matrix from data." << endl; cout << "Converting: Row to Column... " << endl; } CompCol_Mat_double C(R); if (verbose) cout << " Column to Coord... " << endl; Coord_Mat_double CO1(C); if (verbose) cout << " Coord to Row... " << endl; CompRow_Mat_double R2(CO1); double err = 0.0; int i,j; for (i=0;i<5;i++) for (j=0;j<5;j++) if ( (R2(i,j) - R(i,j)) < 0) err -= R2(i,j) - R(i,j); else err += R2(i,j) - R(i,j); if ( err > 1.e-8 ) { cout << "Error in conversions too high. Halting execution. " << endl; exit(1); } if (verbose) { cout << "Accumulated error = " << err << " success. " << endl; cout << "Reverse direction..." << endl; cout << "Converting: Row to Coord... " << endl; } Coord_Mat_double CO2(R); if (verbose) cout << " Coord to Column... " << endl; CompCol_Mat_double C2(CO2); if (verbose) cout << " Column to Row... " << endl; CompRow_Mat_double R3(C2); err = 0.0; for (i=0;i<5;i++) for (j=0;j<5;j++) if ( (R3(i,j) - R(i,j)) < 0) err -= (R3(i,j) - R(i,j)); else err += (R3(i,j) - R(i,j)); if ( err > 1.e-8 ) { cout << "Error in conversions too high. Halting execution. " << endl; exit(1); } if (verbose) { cout << "Accumulated error = " << err << " success. " << endl; cout << endl; cout << "Testing sparse matrix - dense vector multiplies... " << endl; cout << "Small test matrix: " << endl; } VECTOR_double x(5,0.0); VECTOR_double v(5,1.0); if (verbose) cout << "Mat-vec (CompCol)... "; x = C*v; for (i=0;i<5;i++) if (x(i) != rowsum[i]) { cout << "Mat-vec (Compcol) error." < 1.e-5 ) { cout << endl << "Error in Matvecs on HB generated matrix. " << endl; exit(1); } err = 0.0; for (i=0;i 1.e-5 ) { cout << endl << "Error in Matvecs on HB generated matrix. " << endl; exit(1); } if (verbose) cout << "success. " << endl; v1 = 0.0; x1 = 1.0; if (verbose) cout << "Mat-trans-vec (CompCol)... "<< endl; v1 = A1.trans_mult(x1); VECTOR_double v2(N,0.0); if (verbose) cout << "Mat-trans-vec (CompRow)... "<< endl; v2 = A2.trans_mult(x1); VECTOR_double v3(N,0.0); if (verbose) cout << "Mat-trans-vec (Coord)... "<< endl; v3 = A3.trans_mult(x1); if (verbose) cout << "Comparing results... "; err = 0.0; for (i=0;i 1.e-5 ) { cout << endl << "Error in Mat-tran_mult-vecs on HB generated matrix. " << endl; exit(1); } err = 0.0; for (i=0;i 1.e-5 ) { cout << endl << "Error in Mat-tran_mult-vecs on HB generated matrix. " << endl; exit(1); } if (verbose) cout << "success. " << endl; cout << endl << endl; cout << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << endl; cout << "+ Successful completion of testing for SparseLib++ +" << endl; cout << "+ No errors detected in conversion or blas routines. +" << endl; cout << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << endl; cout << endl << endl; }