void ML_Read_Matrix_Dimensions(const char *filename, int *numGlobalRows, Epetra_Comm &Comm) { char line[35], token1[35], token2[35], token3[35], token4[35], token5[35]; int lineLength = 1025; FILE *fid = fopen(filename,"r"); int N, NZ; if(fgets(line, lineLength, fid)==0) { if (fid!=0) fclose(fid); ML_Exit(Comm.MyPID(),"error opening matrix file", EXIT_FAILURE); } if(sscanf(line, "%s %s %s %s %s", token1, token2, token3, token4, token5 )==0) { if (fid!=0) fclose(fid); ML_Exit(Comm.MyPID(),"error reading matrix file header", EXIT_FAILURE); } if (strcmp(token1, "%%MatrixMarket") || strcmp(token2, "matrix") || strcmp(token3, "coordinate") || strcmp(token4, "real") || strcmp(token5, "general")) { if (fid!=0) fclose(fid); ML_Exit(Comm.MyPID(),"error reading matrix file header", EXIT_FAILURE); } // Next, strip off header lines (which start with "%") do { if(fgets(line, lineLength, fid)==0) { if (fid!=0) fclose(fid); ML_Exit(Comm.MyPID(),"error reading matrix file comments", EXIT_FAILURE); } } while (line[0] == '%'); // Next get problem dimensions: M, N, NZ if(sscanf(line, "%d %d %d", numGlobalRows, &N, &NZ)==0) { if (fid!=0) fclose(fid); ML_Exit(Comm.MyPID(),"error reading matrix file dimensions", EXIT_FAILURE); } } //ML_Read_Matrix_Dimensions()
int fevec6(Epetra_Comm& Comm, bool verbose) { int NumElements = 4; Epetra_Map Map(NumElements, 0, Comm); Epetra_FEVector x1(Map); x1.PutScalar (0); // let all processors set global entry 0 to 1 const int GID = 0; const double value = 1; x1.ReplaceGlobalValues(1, &GID, &value); x1.GlobalAssemble (Insert); if (Comm.MyPID()==0) std::cout << "Entry " << GID << " after construct & set: " << x1[0][0] << std::endl; x1.PutScalar(0); // re-apply 1 to the vector, but only on the // owning processor. should be enough to set // the value (as non-local data in x1 should // have been eliminated after calling // GlobalAssemble). if (Comm.MyPID()==0) x1.ReplaceGlobalValues(1, &GID, &value); x1.GlobalAssemble (Insert); if (Comm.MyPID()==0) { std::cout << "Entry " << GID << " after PutScalar & set: " << x1[0][0] << std::endl; if (x1[0][0] != value) return -1; } return 0; }
int generateHyprePrintOut(const char *filename, const Epetra_Comm &comm){ int MyPID = comm.MyPID(); int NumProc = comm.NumProc(); int N = 100; int ilower = MyPID * N; int iupper = (MyPID+1)*N-1; double filePID = (double)MyPID/(double)100000; std::ostringstream stream; // Using setprecision() puts it in the std::string stream << std::setiosflags(std::ios::fixed) << std::setprecision(5) << filePID; // Then just ignore the first character std::string fileName(filename); fileName += stream.str().substr(1,7); std::ofstream myfile(fileName.c_str()); if(myfile.is_open()){ myfile << ilower << " " << iupper << " " << ilower << " " << iupper << std::endl; for(int i = ilower; i <= iupper; i++){ for(int j=i-5; j <= i+5; j++){ if(j >= 0 && j < N*NumProc) myfile << i << " " << j << " " << (double)rand()/(double)RAND_MAX << std::endl; } } myfile.close(); return 0; } else { std::cout << "\nERROR:\nCouldn't open file.\n"; return -1; } }
void random_distribution_1D( itype nrows, // Number of global matrix rows Epetra_Comm &comm, // Epetra communicator to be used in maps Epetra_Map **rowMap, // OUTPUT: pointer to row map to be created long long offsetEpetra64 ) { // Randomly assign matrix rows to processor's row Map. int me = comm.MyPID(); int np = comm.NumProc(); vector<itype> myGlobalElements(1.2 * (nrows / np) + 1); int nMyRows = 0; srandom(1); double denom = (double) RAND_MAX + 1.; for (itype i = 0; i < nrows; i++) { int p = (int) ((double) np * (double) random() / denom); if (p == me) { if (nMyRows >= myGlobalElements.size()) myGlobalElements.resize(1.5*myGlobalElements.size()); myGlobalElements[nMyRows] = i + offsetEpetra64; nMyRows++; } } *rowMap = new Epetra_Map(nrows, nMyRows, &myGlobalElements[0], 0, comm); }
bool global_check_for_flag_on_proc_0(const char* flag, int numargs, char** strargs, const Epetra_Comm& comm) { int mypid = comm.MyPID(); int numprocs = comm.NumProc(); int flag_found = 0; if (mypid==0) { for(int i=0; i<numargs; ++i) { if (strargs[i]==0) continue; if (strcmp(flag, strargs[i]) == 0) { flag_found = 1; break; } } } if (numprocs > 1) { comm.Broadcast(&flag_found, 1, 0); } bool return_value = flag_found==1 ? true : false; return( return_value ); }
void show_matrix(const char *txt, const Epetra_RowMatrix &matrix, const Epetra_Comm &comm) { int me = comm.MyPID(); if (comm.NumProc() > 10){ if (me == 0){ std::cout << txt << std::endl; std::cout << "Printed matrix format only works for 10 or fewer processes" << std::endl; } return; } int numRows = matrix.NumGlobalRows(); int numCols = matrix.NumGlobalCols(); if ((numRows > 200) || (numCols > 500)){ if (me == 0){ std::cerr << txt << std::endl; std::cerr << "show_matrix: problem is too large to display" << std::endl; } return; } int *myA = new int [numRows * numCols]; make_my_A(matrix, myA, comm); printMatrix(txt, myA, NULL, NULL, numRows, numCols, comm); delete [] myA; }
int HypreFileToCrsMatrix(const char *filename, const Epetra_Comm &comm, Epetra_CrsMatrix *&Matrix){ int MyPID = comm.MyPID(); // This double will be in the format we want for the extension besides the leading zero double filePID = (double)MyPID/(double)100000; std::ostringstream stream; // Using setprecision() puts it in the string stream << std::setiosflags(std::ios::fixed) << std::setprecision(5) << filePID; // Then just ignore the first character std::string fileName(filename); fileName += stream.str().substr(1,7); // Open the file std::ifstream file(fileName.c_str()); string line; if(file.is_open()){ std::getline(file, line); int ilower, iupper; std::istringstream istream(line); // The first line of the file has the beginning and ending rows istream >> ilower; istream >> iupper; // Using those we can create a row map Epetra_Map RowMap(-1, iupper-ilower+1, 0, comm); Matrix = new Epetra_CrsMatrix(Copy, RowMap, 0); int currRow = -1; int counter = 0; std::vector<int> indices; std::vector<double> values; while(!file.eof()){ std::getline(file, line); std::istringstream lineStr(line); int row, col; double val; lineStr >> row; lineStr >> col; lineStr >> val; if(currRow == -1) currRow = row; // First line if(row == currRow){ // add to the vector counter = counter + 1; indices.push_back(col); values.push_back(val); } else { Matrix->InsertGlobalValues(currRow, counter, &values[0], &indices[0]); indices.clear(); values.clear(); counter = 0; currRow = row; // make a new vector indices.push_back(col); values.push_back(val); counter = counter + 1; } } Matrix->InsertGlobalValues(currRow, counter, &values[0], &indices[0]); Matrix->Comm().Barrier(); Matrix->FillComplete(); file.close(); return 0; } else {
int special_submap_import_test(Epetra_Comm& Comm) { int localProc = Comm.MyPID(); //set up ids_source and ids_target such that ids_source are only //a subset of ids_target, and furthermore that ids_target are ordered //such that the LIDs don't match up. In other words, even if gid 2 does //exist in both ids_source and ids_target, it will correspond to different //LIDs on at least 1 proc. // //This is to test a certain bug-fix in Epetra_Import where the 'RemoteLIDs' //array wasn't being calculated correctly on all procs. long long ids_source[1]; ids_source[0] = localProc*2+2; long long ids_target[3]; ids_target[0] = localProc*2+2; ids_target[1] = localProc*2+1; ids_target[2] = localProc*2+0; Epetra_Map map_source((long long) -1, 1, &ids_source[0], 0LL, Comm); Epetra_Map map_target((long long) -1, 3, &ids_target[0], 0LL, Comm); Epetra_Import importer(map_target, map_source); Epetra_LongLongVector vec_source(map_source); Epetra_LongLongVector vec_target(map_target); vec_target.PutValue(0); //set vec_source's contents so that entry[i] == GID[i]. long long* GIDs = map_source.MyGlobalElements64(); for(int i=0; i<map_source.NumMyElements(); ++i) { vec_source[i] = GIDs[i]; } //Import vec_source into vec_target. This should result in the contents //of vec_target remaining 0 for the entries that don't exist in vec_source, //and other entries should be equal to the corresponding GID in the map. vec_target.Import(vec_source, importer, Insert); GIDs = map_target.MyGlobalElements64(); int test_failed = 0; //the test passes if the i-th entry in vec_target equals either 0 or //GIDs[i]. for(int i=0; i<vec_target.MyLength(); ++i) { if (vec_target[i] != GIDs[i] && vec_target[i] != 0) test_failed = 1; } int global_result; Comm.MaxAll(&test_failed, &global_result, 1); //If test didn't fail on any procs, global_result should be 0. //If test failed on any proc, global_result should be 1. return global_result; }
void show_matrix(const char *txt, const Epetra_LinearProblem &problem, const Epetra_Comm &comm) { int me = comm.MyPID(); if (comm.NumProc() > 10){ if (me == 0){ std::cout << txt << std::endl; std::cout << "Printed matrix format only works for 10 or fewer processes" << std::endl; } return; } Epetra_RowMatrix *matrix = problem.GetMatrix(); Epetra_MultiVector *lhs = problem.GetLHS(); Epetra_MultiVector *rhs = problem.GetRHS(); int numRows = matrix->NumGlobalRows(); int numCols = matrix->NumGlobalCols(); if ((numRows > 200) || (numCols > 500)){ if (me == 0){ std::cerr << txt << std::endl; std::cerr << "show_matrix: problem is too large to display" << std::endl; } return; } int *myA = new int [numRows * numCols]; make_my_A(*matrix, myA, comm); int *myX = new int [numCols]; int *myB = new int [numRows]; memset(myX, 0, sizeof(int) * numCols); memset(myB, 0, sizeof(int) * numRows); const Epetra_BlockMap &lhsMap = lhs->Map(); const Epetra_BlockMap &rhsMap = rhs->Map(); int base = lhsMap.IndexBase(); for (int j=0; j < lhsMap.NumMyElements(); j++){ int colGID = lhsMap.GID(j); myX[colGID - base] = me + 1; } for (int i=0; i < rhsMap.NumMyElements(); i++){ int rowGID = rhsMap.GID(i); myB[rowGID - base] = me + 1; } printMatrix(txt, myA, myX, myB, numRows, numCols, comm); delete [] myA; delete [] myX; delete [] myB; }
Teuchos::RCP< Epetra_LinearProblem > build_problem(Teuchos::ParameterList& test_params, const Epetra_Comm& comm) { Teuchos::Time timer("build_problem"); timer.start(); Epetra_CrsMatrix* A; Epetra_Vector* b = NULL; std::string mm_file("not specified"); std::string rhs_mm_file("not specified"); helper::GetParameter(test_params, "mm_file", mm_file); helper::GetParameter(test_params, "rhs_mm_file", rhs_mm_file); std::string hb_file("not specified"); helper::GetParameter(test_params, "hb_file", hb_file); if (mm_file != "not specified") { if (comm.MyPID() == 0) { std::cout << "Matrix-Market file: " << mm_file << std::endl; } A = read_matrix_mm(mm_file, comm); if (rhs_mm_file != "not specified") { if (comm.MyPID() == 0) { std::cout << "Matrix-Market file: " << rhs_mm_file << std::endl; } b = read_vector_mm(rhs_mm_file, comm); } } else if (hb_file != "not specified") { read_matrix_hb(hb_file, comm, A, b); } else { throw std::runtime_error("No matrix file specified."); } Teuchos::RCP<Epetra_LinearProblem> problem = build_problem_mm(test_params, A, b); timer.stop(); if (comm.MyPID() == 0) { std::cout << "proc 0 time to read matrix & create problem: " << timer.totalElapsedTime() << std::endl; } return problem; }
// Do something with the given communicator. In this case, we just // print Epetra's version to the given output stream, on Process 0. void exampleRoutine (const Epetra_Comm& comm, std::ostream& out) { if (comm.MyPID () == 0) { // On (MPI) Process 0, print out the Epetra software version. out << Epetra_Version () << std::endl << std::endl; } }
static void print_out(const Epetra_Comm& Comm, const int level, const char* what) { if (Comm.MyPID() == 0 && ML_Get_PrintLevel() > 2) #ifdef TFLOP printf("Amesos (level %d) : Building %s\n", level, what); #else std::cout << "Amesos (level " << level << ") : Building " << what << "\n"; #endif }
//============================================================================== Poisson2dOperator::Poisson2dOperator(int nx, int ny, const Epetra_Comm & comm) : nx_(nx), ny_(ny), useTranspose_(false), comm_(comm), map_(0), numImports_(0), importIDs_(0), importMap_(0), importer_(0), importX_(0), Label_(0) { Label_ = "2D Poisson Operator"; int numProc = comm.NumProc(); // Get number of processors int myPID = comm.MyPID(); // My rank if (2*numProc > ny) { // ny must be >= 2*numProc (to avoid degenerate cases) ny = 2*numProc; ny_ = ny; std::cout << " Increasing ny to " << ny << " to avoid degenerate distribution on " << numProc << " processors." << std::endl; } int chunkSize = ny/numProc; int remainder = ny%numProc; if (myPID+1 <= remainder) chunkSize++; // add on remainder myny_ = chunkSize; map_ = new Epetra_Map(-1LL, ((long long)nx)*chunkSize, 0, comm_); if (numProc>1) { // Build import GID list to build import map and importer if (myPID>0) numImports_ += nx; if (myPID+1<numProc) numImports_ += nx; if (numImports_>0) importIDs_ = new long long[numImports_]; long long * ptr = importIDs_; long long minGID = map_->MinMyGID64(); long long maxGID = map_->MaxMyGID64(); if (myPID>0) for (int i=0; i< nx; i++) *ptr++ = minGID - nx + i; if (myPID+1<numProc) for (int i=0; i< nx; i++) *ptr++ = maxGID + i +1; // At the end of the above step importIDs_ will have a list of global IDs that are needed // to compute the matrix multiplication operation on this processor. Now build import map // and importer importMap_ = new Epetra_Map(-1LL, numImports_, importIDs_, 0LL, comm_); importer_ = new Epetra_Import(*importMap_, *map_); } }
int alternate_import_constructor_test(Epetra_Comm& Comm) { int rv=0; int nodes_per_proc=10; int numprocs = Comm.NumProc(); int mypid = Comm.MyPID(); // Only run if we have multiple procs & MPI if(numprocs==0) return 0; #ifndef HAVE_MPI return 0; #endif // Build Map 1 - linear Epetra_Map Map1((long long)-1,nodes_per_proc,(long long)0,Comm); // Build Map 2 - mod striped std::vector<long long> MyGIDs(nodes_per_proc); for(int i=0; i<nodes_per_proc; i++) MyGIDs[i] = (mypid*nodes_per_proc + i) % numprocs; Epetra_Map Map2((long long)-1,nodes_per_proc,&MyGIDs[0],(long long)0,Comm); // For testing Epetra_LongLongVector Source(Map1), Target(Map2); // Build Import 1 - normal Epetra_Import Import1(Map2,Map1); rv = rv|| test_import_gid("Alt test: 2 map constructor",Source,Target, Import1); // Build Import 2 - no-comm constructor int Nremote=Import1.NumRemoteIDs(); const int * RemoteLIDs = Import1.RemoteLIDs(); std::vector<int> RemotePIDs(Nremote+1); // I hate you, stl vector.... std::vector<int> AllPIDs; Epetra_Util::GetPids(Import1,AllPIDs,true); for(int i=0; i<Nremote; i++) { RemotePIDs[i]=AllPIDs[RemoteLIDs[i]]; } Epetra_Import Import2(Import1.TargetMap(),Import1.SourceMap(),Nremote,&RemotePIDs[0],Import1.NumExportIDs(),Import1.ExportLIDs(),Import1.ExportPIDs()); rv = rv || test_import_gid("Alt test: no comm constructor",Source,Target,Import2); // Build Import 3 - Remotes only Epetra_Import Import3(Import1.TargetMap(),Import1.SourceMap(),Nremote,&RemotePIDs[0]); rv = rv || test_import_gid("Alt test: remote only constructor",Source,Target, Import3); return rv; }
int combine_mode_test(Epetra_Comm& Comm) { int localProc = Comm.MyPID(); long long ids_source[1]; ids_source[0] = localProc*2+2; long long ids_target[3]; ids_target[0] = localProc*2+2; ids_target[1] = localProc*2+1; ids_target[2] = localProc*2+0; Epetra_Map map_source((long long) -1, 1, &ids_source[0], 0LL, Comm); Epetra_Map map_target((long long) -1, 3, &ids_target[0], 0LL, Comm); Epetra_Import importer(map_target, map_source); Epetra_LongLongVector vec_source(map_source); Epetra_LongLongVector vec_target(map_target); vec_target.PutValue(0); //set vec_source's contents so that entry[i] == GID[i]. long long* GIDs = map_source.MyGlobalElements64(); for(int i=0; i<map_source.NumMyElements(); ++i) { vec_source[i] = GIDs[i]; } //Import vec_source into vec_target. This should result in the contents //of vec_target remaining 0 for the entries that don't exist in vec_source, //and other entries should be equal to the corresponding GID in the map. vec_target.Import(vec_source, importer, Insert); GIDs = map_target.MyGlobalElements64(); int test_failed = 0; //the test passes if the i-th entry in vec_target equals either 0 or //GIDs[i]. for(int i=0; i<vec_target.MyLength(); ++i) { if (vec_target[i] != GIDs[i] && vec_target[i] != 0) test_failed = 1; } int global_result; Comm.MaxAll(&test_failed, &global_result, 1); //If test didn't fail on any procs, global_result should be 0. //If test failed on any proc, global_result should be 1. return global_result; }
//============================================================================ void Ifpack_BreakForDebugger(Epetra_Comm& Comm) { char hostname[80]; char buf[80]; if (Comm.MyPID() == 0) cout << "Host and Process Ids for tasks" << endl; for (int i = 0; i <Comm.NumProc() ; i++) { if (i == Comm.MyPID() ) { #if defined(TFLOP) || defined(JANUS_STLPORT) sprintf(buf, "Host: %s PID: %d", "janus", getpid()); #elif defined(_WIN32) sprintf(buf,"Windows compiler, unknown hostname and PID!"); #else gethostname(hostname, sizeof(hostname)); sprintf(buf, "Host: %s\tComm.MyPID(): %d\tPID: %d", hostname, Comm.MyPID(), getpid()); #endif printf("%s\n",buf); fflush(stdout); #if !( defined(_WIN32) ) sleep(1); #endif } } if(Comm.MyPID() == 0) { printf("\n"); printf("** Pausing to attach debugger...\n"); printf("** You may now attach debugger to the processes listed above.\n"); printf( "**\n"); printf( "** Enter a character to continue > "); fflush(stdout); char go; scanf("%c",&go); } Comm.Barrier(); }
//============================================================================== // Epetra_BlockMap constructor function for a Epetra-defined uniform linear distribution of constant size elements. void Epetra_BlockMap::ConstructAutoUniform(long long NumGlobal_Elements, int Element_Size, int Index_Base, const Epetra_Comm& comm, bool IsLongLong) { // Each processor gets roughly numGlobalPoints/p points // This routine automatically defines a linear partitioning of a // map with numGlobalPoints across the processors // specified in the given Epetra_Comm if (NumGlobal_Elements < 0) throw ReportError("NumGlobal_Elements = " + toString(NumGlobal_Elements) + ". Should be >= 0.", -1); if (Element_Size <= 0) throw ReportError("ElementSize = " + toString(Element_Size) + ". Should be > 0.", -2); BlockMapData_ = new Epetra_BlockMapData(NumGlobal_Elements, Element_Size, Index_Base, comm, IsLongLong); int NumProc = comm.NumProc(); BlockMapData_->ConstantElementSize_ = true; BlockMapData_->LinearMap_ = true; int MyPID = comm.MyPID(); if(BlockMapData_->NumGlobalElements_ / NumProc > (long long) std::numeric_limits<int>::max()) throw ReportError("Epetra_BlockMap::ConstructAutoUniform: Error. Not enough space for elements on each processor", -99); BlockMapData_->NumMyElements_ = (int) (BlockMapData_->NumGlobalElements_ / NumProc); int remainder = (int) (BlockMapData_->NumGlobalElements_ % NumProc); // remainder will fit int int start_index = MyPID * (BlockMapData_->NumMyElements_ + 1); if (MyPID < remainder) BlockMapData_->NumMyElements_++; else start_index -= (MyPID - remainder); BlockMapData_->NumGlobalPoints_ = BlockMapData_->NumGlobalElements_ * BlockMapData_->ElementSize_; BlockMapData_->NumMyPoints_ = BlockMapData_->NumMyElements_ * BlockMapData_->ElementSize_; BlockMapData_->MinMyElementSize_ = BlockMapData_->ElementSize_; BlockMapData_->MaxMyElementSize_ = BlockMapData_->ElementSize_; BlockMapData_->MinElementSize_ = BlockMapData_->ElementSize_; BlockMapData_->MaxElementSize_ = BlockMapData_->ElementSize_; BlockMapData_->MinAllGID_ = BlockMapData_->IndexBase_; BlockMapData_->MaxAllGID_ = BlockMapData_->MinAllGID_ + BlockMapData_->NumGlobalElements_ - 1; BlockMapData_->MinMyGID_ = start_index + BlockMapData_->IndexBase_; BlockMapData_->MaxMyGID_ = BlockMapData_->MinMyGID_ + BlockMapData_->NumMyElements_ - 1; BlockMapData_->DistributedGlobal_ = IsDistributedGlobal(BlockMapData_->NumGlobalElements_, BlockMapData_->NumMyElements_); EndOfConstructorOps(); }
static int make_my_A(const Epetra_RowMatrix &matrix, int *myA, const Epetra_Comm &comm) { int me = comm.MyPID(); const Epetra_Map &rowmap = matrix.RowMatrixRowMap(); const Epetra_Map &colmap = matrix.RowMatrixColMap(); int myRows = matrix.NumMyRows(); int numRows = matrix.NumGlobalRows(); int numCols = matrix.NumGlobalCols(); int base = rowmap.IndexBase(); int maxRow = matrix.MaxNumEntries(); memset(myA, 0, sizeof(int) * numRows * numCols); int *myIndices = new int [maxRow]; double *tmp = new double [maxRow]; int rowLen = 0; for (int i=0; i< myRows; i++){ int rc = matrix.ExtractMyRowCopy(i, maxRow, rowLen, tmp, myIndices); if (rc){ if (me == 0){ std::cout << "Error in make_my_A" << std::endl; } return 1; } int *row = myA + (numCols * (rowmap.GID(i) - base)); for (int j=0; j < rowLen; j++){ int colGID = colmap.GID(myIndices[j]); row[colGID - base] = me + 1; } } if (maxRow){ delete [] myIndices; delete [] tmp; } return 0; }
int fevec7(Epetra_Comm& Comm, bool verbose) { const int NumVectors = 4; const int NumElements = 4; Epetra_Map Map(NumElements, 0, Comm); std::vector<double> mydata(NumElements*NumVectors, 1.0); Epetra_FEVector x1(View, Map, &mydata[0], NumElements, NumVectors); x1.PutScalar (0); // let all processors set global entry 0 to 1 const int GID = 0; const double value = 1; x1.ReplaceGlobalValues(1, &GID, &value); x1.GlobalAssemble (Insert); if (Comm.MyPID()==0 && x1[0][0] != value) return -1; return 0; }
void build_maps( itype nrows, // Number of global matrix rows bool testEpetra64,// Flag indicating whether to adjust global row/column // indices to exercise Epetra64 capability. Epetra_Comm &comm, // Epetra communicator to be used in maps Epetra_Map **vectorMap, // OUTPUT: Map to be used for the vector Epetra_Map **rowMap, // OUTPUT: Map to be used for the matrix rows Epetra_Map **colMap, // OUTPUT: Map to be used for the matrix cols long long &offsetEpetra64, // OUTPUT for testing Epetra64: add offsetEpetra64 // to all row/column indices. bool verbose // print out generated maps ) { // Function to build the maps for 1D or 2D matrix distribution. // Output for 1D includes rowMap and NULL colMap and vectorMap. // Output for 2D includes rowMap, colMap and vectorMap. int me = comm.MyPID(); int np = comm.NumProc(); *rowMap = NULL; *colMap = NULL; *vectorMap = NULL; // offsetEpetra64 = (testEpetra64 ? (long long) INT_MAX - (long long) 5 : 0); offsetEpetra64 = (testEpetra64 ? (long long) 2 * INT_MAX : 0); // Generate 1D row-based decomposition. if ((me == 0) && verbose) cout << endl << "1D Distribution: " << endl << " np = " << np << endl; // Linear map similar to Trilinos default. itype nMyRows = nrows / np + (nrows % np > me); itype myFirstRow = me * (nrows / np) + MIN(nrows % np, me); itype *myGlobalRows = new itype[nMyRows]; for (itype i = 0; i < nMyRows; i++) myGlobalRows[i] = i + myFirstRow + offsetEpetra64; *rowMap = new Epetra_Map(nrows, nMyRows, &myGlobalRows[0], 0, comm); delete [] myGlobalRows; }
int check_graph_sharing(Epetra_Comm& Comm) { int numLocalElems = 5; int localProc = Comm.MyPID(); int firstElem = localProc*numLocalElems; int err; Epetra_Map map(-1, numLocalElems, 0, Comm); Epetra_CrsMatrix* A = new Epetra_CrsMatrix(Copy, map, 1); for (int i=0; i<numLocalElems; ++i) { int row = firstElem+i; int col = row; double val = 1.0; err = A->InsertGlobalValues(row, 1, &val, &col); if (err != 0) { cerr << "A->InsertGlobalValues("<<row<<") returned err="<<err<<endl; return(err); } } A->FillComplete(false); Epetra_CrsMatrix B(Copy, A->Graph()); delete A; for (int i=0; i<numLocalElems; ++i) { int row = firstElem+i; int col = row; double val = 1.0; err = B.ReplaceGlobalValues(row, 1, &val, &col); if (err != 0) { cerr << "B.InsertGlobalValues("<<row<<") returned err="<<err<<endl; return(err); } } return(0); }
int rectangular(const Epetra_Comm& Comm, bool verbose) { int mypid = Comm.MyPID(); int numlocalrows = 3; Epetra_Map rowmap((long long) -1, numlocalrows, 0, Comm); long long numglobalrows = numlocalrows*Comm.NumProc(); long long numcols = 2*numglobalrows; Epetra_FECrsGraph fegraph(Copy, rowmap, numcols); long long* cols = new long long[numcols]; for(int j=0; j<numcols; ++j) cols[j] = j; Epetra_Map domainmap((long long) -1, numcols, 0, Comm); long long firstlocalrow = numlocalrows*mypid; long long lastlocalrow = numlocalrows*(mypid+1)-1; for(long long i=0; i<numglobalrows; ++i) { //if i is a local row, then skip it. We want each processor to only //load rows that belong on other processors. if (i >= firstlocalrow && i <= lastlocalrow) continue; EPETRA_CHK_ERR( fegraph.InsertGlobalIndices(1, &i, numcols, &(cols[0])) ); } EPETRA_CHK_ERR( fegraph.GlobalAssemble(domainmap, rowmap) ); if (verbose) { std::cout << "********************** fegraph **********************" << std::endl; std::cout << fegraph << std::endl; } delete [] cols; return(0); }
int test_bug2890(Epetra_Comm& Comm, bool verbose) { //This function tests the AZ_random1() function in AztecOO. //The implementation of the Park and Miller random number //generator was incorrect and resulted in an overflow condition. //This is *not* a complete test of AztecOO's RNG. // //A more robust check is to compile AztecOO with gcc -ftrapv and run //a Krylov method that invokes AZ_random_vector(). int seed = -127773; double rand_num; rand_num = AZ_srandom1(&seed); if (verbose && Comm.MyPID() == 0) printf("test_bug2890: rand_num = %e (should be in [0,1])\n",rand_num); if ( (rand_num > 1) || (rand_num < 0) ) return 1; // rand_num should be in [0,1] else return 0; }
void MPIWrapper::allGatherCompact(const Epetra_Comm &Comm, FieldContainer<Scalar> &gatheredValues, FieldContainer<Scalar> &myValues, FieldContainer<int> &offsets) { int mySize = myValues.size(); int totalSize; Comm.SumAll(&mySize, &totalSize, 1); int myOffset = 0; Comm.ScanSum(&mySize,&myOffset,1); myOffset -= mySize; gatheredValues.resize(totalSize); for (int i=0; i<mySize; i++) { gatheredValues[myOffset+i] = myValues[i]; } MPIWrapper::entryWiseSum(Comm, gatheredValues); offsets.resize(Comm.NumProc()); offsets[Comm.MyPID()] = myOffset; MPIWrapper::entryWiseSum(Comm, offsets); }
void Trilinos_Util_distrib_vbr_matrix(const Epetra_Comm & Comm, int *N_global, int *N_blk_global, int *n_nonzeros, int *n_blk_nonzeros, int *N_update, int **update, double **val, int **indx, int **rpntr, int **cpntr, int **bpntr, int **bindx, double **x, double **b, double **xexact) #undef DEBUG { int i, n_global_nonzeros, n_global_blk_nonzeros; int N_local; int j, row, have_xexact = 0 ; int *rpntr1, *bindx1, *bpntr1, *indx1; double *val1, *b1, *x1, *xexact1=0; int MyPID = Comm.MyPID(); int NumProc = Comm.NumProc(); printf("Processor %d of %d entering distrib_matrix.\n", MyPID,NumProc) ; /*************** Distribute global matrix to all processors ************/ if(MyPID == 0) { if ((*xexact) != NULL) have_xexact = 1; printf("%s", "Broadcasting exact solution\n"); } if(NumProc > 1) { Comm.Broadcast( N_global, 1, 0); Comm.Broadcast( N_blk_global, 1, 0); Comm.Broadcast( n_nonzeros, 1, 0); Comm.Broadcast( n_blk_nonzeros, 1, 0); Comm.Broadcast( &have_xexact, 1, 0); printf("Processor %d of %d done with global parameter broadcast.\n", MyPID,NumProc) ; if(MyPID != 0) { *bpntr = (int *) calloc(*N_blk_global+1,sizeof(int)) ; *rpntr = (int *) calloc(*N_blk_global+1,sizeof(int)) ; *bindx = (int *) calloc(*n_blk_nonzeros+1,sizeof(int)) ; *indx = (int *) calloc(*n_blk_nonzeros+1,sizeof(int)) ; *val = (double *) calloc(*n_nonzeros+1,sizeof(double)) ; printf("Processor %d of %d done with global calloc.\n", MyPID,NumProc) ; } Comm.Broadcast( (*bpntr), (*N_blk_global+1), 0); Comm.Broadcast( (*rpntr), (*N_blk_global+1), 0); Comm.Broadcast( (*bindx), (*n_blk_nonzeros+1), 0); Comm.Broadcast( (*indx), (*n_blk_nonzeros+1), 0); Comm.Broadcast( (*val), (*n_nonzeros+1), 0); printf("Processor %d of %d done with matrix broadcast.\n", MyPID,NumProc) ; /* Set rhs and initialize guess */ if(MyPID != 0) { (*b) = (double *) calloc(*N_global,sizeof(double)) ; (*x) = (double *) calloc(*N_global,sizeof(double)) ; if (have_xexact) (*xexact) = (double *) calloc(*N_global,sizeof(double)) ; } Comm.Broadcast( (*x), (*N_global), 0); Comm.Broadcast( (*b), (*N_global), 0); if (have_xexact) Comm.Broadcast((*xexact), (*N_global), 0); printf("Processor %d of %d done with rhs/guess broadcast.\n", MyPID,NumProc) ; } /********************** Generate update map *************************/ //read_update(N_update, update, proc_config, *N_blk_global, 1, linear) ; Epetra_Map map(*N_blk_global, 0, Comm); *N_update = map.NumMyElements(); (*update) = (int *) calloc(*N_update,sizeof(int)) ; map.MyGlobalElements(*update); printf("Processor %d of %d has %d rows of %d total block rows.\n", MyPID,NumProc,*N_update,*N_blk_global) ; /*************** Construct local matrix from global matrix ************/ /* The local matrix is a copy of the rows assigned to this processor. It is stored in MSR format and still has global indices */ if(NumProc > 1) { n_global_nonzeros = *n_nonzeros; n_global_blk_nonzeros = *n_blk_nonzeros; *n_nonzeros = 0; *n_blk_nonzeros = 0; N_local = 0; for (i=0; i<*N_update; i++) { row = (*update)[i]; *n_nonzeros += (*indx)[(*bpntr)[row+1]] - (*indx)[(*bpntr)[row]]; *n_blk_nonzeros += (*bpntr)[row+1] - (*bpntr)[row]; N_local += (*rpntr)[row+1] - (*rpntr)[row]; } printf("Processor %d of %d has %d nonzeros of %d total nonzeros.\n", MyPID,NumProc, *n_nonzeros,n_global_nonzeros) ; printf("Processor %d of %d has %d block nonzeros of %d total block nonzeros.\n", MyPID,NumProc, *n_blk_nonzeros,n_global_blk_nonzeros) ; printf("Processor %d of %d has %d equations of %d total equations.\n", MyPID,NumProc, N_local,*N_global) ; #ifdef DEBUG { double sum1 = 0.0; for (i=0;i<*N_global; i++) sum1 += (*b)[i]; printf("Processor %d of %d has sum of b = %12.4g.\n", MyPID,NumProc,sum1) ; } #endif /* DEBUG */ /* Allocate memory for local matrix */ bpntr1 = (int *) calloc(*N_update+1,sizeof(int)) ; rpntr1 = (int *) calloc(*N_update+1,sizeof(int)) ; bindx1 = (int *) calloc(*n_blk_nonzeros+1,sizeof(int)) ; indx1 = (int *) calloc(*n_blk_nonzeros+1,sizeof(int)) ; val1 = (double *) calloc(*n_nonzeros+1,sizeof(double)) ; b1 = (double *) calloc(N_local,sizeof(double)) ; x1 = (double *) calloc(N_local,sizeof(double)) ; if (have_xexact) xexact1 = (double *) calloc(N_local,sizeof(double)) ; { int cur_blk_size, indx_offset, len_val, row_offset, row_offset1; double *val_ptr, *val1_ptr; bpntr1[0] = 0; indx1[0] = 0; rpntr1[0] = 0; for (i=0; i<*N_update; i++) { row = (*update)[i]; cur_blk_size = (*rpntr)[row+1] - (*rpntr)[row]; rpntr1[i+1] = rpntr1[i] + cur_blk_size; row_offset = (*rpntr)[row]; row_offset1 = rpntr1[i]; for (j = 0; j<cur_blk_size; j++) { b1[row_offset1+j] = (*b)[row_offset+j]; x1[row_offset1+j] = (*x)[row_offset+j]; if (have_xexact) xexact1[row_offset1+j] = (*xexact)[row_offset+j]; } bpntr1[i+1] = bpntr1[i]; #ifdef DEBUG printf("Proc %d of %d: Global row = %d: Local row = %d: b = %12.4g: x = %12.4g: bindx = %d: val = %12.4g \n", MyPID,NumProc, row, i, b1[i], x1[i], bindx1[i], val1[i]) ; #endif indx_offset = (*indx)[(*bpntr)[row]] - indx1[bpntr1[i]]; for (j = (*bpntr)[row]; j < (*bpntr)[row+1]; j++) { indx1[bpntr1 [i+1] + 1] = (*indx)[j+1] - indx_offset; bindx1[bpntr1 [i+1] ] = (*bindx)[j]; bpntr1[i+1] ++; } len_val = indx1[bpntr1[i+1]] - indx1[bpntr1[i]]; val_ptr = (*val)+(*indx)[(*bpntr)[row]]; val1_ptr = val1+indx1[bpntr1[i]]; for (j = 0; j<len_val; j++) { *val1_ptr = *val_ptr; val_ptr++; val1_ptr++; } } } printf("Processor %d of %d done with extracting local operators.\n", MyPID,NumProc) ; if (have_xexact) { printf( "The residual using VBR format and exact solution on processor %d is %12.4g\n", MyPID, Trilinos_Util_svbrres (N_local, *N_global, *N_update, val1, indx1, bindx1, rpntr1, (*rpntr), bpntr1, bpntr1+1, (*xexact), b1)); } /* Release memory for global matrix, rhs and solution */ free ((void *) (*val)); free ((void *) (*indx)); free ((void *) (*bindx)); free ((void *) (*bpntr)); free ((void *) (*rpntr)); free ((void *) (*b)); free ((void *) (*x)); if (have_xexact) free((void *) *xexact); /* Return local matrix through same pointers. */ *val = val1; *indx = indx1; *bindx = bindx1; *bpntr = bpntr1; *rpntr = rpntr1; *b = b1; *x = x1; if (have_xexact) *xexact = xexact1; } if (have_xexact && NumProc == 1) { printf( "The residual using VBR format and exact solution on processor %d is %12.4g\n", MyPID, Trilinos_Util_svbrres (*N_global, *N_global, *N_update, (*val), (*indx), (*bindx), (*rpntr), (*rpntr), (*bpntr), (*bpntr)+1, (*xexact), (*b))); } printf("Processor %d of %d leaving distrib_matrix.\n", MyPID,NumProc) ; /* end distrib_matrix */ }
// // Amesos_TestMultiSolver.cpp reads in a matrix in Harwell-Boeing format, // calls one of the sparse direct solvers, using blocked right hand sides // and computes the error and residual. // // TestSolver ignores the Harwell-Boeing right hand sides, creating // random right hand sides instead. // // Amesos_TestMultiSolver can test either A x = b or A^T x = b. // This can be a bit confusing because sparse direct solvers // use compressed column storage - the transpose of Trilinos' // sparse row storage. // // Matrices: // readA - Serial. As read from the file. // transposeA - Serial. The transpose of readA. // serialA - if (transpose) then transposeA else readA // distributedA - readA distributed to all processes // passA - if ( distributed ) then distributedA else serialA // // int Amesos_TestMultiSolver( Epetra_Comm &Comm, char *matrix_file, int numsolves, SparseSolverType SparseSolver, bool transpose, int special, AMESOS_MatrixType matrix_type ) { int iam = Comm.MyPID() ; // int hatever; // if ( iam == 0 ) std::cin >> hatever ; Comm.Barrier(); Epetra_Map * readMap; Epetra_CrsMatrix * readA; Epetra_Vector * readx; Epetra_Vector * readb; Epetra_Vector * readxexact; std::string FileName = matrix_file ; int FN_Size = FileName.size() ; std::string LastFiveBytes = FileName.substr( EPETRA_MAX(0,FN_Size-5), FN_Size ); std::string LastFourBytes = FileName.substr( EPETRA_MAX(0,FN_Size-4), FN_Size ); bool NonContiguousMap = false; if ( LastFiveBytes == ".triU" ) { NonContiguousMap = true; // Call routine to read in unsymmetric Triplet matrix EPETRA_CHK_ERR( Trilinos_Util_ReadTriples2Epetra( matrix_file, false, Comm, readMap, readA, readx, readb, readxexact, NonContiguousMap ) ); } else { if ( LastFiveBytes == ".triS" ) { NonContiguousMap = true; // Call routine to read in symmetric Triplet matrix EPETRA_CHK_ERR( Trilinos_Util_ReadTriples2Epetra( matrix_file, true, Comm, readMap, readA, readx, readb, readxexact, NonContiguousMap ) ); } else { if ( LastFourBytes == ".mtx" ) { EPETRA_CHK_ERR( Trilinos_Util_ReadMatrixMarket2Epetra( matrix_file, Comm, readMap, readA, readx, readb, readxexact) ); } else { // Call routine to read in HB problem Trilinos_Util_ReadHb2Epetra( matrix_file, Comm, readMap, readA, readx, readb, readxexact) ; } } } Epetra_CrsMatrix transposeA(Copy, *readMap, 0); Epetra_CrsMatrix *serialA ; if ( transpose ) { assert( CrsMatrixTranspose( readA, &transposeA ) == 0 ); serialA = &transposeA ; } else { serialA = readA ; } // Create uniform distributed map Epetra_Map map(readMap->NumGlobalElements(), 0, Comm); Epetra_Map* map_; if( NonContiguousMap ) { // // map gives us NumMyElements and MyFirstElement; // int NumGlobalElements = readMap->NumGlobalElements(); int NumMyElements = map.NumMyElements(); int MyFirstElement = map.MinMyGID(); std::vector<int> MapMap_( NumGlobalElements ); readMap->MyGlobalElements( &MapMap_[0] ) ; Comm.Broadcast( &MapMap_[0], NumGlobalElements, 0 ) ; map_ = new Epetra_Map( NumGlobalElements, NumMyElements, &MapMap_[MyFirstElement], 0, Comm); } else { map_ = new Epetra_Map( map ) ; } // Create Exporter to distribute read-in matrix and vectors Epetra_Export exporter(*readMap, *map_); Epetra_CrsMatrix A(Copy, *map_, 0); Epetra_RowMatrix * passA = 0; Epetra_MultiVector * passx = 0; Epetra_MultiVector * passb = 0; Epetra_MultiVector * passxexact = 0; Epetra_MultiVector * passresid = 0; Epetra_MultiVector * passtmp = 0; Epetra_MultiVector x(*map_,numsolves); Epetra_MultiVector b(*map_,numsolves); Epetra_MultiVector xexact(*map_,numsolves); Epetra_MultiVector resid(*map_,numsolves); Epetra_MultiVector tmp(*map_,numsolves); Epetra_MultiVector serialx(*readMap,numsolves); Epetra_MultiVector serialb(*readMap,numsolves); Epetra_MultiVector serialxexact(*readMap,numsolves); Epetra_MultiVector serialresid(*readMap,numsolves); Epetra_MultiVector serialtmp(*readMap,numsolves); bool distribute_matrix = ( matrix_type == AMESOS_Distributed ) ; if ( distribute_matrix ) { // // Initialize x, b and xexact to the values read in from the file // A.Export(*serialA, exporter, Add); Comm.Barrier(); assert(A.FillComplete()==0); Comm.Barrier(); passA = &A; passx = &x; passb = &b; passxexact = &xexact; passresid = &resid; passtmp = &tmp; } else { passA = serialA; passx = &serialx; passb = &serialb; passxexact = &serialxexact; passresid = &serialresid; passtmp = &serialtmp; } passxexact->SetSeed(131) ; passxexact->Random(); passx->SetSeed(11231) ; passx->Random(); passb->PutScalar( 0.0 ); passA->Multiply( transpose, *passxexact, *passb ) ; Epetra_MultiVector CopyB( *passb ) ; double Anorm = passA->NormInf() ; SparseDirectTimingVars::SS_Result.Set_Anorm(Anorm) ; Epetra_LinearProblem Problem( (Epetra_RowMatrix *) passA, (Epetra_MultiVector *) passx, (Epetra_MultiVector *) passb ); double max_resid = 0.0; for ( int j = 0 ; j < special+1 ; j++ ) { Epetra_Time TotalTime( Comm ) ; if ( false ) { #ifdef TEST_UMFPACK unused code } else if ( SparseSolver == UMFPACK ) { UmfpackOO umfpack( (Epetra_RowMatrix *) passA, (Epetra_MultiVector *) passx, (Epetra_MultiVector *) passb ) ; umfpack.SetTrans( transpose ) ; umfpack.Solve() ; #endif #ifdef TEST_SUPERLU } else if ( SparseSolver == SuperLU ) { SuperluserialOO superluserial( (Epetra_RowMatrix *) passA, (Epetra_MultiVector *) passx, (Epetra_MultiVector *) passb ) ; superluserial.SetPermc( SuperLU_permc ) ; superluserial.SetTrans( transpose ) ; superluserial.SetUseDGSSV( special == 0 ) ; superluserial.Solve() ; #endif #ifdef HAVE_AMESOS_SLUD } else if ( SparseSolver == SuperLUdist ) { SuperludistOO superludist( Problem ) ; superludist.SetTrans( transpose ) ; EPETRA_CHK_ERR( superludist.Solve( true ) ) ; #endif #ifdef HAVE_AMESOS_SLUD2 } else if ( SparseSolver == SuperLUdist2 ) { Superludist2_OO superludist2( Problem ) ; superludist2.SetTrans( transpose ) ; EPETRA_CHK_ERR( superludist2.Solve( true ) ) ; #endif #ifdef TEST_SPOOLES } else if ( SparseSolver == SPOOLES ) { SpoolesOO spooles( (Epetra_RowMatrix *) passA, (Epetra_MultiVector *) passx, (Epetra_MultiVector *) passb ) ; spooles.SetTrans( transpose ) ; spooles.Solve() ; #endif #ifdef HAVE_AMESOS_DSCPACK } else if ( SparseSolver == DSCPACK ) { Teuchos::ParameterList ParamList ; Amesos_Dscpack dscpack( Problem ) ; ParamList.set( "MaxProcs", -3 ); EPETRA_CHK_ERR( dscpack.SetParameters( ParamList ) ); EPETRA_CHK_ERR( dscpack.Solve( ) ); #endif #ifdef HAVE_AMESOS_UMFPACK } else if ( SparseSolver == UMFPACK ) { Teuchos::ParameterList ParamList ; Amesos_Umfpack umfpack( Problem ) ; ParamList.set( "MaxProcs", -3 ); EPETRA_CHK_ERR( umfpack.SetParameters( ParamList ) ); EPETRA_CHK_ERR( umfpack.SetUseTranspose( transpose ) ); EPETRA_CHK_ERR( umfpack.Solve( ) ); #endif #ifdef HAVE_AMESOS_KLU } else if ( SparseSolver == KLU ) { Teuchos::ParameterList ParamList ; Amesos_Klu klu( Problem ) ; ParamList.set( "MaxProcs", -3 ); EPETRA_CHK_ERR( klu.SetParameters( ParamList ) ); EPETRA_CHK_ERR( klu.SetUseTranspose( transpose ) ); EPETRA_CHK_ERR( klu.SymbolicFactorization( ) ); EPETRA_CHK_ERR( klu.NumericFactorization( ) ); EPETRA_CHK_ERR( klu.Solve( ) ); #endif #ifdef HAVE_AMESOS_PARAKLETE } else if ( SparseSolver == PARAKLETE ) { Teuchos::ParameterList ParamList ; Amesos_Paraklete paraklete( Problem ) ; ParamList.set( "MaxProcs", -3 ); EPETRA_CHK_ERR( paraklete.SetParameters( ParamList ) ); EPETRA_CHK_ERR( paraklete.SetUseTranspose( transpose ) ); EPETRA_CHK_ERR( paraklete.SymbolicFactorization( ) ); EPETRA_CHK_ERR( paraklete.NumericFactorization( ) ); EPETRA_CHK_ERR( paraklete.Solve( ) ); #endif #ifdef HAVE_AMESOS_SLUS } else if ( SparseSolver == SuperLU ) { Epetra_SLU superluserial( &Problem ) ; EPETRA_CHK_ERR( superluserial.SetUseTranspose( transpose ) ); EPETRA_CHK_ERR( superluserial.SymbolicFactorization( ) ); EPETRA_CHK_ERR( superluserial.NumericFactorization( ) ); EPETRA_CHK_ERR( superluserial.Solve( ) ); #endif #ifdef HAVE_AMESOS_LAPACK } else if ( SparseSolver == LAPACK ) { Teuchos::ParameterList ParamList ; ParamList.set( "MaxProcs", -3 ); Amesos_Lapack lapack( Problem ) ; EPETRA_CHK_ERR( lapack.SetUseTranspose( transpose ) ); EPETRA_CHK_ERR( lapack.SymbolicFactorization( ) ); EPETRA_CHK_ERR( lapack.NumericFactorization( ) ); EPETRA_CHK_ERR( lapack.Solve( ) ); #endif #ifdef HAVE_AMESOS_TAUCS } else if ( SparseSolver == TAUCS ) { Teuchos::ParameterList ParamList ; Amesos_Taucs taucs( Problem ) ; ParamList.set( "MaxProcs", -3 ); EPETRA_CHK_ERR( taucs.SetParameters( ParamList ) ); EPETRA_CHK_ERR( taucs.SetUseTranspose( transpose ) ); EPETRA_CHK_ERR( taucs.SymbolicFactorization( ) ); EPETRA_CHK_ERR( taucs.NumericFactorization( ) ); EPETRA_CHK_ERR( taucs.Solve( ) ); #endif #ifdef HAVE_AMESOS_PARDISO } else if ( SparseSolver == PARDISO ) { Teuchos::ParameterList ParamList ; Amesos_Pardiso pardiso( Problem ) ; ParamList.set( "MaxProcs", -3 ); EPETRA_CHK_ERR( pardiso.SetParameters( ParamList ) ); EPETRA_CHK_ERR( pardiso.SetUseTranspose( transpose ) ); EPETRA_CHK_ERR( pardiso.SymbolicFactorization( ) ); EPETRA_CHK_ERR( pardiso.NumericFactorization( ) ); EPETRA_CHK_ERR( pardiso.Solve( ) ); #endif #ifdef HAVE_AMESOS_PARKLETE } else if ( SparseSolver == PARKLETE ) { Teuchos::ParameterList ParamList ; Amesos_Parklete parklete( Problem ) ; ParamList.set( "MaxProcs", -3 ); EPETRA_CHK_ERR( parklete.SetParameters( ParamList ) ); EPETRA_CHK_ERR( parklete.SetUseTranspose( transpose ) ); EPETRA_CHK_ERR( parklete.SymbolicFactorization( ) ); EPETRA_CHK_ERR( parklete.NumericFactorization( ) ); EPETRA_CHK_ERR( parklete.Solve( ) ); #endif #ifdef HAVE_AMESOS_MUMPS } else if ( SparseSolver == MUMPS ) { Teuchos::ParameterList ParamList ; Amesos_Mumps mumps( Problem ) ; ParamList.set( "MaxProcs", -3 ); EPETRA_CHK_ERR( mumps.SetParameters( ParamList ) ); EPETRA_CHK_ERR( mumps.SetUseTranspose( transpose ) ); EPETRA_CHK_ERR( mumps.SymbolicFactorization( ) ); EPETRA_CHK_ERR( mumps.NumericFactorization( ) ); EPETRA_CHK_ERR( mumps.Solve( ) ); #endif #ifdef HAVE_AMESOS_SCALAPACK } else if ( SparseSolver == SCALAPACK ) { Teuchos::ParameterList ParamList ; Amesos_Scalapack scalapack( Problem ) ; ParamList.set( "MaxProcs", -3 ); EPETRA_CHK_ERR( scalapack.SetParameters( ParamList ) ); EPETRA_CHK_ERR( scalapack.SetUseTranspose( transpose ) ); EPETRA_CHK_ERR( scalapack.SymbolicFactorization( ) ); EPETRA_CHK_ERR( scalapack.NumericFactorization( ) ); EPETRA_CHK_ERR( scalapack.Solve( ) ); #endif #ifdef HAVE_AMESOS_SUPERLUDIST } else if ( SparseSolver == SUPERLUDIST ) { Teuchos::ParameterList ParamList ; Amesos_Superludist superludist( Problem ) ; ParamList.set( "MaxProcs", -3 ); EPETRA_CHK_ERR( superludist.SetParameters( ParamList ) ); EPETRA_CHK_ERR( superludist.SetUseTranspose( transpose ) ); EPETRA_CHK_ERR( superludist.SymbolicFactorization( ) ); EPETRA_CHK_ERR( superludist.NumericFactorization( ) ); EPETRA_CHK_ERR( superludist.Solve( ) ); #endif #ifdef HAVE_AMESOS_SUPERLU } else if ( SparseSolver == SUPERLU ) { Teuchos::ParameterList ParamList ; Amesos_Superlu superlu( Problem ) ; ParamList.set( "MaxProcs", -3 ); EPETRA_CHK_ERR( superlu.SetParameters( ParamList ) ); EPETRA_CHK_ERR( superlu.SetUseTranspose( transpose ) ); EPETRA_CHK_ERR( superlu.SymbolicFactorization( ) ); EPETRA_CHK_ERR( superlu.NumericFactorization( ) ); EPETRA_CHK_ERR( superlu.Solve( ) ); #endif #ifdef TEST_SPOOLESSERIAL } else if ( SparseSolver == SPOOLESSERIAL ) { SpoolesserialOO spoolesserial( (Epetra_RowMatrix *) passA, (Epetra_MultiVector *) passx, (Epetra_MultiVector *) passb ) ; spoolesserial.Solve() ; #endif } else { SparseDirectTimingVars::log_file << "Solver not implemented yet" << std::endl ; std::cerr << "\n\n#################### Requested solver not available (Or not tested with blocked RHS) on this platform #####################\n" << std::endl ; } SparseDirectTimingVars::SS_Result.Set_Total_Time( TotalTime.ElapsedTime() ); // SparseDirectTimingVars::SS_Result.Set_First_Time( 0.0 ); // SparseDirectTimingVars::SS_Result.Set_Middle_Time( 0.0 ); // SparseDirectTimingVars::SS_Result.Set_Last_Time( 0.0 ); // // Compute the error = norm(xcomp - xexact ) // std::vector <double> error(numsolves) ; double max_error = 0.0; passresid->Update(1.0, *passx, -1.0, *passxexact, 0.0); passresid->Norm2(&error[0]); for ( int i = 0 ; i< numsolves; i++ ) if ( error[i] > max_error ) max_error = error[i] ; SparseDirectTimingVars::SS_Result.Set_Error(max_error) ; // passxexact->Norm2(&error[0] ) ; // passx->Norm2(&error ) ; // // Compute the residual = norm(Ax - b) // std::vector <double> residual(numsolves) ; passtmp->PutScalar(0.0); passA->Multiply( transpose, *passx, *passtmp); passresid->Update(1.0, *passtmp, -1.0, *passb, 0.0); // passresid->Update(1.0, *passtmp, -1.0, CopyB, 0.0); passresid->Norm2(&residual[0]); for ( int i = 0 ; i< numsolves; i++ ) if ( residual[i] > max_resid ) max_resid = residual[i] ; SparseDirectTimingVars::SS_Result.Set_Residual(max_resid) ; std::vector <double> bnorm(numsolves); passb->Norm2( &bnorm[0] ) ; SparseDirectTimingVars::SS_Result.Set_Bnorm(bnorm[0]) ; std::vector <double> xnorm(numsolves); passx->Norm2( &xnorm[0] ) ; SparseDirectTimingVars::SS_Result.Set_Xnorm(xnorm[0]) ; if ( false && iam == 0 ) { std::cout << " Amesos_TestMutliSolver.cpp " << std::endl ; for ( int i = 0 ; i< numsolves && i < 10 ; i++ ) { std::cout << "i=" << i << " error = " << error[i] << " xnorm = " << xnorm[i] << " residual = " << residual[i] << " bnorm = " << bnorm[i] << std::endl ; } std::cout << std::endl << " max_resid = " << max_resid ; std::cout << " max_error = " << max_error << std::endl ; std::cout << " Get_residual() again = " << SparseDirectTimingVars::SS_Result.Get_Residual() << std::endl ; } } delete readA; delete readx; delete readb; delete readxexact; delete readMap; delete map_; Comm.Barrier(); return 0 ; }
int tcubed_test(int NumGlobalElements, bool verbose, Epetra_Comm& Comm, bool includeUV, bool useP, const std::string& prec, const std::string& prec_method) { int ierr = 0; int MyPID = Comm.MyPID(); if (MyPID == 0) { std::cout << "********** " << "Testing includeUV = " << includeUV << " useP = " << useP << " Preconditioner = " << prec << " Preconditioner method = " << prec_method << " **********" << std::endl; } try { double nonlinear_factor = 1.0; double left_bc = 0.0; double right_bc = 2.07; // Create the FiniteElementProblem class. This creates all required // Epetra objects for the problem and allows calls to the // function (RHS) and Jacobian evaluation routines. Tcubed_FiniteElementProblem Problem(NumGlobalElements, Comm); // Get the vector from the Problem Epetra_Vector& soln = Problem.getSolution(); // Initialize Solution soln.PutScalar(1.0); // Create initial guess for the null vector of jacobian // Only needed for Moore-Spence Teuchos::RCP<NOX::Abstract::Vector> nullVec = Teuchos::rcp(new NOX::Epetra::Vector(soln)); nullVec->init(1.0); // initial value 1.0 // Begin LOCA Solver ************************************ // Create parameter list Teuchos::RCP<Teuchos::ParameterList> paramList = Teuchos::rcp(new Teuchos::ParameterList); // Create LOCA sublist Teuchos::ParameterList& locaParamsList = paramList->sublist("LOCA"); // Create the stepper sublist and set the stepper parameters Teuchos::ParameterList& locaStepperList = locaParamsList.sublist("Stepper"); locaStepperList.set("Continuation Method", "Arc Length"); locaStepperList.set("Continuation Parameter", "Nonlinear Factor"); locaStepperList.set("Initial Value", nonlinear_factor); locaStepperList.set("Max Value", 2.0); locaStepperList.set("Min Value", 0.05); locaStepperList.set("Max Steps", 20); locaStepperList.set("Max Nonlinear Iterations", 15); locaStepperList.set("Bordered Solver Method", "Nested"); Teuchos::ParameterList& nestedList = locaStepperList.sublist("Nested Bordered Solver"); nestedList.set("Bordered Solver Method", "Householder"); nestedList.set("Include UV In Preconditioner", includeUV); nestedList.set("Use P For Preconditioner", useP); // Create bifurcation sublist Teuchos::ParameterList& bifurcationList = locaParamsList.sublist("Bifurcation"); bifurcationList.set("Type", "Turning Point"); bifurcationList.set("Bifurcation Parameter", "Right BC"); bifurcationList.set("Formulation", "Minimally Augmented"); bifurcationList.set("Symmetric Jacobian", false); bifurcationList.set("Update Null Vectors Every Continuation Step", true); bifurcationList.set("Update Null Vectors Every Nonlinear Iteration", false); bifurcationList.set("Transpose Solver Method",prec); bifurcationList.set("Multiply Null Vectors by Mass Matrix", true); // The others don't seem to work with "Solve df/dp" if (prec == "Explicit Transpose") bifurcationList.set("Initial Null Vector Computation", "Solve df/dp"); else { bifurcationList.set("Initial A Vector", nullVec); bifurcationList.set("Initial B Vector", nullVec); } bifurcationList.set("Bordered Solver Method", "Householder"); bifurcationList.set("Include UV In Preconditioner", includeUV); bifurcationList.set("Use P For Preconditioner", useP); bifurcationList.set("Preconditioner Method", prec_method); //bifurcationList.set("Formulation", "Moore-Spence"); //bifurcationList.set("Solver Method", "Phipps Bordering"); //bifurcationList.set("Solver Method", "Salinger Bordering"); //bifurcationList.set("Initial Null Vector", nullVec); //bifurcationList.set("Length Normalization Vector", nullVec); // Create predictor sublist Teuchos::ParameterList& predictorList = locaParamsList.sublist("Predictor"); predictorList.set("Method", "Secant"); // Create step size sublist Teuchos::ParameterList& stepSizeList = locaParamsList.sublist("Step Size"); stepSizeList.set("Method", "Adaptive"); stepSizeList.set("Initial Step Size", 0.1); stepSizeList.set("Min Step Size", 1.0e-3); stepSizeList.set("Max Step Size", 2000.0); stepSizeList.set("Aggressiveness", 0.1); // Create the "Solver" parameters sublist to be used with NOX Solvers Teuchos::ParameterList& nlParams = paramList->sublist("NOX"); // Create the NOX printing parameter list Teuchos::ParameterList& nlPrintParams = nlParams.sublist("Printing"); nlPrintParams.set("MyPID", MyPID); nlPrintParams.set("Output Precision", 4); if (verbose) nlPrintParams.set("Output Information", NOX::Utils::OuterIteration + NOX::Utils::OuterIterationStatusTest + NOX::Utils::InnerIteration + NOX::Utils::Details + NOX::Utils::LinearSolverDetails + NOX::Utils::Warning + NOX::Utils::TestDetails + NOX::Utils::Error + NOX::Utils::StepperIteration + NOX::Utils::StepperDetails + NOX::Utils::StepperParameters); else nlPrintParams.set("Output Information", NOX::Utils::Error); // Create the "Linear Solver" sublist for Newton's method Teuchos::ParameterList& dirParams = nlParams.sublist("Direction"); Teuchos::ParameterList& newParams = dirParams.sublist("Newton"); Teuchos::ParameterList& lsParams = newParams.sublist("Linear Solver"); lsParams.set("Aztec Solver", "GMRES"); lsParams.set("Max Iterations", 200); lsParams.set("Tolerance", 1e-6); lsParams.set("Output Frequency", 50); //lsParams.set("Scaling", "None"); //lsParams.set("Scaling", "Row Sum"); lsParams.set("Compute Scaling Manually", false); //lsParams.set("Preconditioner", "Ifpack"); lsParams.set("Preconditioner", "New Ifpack"); lsParams.set("Ifpack Preconditioner", "ILU"); // Create and initialize the parameter vector LOCA::ParameterVector pVector; pVector.addParameter("Nonlinear Factor",nonlinear_factor); pVector.addParameter("Left BC", left_bc); pVector.addParameter("Right BC", right_bc); // Create the interface between the test problem and the nonlinear solver // This is created by the user using inheritance of the abstract base class Teuchos::RCP<Problem_Interface> interface = Teuchos::rcp(new Problem_Interface(Problem)); Teuchos::RCP<LOCA::Epetra::Interface::TimeDependent> iReq = interface; Teuchos::RCP<NOX::Epetra::Interface::Jacobian> iJac = interface; // Create the Epetra_RowMatrixfor the Jacobian/Preconditioner Teuchos::RCP<Epetra_RowMatrix> Amat = Teuchos::rcp(&Problem.getJacobian(),false); // Create scaling object Teuchos::RCP<NOX::Epetra::Scaling> scaling = Teuchos::null; // scaling = Teuchos::rcp(new NOX::Epetra::Scaling); // Teuchos::RCP<Epetra_Vector> scalingVector = // Teuchos::rcp(new Epetra_Vector(soln.Map())); // //scaling->addRowSumScaling(NOX::Epetra::Scaling::Left, scalingVector); // scaling->addColSumScaling(NOX::Epetra::Scaling::Right, scalingVector); // Create transpose scaling object // Teuchos::RCP<NOX::Epetra::Scaling> trans_scaling = Teuchos::null; // trans_scaling = Teuchos::rcp(new NOX::Epetra::Scaling); // Teuchos::RCP<Epetra_Vector> transScalingVector = // Teuchos::rcp(new Epetra_Vector(soln.Map())); // trans_scaling->addRowSumScaling(NOX::Epetra::Scaling::Right, // transScalingVector); // trans_scaling->addColSumScaling(NOX::Epetra::Scaling::Left, // transScalingVector); // //bifurcationList.set("Transpose Scaling", trans_scaling); // Create the linear systems Teuchos::RCP<NOX::Epetra::LinearSystemAztecOO> linsys = Teuchos::rcp(new NOX::Epetra::LinearSystemAztecOO(nlPrintParams, lsParams, iReq, iJac, Amat, soln, scaling)); // Create the loca vector NOX::Epetra::Vector locaSoln(soln); // Create Epetra factory Teuchos::RCP<LOCA::Abstract::Factory> epetraFactory = Teuchos::rcp(new LOCA::Epetra::Factory); // Create global data object Teuchos::RCP<LOCA::GlobalData> globalData = LOCA::createGlobalData(paramList, epetraFactory); // Create the Group Teuchos::RCP<LOCA::Epetra::Group> grp = Teuchos::rcp(new LOCA::Epetra::Group(globalData, nlPrintParams, iReq, locaSoln, linsys, linsys, pVector)); grp->computeF(); // Create the Solver convergence test //NOX::StatusTest::NormWRMS wrms(1.0e-2, 1.0e-8); Teuchos::RCP<NOX::StatusTest::NormF> wrms = Teuchos::rcp(new NOX::StatusTest::NormF(1.0e-12)); Teuchos::RCP<NOX::StatusTest::MaxIters> maxiters = Teuchos::rcp(new NOX::StatusTest::MaxIters(locaStepperList.get("Max Nonlinear Iterations", 10))); Teuchos::RCP<NOX::StatusTest::Combo> combo = Teuchos::rcp(new NOX::StatusTest::Combo(NOX::StatusTest::Combo::OR)); combo->addStatusTest(wrms); combo->addStatusTest(maxiters); // Create the stepper LOCA::Stepper stepper(globalData, grp, combo, paramList); LOCA::Abstract::Iterator::IteratorStatus status = stepper.run(); if (status != LOCA::Abstract::Iterator::Finished) { ierr = 1; if (globalData->locaUtils->isPrintType(NOX::Utils::Error)) globalData->locaUtils->out() << "Stepper failed to converge!" << std::endl; } // Get the final solution from the stepper Teuchos::RCP<const LOCA::Epetra::Group> finalGroup = Teuchos::rcp_dynamic_cast<const LOCA::Epetra::Group>(stepper.getSolutionGroup()); const NOX::Epetra::Vector& finalSolution = dynamic_cast<const NOX::Epetra::Vector&>(finalGroup->getX()); // Output the parameter list if (globalData->locaUtils->isPrintType(NOX::Utils::StepperParameters)) { globalData->locaUtils->out() << std::endl << "Final Parameters" << std::endl << "****************" << std::endl; stepper.getList()->print(globalData->locaUtils->out()); globalData->locaUtils->out() << std::endl; } // Check some statistics on the solution NOX::TestCompare testCompare(globalData->locaUtils->out(), *(globalData->locaUtils)); if (globalData->locaUtils->isPrintType(NOX::Utils::TestDetails)) globalData->locaUtils->out() << std::endl << "***** Checking solution statistics *****" << std::endl; // Check number of steps int numSteps = stepper.getStepNumber(); int numSteps_expected = 7; ierr += testCompare.testValue(numSteps, numSteps_expected, 0.0, "number of continuation steps", NOX::TestCompare::Absolute); // Check number of failed steps int numFailedSteps = stepper.getNumFailedSteps(); int numFailedSteps_expected = 0; ierr += testCompare.testValue(numFailedSteps, numFailedSteps_expected, 0.0, "number of failed continuation steps", NOX::TestCompare::Absolute); // Check final value of continuation parameter double factor_final = finalGroup->getParam("Nonlinear Factor"); double factor_expected = 2.0; ierr += testCompare.testValue(factor_final, factor_expected, 1.0e-14, "final value of continuation parameter", NOX::TestCompare::Relative); // Check final value of bifurcation parameter double right_bc_final = finalGroup->getParam("Right BC"); double right_bc_expected = 1.47241293; ierr += testCompare.testValue(right_bc_final, right_bc_expected, 1.0e-7, "final value of bifurcation parameter", NOX::TestCompare::Relative); // Check norm of solution double norm_x = finalSolution.norm(); double norm_x_expected = 12.038464; ierr += testCompare.testValue(norm_x, norm_x_expected, 1.0e-7, "norm of final solution", NOX::TestCompare::Relative); LOCA::destroyGlobalData(globalData); } catch (std::exception& e) { std::cout << e.what() << std::endl; ierr = 1; } catch (const char *s) { std::cout << s << std::endl; ierr = 1; } catch (...) { std::cout << "Caught unknown exception!" << std::endl; ierr = 1; } return ierr ; }
void Trilinos_Util_ReadHpc2Epetra(char *data_file, const Epetra_Comm &comm, Epetra_Map *& map, Epetra_CrsMatrix *& A, Epetra_Vector *& x, Epetra_Vector *& b, Epetra_Vector *&xexact) { FILE *in_file ; int l; int * lp = &l; double v; double * vp = &v; #ifdef DEBUG bool debug = true; #else bool debug = false; #endif int size = comm.NumProc(); int rank = comm.MyPID(); printf("Reading matrix info from %s...\n",data_file); in_file = fopen( data_file, "r"); if (in_file == NULL) { printf("Error: Cannot open file: %s\n",data_file); exit(1); } int numGlobalEquations, total_nnz; fscanf(in_file,"%d",&numGlobalEquations); fscanf(in_file,"%d",&total_nnz); map = new Epetra_Map(numGlobalEquations, 0, comm); // Create map with uniform distribution A = new Epetra_CrsMatrix(Copy, *map, 0); // Construct matrix x = new Epetra_Vector(*map); b = new Epetra_Vector(*map); xexact = new Epetra_Vector(*map); int numMyEquations = map->NumMyPoints(); // Allocate arrays that are of length numMyEquations // Find max nnz per row for this processor int max_nnz = 0; for (int i=0; i<numGlobalEquations; i++) { fscanf(in_file, "%d",lp); /* row #, nnz in row */ if (map->MyGID(i)) max_nnz = EPETRA_MAX(max_nnz,l); } // Allocate arrays that are of length local_nnz double * list_of_vals = new double[max_nnz]; int *list_of_inds = new int [max_nnz]; {for (int i=0; i<numGlobalEquations; i++) { int cur_nnz; fscanf(in_file, "%d",&cur_nnz); if (map->MyGID(i)) // See if nnz for row should be added { if (debug) cout << "Process "<<rank <<" of "<<size<<" getting row "<<i<<endl; int nnz_kept = 0; for (int j=0; j<cur_nnz; j++) { fscanf(in_file, "%lf %d",vp,lp); if (v!=0.0) { list_of_vals[nnz_kept] = v; list_of_inds[nnz_kept] = l; nnz_kept++; } } A->InsertGlobalValues(i, nnz_kept, list_of_vals, list_of_inds); } else for (int j=0; j<cur_nnz; j++) fscanf(in_file, "%lf %d",vp,lp); // otherwise read and discard }} double xt, bt, xxt; {for (int i=0; i<numGlobalEquations; i++) { if (map->MyGID(i)) // See if entry should be added { if (debug) cout << "Process "<<rank<<" of " <<size<<" getting RHS "<<i<<endl; fscanf(in_file, "%lf %lf %lf",&xt, &bt, &xxt); int cur_local_row = map->LID(i); (*x)[cur_local_row] = xt; (*b)[cur_local_row] = bt; (*xexact)[cur_local_row] = xxt; } else fscanf(in_file, "%lf %lf %lf",vp, vp, vp); // or thrown away }} fclose(in_file); if (debug) cout << "Process "<<rank<<" of "<<size<<" has "<<numMyEquations << " rows. Min global row "<< map->MinMyGID() <<" Max global row "<< map->MaxMyGID() <<endl <<" and "<<A->NumMyNonzeros()<<" nonzeros."<<endl; A->FillComplete(); Epetra_Vector bcomp(*map); A->Multiply(false, *xexact, bcomp); double residual; bcomp.Norm2(&residual); if (comm.MyPID()==0) cout << "Norm of computed b = " << residual << endl; b->Norm2(&residual); if (comm.MyPID()==0) cout << "Norm of given b = " << residual << endl; bcomp.Update(-1.0, *b, 1.0); bcomp.Norm2(&residual); if (comm.MyPID()==0) cout << "Norm of difference between computed b and given b for xexact = " << residual << endl; delete [] list_of_vals; delete []list_of_inds; return; }
void Trilinos_Util_ReadHb2EpetraVbr(char *data_file, char * partitioning, const Epetra_Comm &comm, Epetra_BlockMap *& map, Epetra_VbrMatrix *& A, Epetra_Vector *& x, Epetra_Vector *& b, Epetra_Vector *&xexact) { /* Read matrix file and distribute among processors. Returns with this processor's set of rows */ int NumGlobalEquations = 0, NumMyNonzeros = 0; double *val_msr = 0, *x_in = 0, *b_in = 0, *xexact_in = 0; int *bindx_msr = 0; /* Set exact solution to NULL */ xexact = NULL; Trilinos_Util_read_hb(data_file, comm.MyPID(), &NumGlobalEquations, &NumMyNonzeros, &val_msr, &bindx_msr, &x_in, &b_in, &xexact_in); double *val = 0; int NumGlobalElements = 0; int *indx = 0, *rpntr = 0, *cpntr = 0, *bpntr = 0, *bindx = 0; int NumMyBlockEntries = 0, NumMyElements = 0, * MyGlobalElements = 0; Trilinos_Util_create_vbr(comm, partitioning, &NumGlobalEquations, &NumGlobalElements, &NumMyNonzeros, &NumMyBlockEntries, &NumMyElements, &MyGlobalElements, bindx_msr, val_msr, &val, &indx, &rpntr, &cpntr, &bpntr, &bindx); if(comm.MyPID()==0) { free ((void *) val_msr); free ((void *) bindx_msr); free ((void *) cpntr); } int * ElementSizeList = 0; if (NumMyElements>0) ElementSizeList = new int[NumMyElements]; for (int i=0; i<NumMyElements; i++) ElementSizeList[i] = rpntr[i+1] - rpntr[i]; map = new Epetra_BlockMap(-1, NumMyElements, MyGlobalElements, ElementSizeList, 0, comm); A = new Epetra_VbrMatrix(Copy, *map, 0); /* Add block rows one-at-a-time */ {for (int i=0; i<NumMyElements; i++) { int BlockRow = MyGlobalElements[i]; int NumBlockEntries = bpntr[i+1] - bpntr[i]; int *BlockIndices = bindx + bpntr[i]; int ierr = A->BeginInsertGlobalValues(BlockRow, NumBlockEntries, BlockIndices); if (ierr!=0) { cerr << "Error in BeginInsertGlobalValues(GlobalBlockRow = " << BlockRow << ") = " << ierr << endl; abort(); } int LDA = ElementSizeList[i]; int NumRows = LDA; for (int j=bpntr[i]; j<bpntr[i+1]; j++) { int NumCols = (indx[j+1] - indx[j])/LDA; double * Values = val + indx[j]; ierr = A->SubmitBlockEntry(Values, LDA, NumRows, NumCols); if (ierr!=0) { cerr << "Error in SubmitBlockEntry, GlobalBlockRow = " << BlockRow << "GlobalBlockCol = " << BlockIndices[j] << "Error = " << ierr << endl; abort(); } } ierr = A->EndSubmitEntries(); if (ierr!=0) { cerr << "Error in EndSubmitEntries(GlobalBlockRow = " << BlockRow << ") = " << ierr << endl; abort(); } }} int ierr=A->FillComplete(); if (ierr!=0) cerr << "Error in Epetra_VbrMatrix FillComplete ierr = " << ierr << endl; xexact = new Epetra_Vector(Copy, *map, xexact_in); x = new Epetra_Vector(Copy, *map, x_in); b = new Epetra_Vector(Copy, *map, b_in); if(comm.MyPID()==0) { free ((void *) val); free ((void *) indx); free ((void *) rpntr); free ((void *) bpntr); free ((void *) bindx); free ((void *) b_in); free ((void *) x_in); free ((void *) xexact_in); free ((void *) MyGlobalElements); delete [] ElementSizeList; } return; }
int TestOneMatrix( std::string HBname, std::string MMname, std::string TRIname, Epetra_Comm &Comm, bool verbose ) { if ( Comm.MyPID() != 0 ) verbose = false ; Epetra_Map * readMap = 0; Epetra_CrsMatrix * HbA = 0; Epetra_Vector * Hbx = 0; Epetra_Vector * Hbb = 0; Epetra_Vector * Hbxexact = 0; Epetra_CrsMatrix * TriplesA = 0; Epetra_Vector * Triplesx = 0; Epetra_Vector * Triplesb = 0; Epetra_Vector * Triplesxexact = 0; Epetra_CrsMatrix * MatrixMarketA = 0; Epetra_Vector * MatrixMarketx = 0; Epetra_Vector * MatrixMarketb = 0; Epetra_Vector * MatrixMarketxexact = 0; int TRI_Size = TRIname.size() ; std::string LastFiveBytes = TRIname.substr( EPETRA_MAX(0,TRI_Size-5), TRI_Size ); if ( LastFiveBytes == ".TimD" ) { // Call routine to read in a file with a Tim Davis header and zero-based indexing EPETRA_CHK_ERR( Trilinos_Util_ReadTriples2Epetra64( &TRIname[0], false, Comm, readMap, TriplesA, Triplesx, Triplesb, Triplesxexact, false, true, true ) ); delete readMap; } else { if ( LastFiveBytes == ".triU" ) { // Call routine to read in unsymmetric Triplet matrix EPETRA_CHK_ERR( Trilinos_Util_ReadTriples2Epetra64( &TRIname[0], false, Comm, readMap, TriplesA, Triplesx, Triplesb, Triplesxexact, false, false ) ); delete readMap; } else { if ( LastFiveBytes == ".triS" ) { // Call routine to read in symmetric Triplet matrix EPETRA_CHK_ERR( Trilinos_Util_ReadTriples2Epetra64( &TRIname[0], true, Comm, readMap, TriplesA, Triplesx, Triplesb, Triplesxexact, false, false ) ); delete readMap; } else { assert( false ) ; } } } EPETRA_CHK_ERR( Trilinos_Util_ReadMatrixMarket2Epetra64( &MMname[0], Comm, readMap, MatrixMarketA, MatrixMarketx, MatrixMarketb, MatrixMarketxexact) ); delete readMap; // Call routine to read in HB problem Trilinos_Util_ReadHb2Epetra64( &HBname[0], Comm, readMap, HbA, Hbx, Hbb, Hbxexact) ; #if 0 std::cout << " HbA " ; HbA->Print( std::cout ) ; std::cout << std::endl ; std::cout << " MatrixMarketA " ; MatrixMarketA->Print( std::cout ) ; std::cout << std::endl ; std::cout << " TriplesA " ; TriplesA->Print( std::cout ) ; std::cout << std::endl ; #endif int TripleErr = 0 ; int MMerr = 0 ; for ( int i = 0 ; i < 10 ; i++ ) { double resid_Hb_Triples; double resid_Hb_Matrix_Market; double norm_A ; Hbx->Random(); // // Set the output vectors to different values: // Triplesb->PutScalar(1.1); Hbb->PutScalar(1.2); MatrixMarketb->PutScalar(1.3); HbA->Multiply( false, *Hbx, *Hbb ); norm_A = HbA->NormOne( ) ; TriplesA->Multiply( false, *Hbx, *Triplesb ); Triplesb->Update( 1.0, *Hbb, -1.0 ) ; MatrixMarketA->Multiply( false, *Hbx, *MatrixMarketb ); MatrixMarketb->Update( 1.0, *Hbb, -1.0 ) ; Triplesb->Norm1( &resid_Hb_Triples ) ; MatrixMarketb->Norm1( &resid_Hb_Matrix_Market ) ; TripleErr += ( resid_Hb_Triples > 1e-11 * norm_A ) ; MMerr += ( resid_Hb_Matrix_Market > 1e-11 * norm_A ) ; if ( verbose && resid_Hb_Triples > 1e-11 * norm_A ) std::cout << " resid_Hb_Triples = " << resid_Hb_Triples << " norm_A = " << norm_A << std::endl ; if ( verbose && resid_Hb_Matrix_Market > 1e-11 * norm_A ) std::cout << " resid_Hb_Matrix_Market = " << resid_Hb_Matrix_Market << " norm_A = " << norm_A << std::endl ; } if ( verbose ) { if ( TripleErr ) std::cout << " Error in reading " << HBname << " or " << TRIname << std::endl ; if ( MMerr ) std::cout << " Error in reading " << HBname << " or " << MMname << std::endl ; } delete HbA; delete Hbx; delete Hbb; delete Hbxexact; delete TriplesA; delete Triplesx; delete Triplesb; delete Triplesxexact; delete MatrixMarketA; delete MatrixMarketx; delete MatrixMarketb; delete MatrixMarketxexact; delete readMap; return TripleErr+MMerr ; }