80 const std::string& input_file_name,
81 std::vector<std::string>& filenames);
84 const std::string& input_file_name,
94 const std::string& input_file_name,
109 const std::string& filename,
110 bool do_FillComplete,
111 bool result_mtx_to_file=
false,
122 bool callFillComplete =
true,
123 bool symmetric =
true);
135 int main(
int argc,
char** argv) {
138 MPI_Init(&argc,&argv);
144 bool write_result_mtx =
false;
145 bool verbose =
false;
146 int write = 0, inp_specified = 0;
147 bool path_specified =
false;
148 std::string input_file;
149 bool input_file_specified =
false;
151 if (Comm.
MyPID()==0) {
152 for(
int ii=0; ii<argc; ++ii) {
153 if (!strcmp(
"-write_result", argv[ii])) write_result_mtx =
true;
154 if (!strcmp(
"-v", argv[ii])) verbose =
true;
155 if (!strcmp(
"-i", argv[ii])) {
156 input_file = argv[ii+1];
157 input_file_specified =
true;
159 if (!strcmp(
"-d",argv[ii])) {
161 path_specified =
true;
164 write = write_result_mtx ? 1 : 0;
165 inp_specified = input_file_specified ? 1 : 0;
168 MPI_Bcast(&write, 1, MPI_INT, 0, MPI_COMM_WORLD);
169 if (write) write_result_mtx =
true;
170 MPI_Bcast(&inp_specified, 1, MPI_INT, 0, MPI_COMM_WORLD);
171 if (inp_specified) input_file_specified =
true;
174 if (!path_specified) {
180 std::cout <<
"two_proc_test returned err=="<<err<<std::endl;
184 std::vector<std::string> filenames;
186 if (input_file_specified) {
187 filenames.push_back(std::string(input_file));
190 input_file =
"infiles";
191 std::cout <<
"specific input-file not specified, getting list of input-files from file 'infiles'." << std::endl;
195 if (path_specified) path_specified =
false;
196 path =
"./MatrixMatrix";
203 std::cout <<
"test_find_rows returned err=="<<err<<std::endl;
209 std::cout <<
"test_drumm1 returned err=="<<err<<std::endl;
213 for(
size_t i=0; i<filenames.size(); ++i) {
214 err =
run_test(Comm, filenames[i],
true, write_result_mtx, verbose);
216 err =
run_test(Comm, filenames[i],
false, write_result_mtx, verbose);
236 int global_err = err;
239 MPI_Allreduce(&err, &global_err, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
249 int localproc = Comm.
MyPID();
250 int numlocalrows = 2;
251 int numglobalrows = numprocs*numlocalrows;
252 Epetra_Map rowmap(numlocalrows*numprocs, 0, Comm);
256 int* cols =
new int[numglobalrows];
257 double*vals =
new double[numglobalrows];
259 for(
int j=0; j<numglobalrows; ++j) {
264 Epetra_Map colmap(-1, numglobalrows, cols, 0, Comm);
266 for(
int i=0; i<numlocalrows; ++i) {
267 int row = localproc*numlocalrows+i;
297 int offset = num_names;
298 if (offset >= alloc_len) {
299 int alloc_increment = 8;
300 const char** newlist =
new const char*[alloc_len+alloc_increment];
301 for(
int i=0; i<offset; ++i) {
302 newlist[i] = names[i];
306 alloc_len += alloc_increment;
307 for(
int i=offset; i<alloc_len; ++i) {
312 names[offset] = newname;
319 if (Comm.
NumProc() < 2)
return(0);
322 int len = name.size();
323 int localProc = Comm.
MyPID();
324 if (localProc == 0) {
325 MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
326 MPI_Bcast((
void*)name.c_str(), len+1, MPI_CHAR, 0, MPI_COMM_WORLD);
329 MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
330 name.resize(len+1,
' ');
331 MPI_Bcast((
void*)name.c_str(), len+1, MPI_CHAR, 0, MPI_COMM_WORLD);
339 const std::string& input_file_name,
340 std::vector<std::string>& filenames)
342 int local_err = 0, global_err = 0;
343 std::ifstream* infile = NULL;
344 int pathlen =
path.size();
346 if (Comm.
MyPID() == 0) {
347 std::string full_name =
path.empty() ? input_file_name :
path+
"/"+input_file_name;
349 infile =
new std::ifstream(full_name.c_str());
356 Comm.
SumAll(&local_err, &global_err, 1);
358 if (global_err != 0) {
363 if (Comm.
MyPID() == 0) {
364 const int linelen = 512;
367 std::ifstream& ifile = *infile;
368 while(!ifile.eof()) {
370 sprintf(line,
"%s/",
path.c_str());
371 ifile.getline(&(line[pathlen+1]), linelen);
374 ifile.getline(line, linelen);
380 if (strchr(line,
'#') == NULL) {
381 filenames.push_back(std::string(line));
385 int numfiles = filenames.size();
387 MPI_Bcast(&numfiles, 1, MPI_INT, 0, MPI_COMM_WORLD);
389 for(
int i=0; i<numfiles; ++i) {
398 MPI_Bcast(&numfiles, 1, MPI_INT, 0, MPI_COMM_WORLD);
400 filenames.resize(numfiles);
401 for(
int i=0; i<numfiles; ++i) {
410 const std::string& filename,
411 bool do_FillComplete,
412 bool result_mtx_to_file,
416 char AT[3]; AT[0] =
'^'; AT[1] =
'T'; AT[2] =
'\0';
418 char BT[3]; BT[0] =
'^'; BT[1] =
'T'; BT[2] =
'\0';
422 if(!Comm.
MyPID()) std::cout<<
"Testing: "<<filename<<std::endl;
425 B_file, transB, C_file);
427 std::cout <<
"Error, read_matrix_file_names returned " << err << std::endl;
431 if (!transA) AT[0] =
'\0';
432 if (!transB) BT[0] =
'\0';
434 int localProc = Comm.
MyPID();
436 if (localProc == 0 && verbose) {
437 std::cout <<
"Testing C=A"<<AT<<
"*B"<<BT<<
"; A:" << A_file
438 <<
", B:" << B_file <<
", C:" << C_file << std::endl;
450 err =
create_maps(Comm, A_file, A_row_map, A_col_map, A_range_map, A_domain_map);
452 std::cout <<
"create_maps A returned err=="<<err<<std::endl;
460 err =
create_maps(Comm, B_file, B_row_map, B_col_map, B_range_map, B_domain_map);
462 std::cout <<
"create_maps B returned err=="<<err<<std::endl;
466 err =
read_matrix(A_file, Comm, A_row_map, A_col_map,
467 A_range_map, A_domain_map, A);
469 std::cout <<
"read_matrix A returned err=="<<err<<std::endl;
473 err =
read_matrix(B_file, Comm, B_row_map, B_col_map,
474 B_range_map, B_domain_map, B);
476 std::cout <<
"read_matrix B returned err=="<<err<<std::endl;
487 if(C->Comm().MyPID()) printf(
"transA = %d transB = %d\n",(
int)transA,(int)transB);
491 std::cout <<
"err "<<err<<
" from MatrixMatrix::Multiply"<<std::endl;
495 if(!do_FillComplete) C->FillComplete(*domainMap,*rangeMap);
499 if (result_mtx_to_file) {
507 err =
create_maps(Comm, C_file, Cck_row_map, Cck_col_map,
508 Cck_range_map, Cck_domain_map);
510 std::cout <<
"create_maps C returned err=="<<err<<std::endl;
514 err =
read_matrix(C_file, Comm, Cck_row_map, Cck_col_map,
515 Cck_range_map, Cck_domain_map, C_check);
517 std::cout <<
"read_matrix C returned err=="<<err<<std::endl;
525 double inf_norm = C_check->
NormInf();
529 if (inf_norm < 1.e-13) {
530 if (localProc == 0 && verbose) {
531 std::cout <<
"Test Passed" << std::endl;
536 if (localProc == 0) {
537 std::cout <<
"Test Failed ("<<filename<<
"), inf_norm = " << inf_norm << std::endl;
540 std::cout <<
"C"<<std::endl;
541 std::cout << *C<<std::endl;
546 if(!Comm.
MyPID()) std::cout<<
"--Testing: Jacobi for same matrices"<<std::endl;
547 delete C;
delete C_check;
558 Dinv.PutScalar(omega);
572 if (inf_norm < 1.e-13) {
573 if (localProc == 0 && verbose) {
574 std::cout <<
"Jacobi Test Passed" << std::endl;
579 if (localProc == 0) {
580 std::cout <<
"Jacobi Test Failed ("<<filename<<
"), inf_norm = " << inf_norm << std::endl;
583 std::cout <<
"C"<<std::endl;
584 std::cout << *C<<std::endl;
608 delete Cck_range_map;
609 delete Cck_domain_map;
615 const std::string& input_file_name,
622 if (Comm.
MyPID()==0) {
623 std::ifstream infile(input_file_name.c_str());
625 std::cout <<
"error opening input file " << input_file_name << std::endl;
629 const int linelen = 512;
632 infile.getline(line, linelen);
634 if (strchr(line,
'#') == NULL) {
635 A_file =
path+
"/"+line;
639 infile.getline(line, linelen);
641 if (!strcmp(line,
"TRANSPOSE")) {
647 infile.getline(line, linelen);
649 if (strchr(line,
'#') == NULL) {
650 B_file =
path+
"/"+line;
654 infile.getline(line, linelen);
656 if (!strcmp(line,
"TRANSPOSE")) {
662 infile.getline(line, linelen);
664 if (strchr(line,
'#') == NULL) {
665 C_file =
path+
"/"+line;
673 int len = transA ? 1 : 0;
674 MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
675 len = transB ? 1 : 0;
676 MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
685 MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
686 transA = len==1 ?
true :
false;
687 MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
688 transB = len==1 ?
true :
false;
696 const std::string& input_file_name,
721 *rangemap, *domainmap, mat);
730 int thisproc = Comm.
MyPID();
734 if (numprocs != 2)
return(0);
738 int numGlobalRows = 2;
741 if (thisproc == 1) myrow = 7;
742 Epetra_Map rowmap(numGlobalRows, numMyRows, &myrow, 0, Comm);
746 int numGlobalCols = 10;
748 int* mycols =
new int[numGlobalCols];
750 for(i=0; i<numGlobalCols; ++i) {
754 Epetra_Map domainmap(numGlobalCols, numMyCols, &(mycols[thisproc*numMyCols]),
762 double* coefs =
new double[numGlobalCols];
763 for(i=0; i<numGlobalCols; ++i) {
767 int numCols = numGlobalCols - 2;
769 if (thisproc == 1) offset = 2;
774 &(mycols[thisproc*numMyCols]));
803 const int magic_num = 3000;
808 int localn = magic_num/Comm.
NumProc();
817 double start_time = timer.WallTime();
821 int globaln = localn*Comm.
NumProc();
823 std::cout <<
"size: " << globaln <<
"x"<<globaln<<
", C = A*A, time: "
824 << timer.WallTime()-start_time << std::endl;
829 start_time = timer.WallTime();
834 std::cout <<
"size: " << globaln <<
"x"<<globaln<<
", C = A*A, time: "
835 << timer.WallTime()-start_time <<
" (C already Filled)\n" <<std::endl;
842 start_time = timer.WallTime();
847 std::cout <<
"size: " << globaln <<
"x"<<globaln<<
", C = A*A^T, time: "
848 << timer.WallTime()-start_time << std::endl;
853 start_time = timer.WallTime();
858 std::cout <<
"size: " << globaln <<
"x"<<globaln<<
", C = A*A^T, time: "
859 << timer.WallTime()-start_time <<
" (C already Filled)\n" <<std::endl;
866 start_time = timer.WallTime();
871 std::cout <<
"size: " << globaln <<
"x"<<globaln<<
", C = A^T*A, time: "
872 << timer.WallTime()-start_time << std::endl;
877 start_time = timer.WallTime();
882 std::cout <<
"size: " << globaln <<
"x"<<globaln<<
", C = A^T*A, time: "
883 << timer.WallTime()-start_time <<
" (C already Filled)\n"<<std::endl;
890 start_time = timer.WallTime();
895 std::cout <<
"size: " << globaln <<
"x"<<globaln<<
", C = A^T*A^T, time: "
896 << timer.WallTime()-start_time << std::endl;
901 start_time = timer.WallTime();
906 std::cout <<
"size: " << globaln <<
"x"<<globaln<<
", C = A^T*A^T, time: "
907 << timer.WallTime()-start_time <<
" (C already Filled)\n" <<std::endl;
920 bool callFillComplete,
929 int global_num_rows = numProcs*local_n;
931 Epetra_Map rowmap(global_num_rows, local_n, 0, comm);
938 double negOne = -1.0;
940 double val_L = symmetric ? negOne : -0.5;
942 for (
int i=0; i<local_n; i++) {
943 int GlobalRow = matrix->
GRID(i);
944 int RowLess1 = GlobalRow - 1;
945 int RowPlus1 = GlobalRow + 1;
946 int RowLess5 = GlobalRow - 5;
947 int RowPlus5 = GlobalRow + 5;
948 int RowLess9 = GlobalRow - 9;
949 int RowPlus9 = GlobalRow + 9;
950 int RowLess24 = GlobalRow - 24;
951 int RowPlus24 = GlobalRow + 24;
952 int RowLess48 = GlobalRow - 48;
953 int RowPlus48 = GlobalRow + 48;
972 if (RowPlus1<global_num_rows) {
975 if (RowPlus5<global_num_rows) {
978 if (RowPlus9<global_num_rows) {
981 if (RowPlus24<global_num_rows) {
984 if (RowPlus48<global_num_rows) {
991 if (callFillComplete) {
994 std::cout <<
"create_epetra_matrix: error in matrix.FillComplete()"
1005 if (size != 2)
return 0;
1007 int rank = Comm.
MyPID();
1010 int numGlobalElements = 2;
1012 Epetra_Map emap(numGlobalElements, indexBase, Comm);
1019 std::vector<std::vector<double> > vals(numGlobalElements);
1020 vals[0].push_back(3); vals[0].push_back(4);
1021 vals[1].push_back(1); vals[1].push_back(2);
1023 std::vector<int> indices;
1024 indices.push_back(0); indices.push_back(1);
1026 for (
int row=0; row<numGlobalElements; ++row) {
1046 int test_result = 0;
1049 if (idx[0] == 0 && val[0] != 10.0) test_result = 1;
1050 if (idx[1] == 0 && val[1] != 10.0) test_result = 1;
1051 if (idx[0] == 1 && val[0] != 14.0) test_result = 1;
1052 if (idx[1] == 1 && val[1] != 14.0) test_result = 1;
1055 if (idx[0] == 0 && val[0] != 14.0) test_result = 1;
1056 if (idx[1] == 0 && val[1] != 14.0) test_result = 1;
1057 if (idx[0] == 1 && val[0] != 20.0) test_result = 1;
1058 if (idx[1] == 1 && val[1] != 20.0) test_result = 1;
1061 int global_test_result = 0;
1062 Comm.
SumAll(&test_result, &global_test_result, 1);
1064 return global_test_result;
int test_find_rows(Epetra_Comm &Comm)
bool MyGRID(int GRID_in) const
const Epetra_Map & RangeMap() const
int ExtractGlobalRowCopy(int_type Row, int Length, int &NumEntries, double *values, int_type *Indices) const
bool SameAs(const Epetra_BlockMap &Map) const
Epetra_CrsMatrix * create_epetra_crsmatrix(int numProcs, int localProc, int local_n, bool callFillComplete=true, bool symmetric=true)
virtual int InsertGlobalValues(int GlobalRow, int NumEntries, const double *Values, const int *Indices)
static int Multiply(const Epetra_CrsMatrix &A, bool transposeA, const Epetra_CrsMatrix &B, bool transposeB, Epetra_CrsMatrix &C, bool call_FillComplete_on_result=true, bool keep_all_hard_zeros=false)
Given Epetra_CrsMatrix objects A, B and C, form the product C = A*B.
int time_matrix_matrix_multiply(Epetra_Comm &Comm, bool verbose)
virtual void Barrier() const =0
int two_proc_test(Epetra_Comm &Comm, bool verbose=false)
virtual int MyPID() const =0
int FillComplete(bool OptimizeDataStorage=true)
int create_maps(Epetra_Comm &Comm, const std::string &input_file_name, Epetra_Map *&row_map, Epetra_Map *&col_map, Epetra_Map *&range_map, Epetra_Map *&domain_map)
int main(int argc, char **argv)
int test_drumm1(Epetra_Comm &Comm)
int read_input_file(Epetra_Comm &Comm, const std::string &input_file_name, std::vector< std::string > &filenames)
const Epetra_Map & RowMap() const
virtual int SumAll(double *PartialSums, double *GlobalSums, int Count) const =0
int NumMyElements() const
int MatrixMarketFileToCrsMatrix(const char *filename, const Epetra_Comm &comm, Epetra_CrsMatrix *&A)
Epetra_Map * find_rows_containing_cols(const Epetra_CrsMatrix &M, const Epetra_Map &column_map)
int run_test(Epetra_Comm &Comm, const std::string &filename, bool do_FillComplete, bool result_mtx_to_file=false, bool verbose=false)
int NumGlobalNonzeros() const
static int Add(const Epetra_CrsMatrix &A, bool transposeA, double scalarA, Epetra_CrsMatrix &B, double scalarB)
Given Epetra_CrsMatrix objects A and B, form the sum B = a*A + b*B.
int LeftScale(const Epetra_Vector &x)
int RowMatrixToMatrixMarketFile(const char *filename, const Epetra_RowMatrix &A, const char *matrixName, const char *matrixDescription, bool writeHeader)
Writes an Epetra_RowMatrix object to a Matrix Market format file.
int expand_name_list(const char *newname, const char **&names, int &alloc_len, int &num_names)
virtual int NumProc() const =0
static int Jacobi(double omega, const Epetra_Vector &Dinv, const Epetra_CrsMatrix &A, const Epetra_CrsMatrix &B, Epetra_CrsMatrix &C, bool call_FillComplete_on_result=true)
Given Epetra_CrsMatrix objects A, B and C, and Epetra_Vector Dinv, form the product C = (I-omega * Di...
int read_matrix(const std::string &filename, Epetra_Comm &Comm, const Epetra_Map *rowmap, Epetra_Map *colmap, const Epetra_Map *rangemap, const Epetra_Map *domainmap, Epetra_CrsMatrix *&mat)
int GRID(int LRID_in) const
const Epetra_Map & DomainMap() const
int read_matrix_file_names(Epetra_Comm &Comm, const std::string &input_file_name, std::string &A_file, bool &transA, std::string &B_file, bool &transB, std::string &C_file)
int MatrixMarketFileToBlockMaps(const char *filename, const Epetra_Comm &comm, Epetra_BlockMap *&rowmap, Epetra_BlockMap *&colmap, Epetra_BlockMap *&rangemap, Epetra_BlockMap *&domainmap)
Constructs row,col,range and domain maps from a matrix-market matrix file.
int broadcast_name(Epetra_Comm &Comm, std::string &name)