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 long long numglobalrows = ((
long long)numprocs)*numlocalrows;
256 long long* cols =
new long long[numglobalrows];
257 double*vals =
new double[numglobalrows];
259 for(
long long j=0; j<numglobalrows; ++j) {
264 Epetra_Map colmap(-1LL, numglobalrows, cols, 0LL, Comm);
266 for(
int i=0; i<numlocalrows; ++i) {
267 long long row = ((
long long)localproc)*numlocalrows+i;
268 err = matrix.InsertGlobalValues(row, 1, &(vals[i]), &row);
274 err = matrix.FillComplete();
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 A 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;
561 delete Cck_range_map;
562 delete Cck_domain_map;
568 const std::string& input_file_name,
575 if (Comm.
MyPID()==0) {
576 std::ifstream infile(input_file_name.c_str());
578 std::cout <<
"error opening input file " << input_file_name << std::endl;
582 const int linelen = 512;
585 infile.getline(line, linelen);
587 if (strchr(line,
'#') == NULL) {
588 A_file =
path+
"/"+line;
592 infile.getline(line, linelen);
594 if (!strcmp(line,
"TRANSPOSE")) {
600 infile.getline(line, linelen);
602 if (strchr(line,
'#') == NULL) {
603 B_file =
path+
"/"+line;
607 infile.getline(line, linelen);
609 if (!strcmp(line,
"TRANSPOSE")) {
615 infile.getline(line, linelen);
617 if (strchr(line,
'#') == NULL) {
618 C_file =
path+
"/"+line;
626 int len = transA ? 1 : 0;
627 MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
628 len = transB ? 1 : 0;
629 MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
638 MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
639 transA = len==1 ?
true :
false;
640 MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
641 transB = len==1 ?
true :
false;
649 const std::string& input_file_name,
674 *rangemap, *domainmap, mat);
683 int thisproc = Comm.
MyPID();
687 if (numprocs != 2)
return(0);
691 long long numGlobalRows = 2;
694 if (thisproc == 1) myrow = 7;
695 Epetra_Map rowmap(numGlobalRows, numMyRows, &myrow, 0LL, Comm);
699 long long numGlobalCols = 10;
701 long long* mycols =
new long long[numGlobalCols];
703 for(i=0; i<numGlobalCols; ++i) {
707 Epetra_Map domainmap(numGlobalCols, numMyCols, &(mycols[thisproc*numMyCols]),
715 double* coefs =
new double[numGlobalCols];
716 for(i=0; i<numGlobalCols; ++i) {
720 long long numCols = numGlobalCols - 2;
722 if (thisproc == 1) offset = 2;
727 &(mycols[thisproc*numMyCols]));
743 if (C.NumGlobalNonzeros64() != 4) {
756 const int magic_num = 3000;
761 int localn = magic_num/Comm.
NumProc();
770 double start_time = timer.WallTime();
774 int globaln = localn*Comm.
NumProc();
776 std::cout <<
"size: " << globaln <<
"x"<<globaln<<
", C = A*A, time: "
777 << timer.WallTime()-start_time << std::endl;
782 start_time = timer.WallTime();
787 std::cout <<
"size: " << globaln <<
"x"<<globaln<<
", C = A*A, time: "
788 << timer.WallTime()-start_time <<
" (C already Filled)\n" <<std::endl;
795 start_time = timer.WallTime();
800 std::cout <<
"size: " << globaln <<
"x"<<globaln<<
", C = A*A^T, time: "
801 << timer.WallTime()-start_time << std::endl;
806 start_time = timer.WallTime();
811 std::cout <<
"size: " << globaln <<
"x"<<globaln<<
", C = A*A^T, time: "
812 << timer.WallTime()-start_time <<
" (C already Filled)\n" <<std::endl;
819 start_time = timer.WallTime();
824 std::cout <<
"size: " << globaln <<
"x"<<globaln<<
", C = A^T*A, time: "
825 << timer.WallTime()-start_time << std::endl;
830 start_time = timer.WallTime();
835 std::cout <<
"size: " << globaln <<
"x"<<globaln<<
", C = A^T*A, time: "
836 << timer.WallTime()-start_time <<
" (C already Filled)\n"<<std::endl;
843 start_time = timer.WallTime();
848 std::cout <<
"size: " << globaln <<
"x"<<globaln<<
", C = A^T*A^T, time: "
849 << timer.WallTime()-start_time << std::endl;
854 start_time = timer.WallTime();
859 std::cout <<
"size: " << globaln <<
"x"<<globaln<<
", C = A^T*A^T, time: "
860 << timer.WallTime()-start_time <<
" (C already Filled)\n" <<std::endl;
873 bool callFillComplete,
882 long long global_num_rows = numProcs*local_n;
884 Epetra_Map rowmap(global_num_rows, local_n, 0LL, comm);
891 double negOne = -1.0;
893 double val_L = symmetric ? negOne : -0.5;
895 for (
int i=0; i<local_n; i++) {
896 long long GlobalRow = matrix->
GRID64(i);
897 long long RowLess1 = GlobalRow - 1;
898 long long RowPlus1 = GlobalRow + 1;
899 long long RowLess5 = GlobalRow - 5;
900 long long RowPlus5 = GlobalRow + 5;
901 long long RowLess9 = GlobalRow - 9;
902 long long RowPlus9 = GlobalRow + 9;
903 long long RowLess24 = GlobalRow - 24;
904 long long RowPlus24 = GlobalRow + 24;
905 long long RowLess48 = GlobalRow - 48;
906 long long RowPlus48 = GlobalRow + 48;
925 if (RowPlus1<global_num_rows) {
928 if (RowPlus5<global_num_rows) {
931 if (RowPlus9<global_num_rows) {
934 if (RowPlus24<global_num_rows) {
937 if (RowPlus48<global_num_rows) {
944 if (callFillComplete) {
947 std::cout <<
"create_epetra_matrix: error in matrix.FillComplete()"
958 if (size != 2)
return 0;
960 int rank = Comm.
MyPID();
962 long long indexBase = 0;
963 long long numGlobalElements = 2;
965 Epetra_Map emap(numGlobalElements, indexBase, Comm);
972 std::vector<std::vector<double> > vals(numGlobalElements);
973 vals[0].push_back(3); vals[0].push_back(4);
974 vals[1].push_back(1); vals[1].push_back(2);
976 std::vector<long long> indices;
977 indices.push_back(0); indices.push_back(1);
979 for (
int row=0; row<numGlobalElements; ++row) {
1002 if (idx[0] == 0 && val[0] != 10.0) test_result = 1;
1003 if (idx[1] == 0 && val[1] != 10.0) test_result = 1;
1004 if (idx[0] == 1 && val[0] != 14.0) test_result = 1;
1005 if (idx[1] == 1 && val[1] != 14.0) test_result = 1;
1008 if (idx[0] == 0 && val[0] != 14.0) test_result = 1;
1009 if (idx[1] == 0 && val[1] != 14.0) test_result = 1;
1010 if (idx[0] == 1 && val[0] != 20.0) test_result = 1;
1011 if (idx[1] == 1 && val[1] != 20.0) test_result = 1;
1014 int global_test_result = 0;
1015 Comm.
SumAll(&test_result, &global_test_result, 1);
1017 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
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)
long long GRID64(int LRID_in) const
int MatrixMarketFileToCrsMatrix64(const char *filename, const Epetra_Comm &comm, Epetra_CrsMatrix *&A)
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
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)
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 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
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)
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 broadcast_name(Epetra_Comm &Comm, std::string &name)
int MatrixMarketFileToBlockMaps64(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.