Commit d64fd943 by Dmitry Bagaev

### MatSolve ordering support

parent 2d7b7ecc
 ... ... @@ -14,6 +14,148 @@ using namespace INMOST; #define BARRIER #endif // developed by Igor Konshin #define NMAX 1024 //1024 // maximal pixel field dimension static int f[NMAX][NMAX]; // pixel field static int nm; // actual matrix dimention static int nf; // actual field dimention static double sc; // scaling indices from matrix to pixel field // Initialize print of matrix portrait into PS file void ps_init (int n) { nm = n; nf = (n <= NMAX) ? n : NMAX; sc = 1; if (nm > 1 && nm > nf) sc = (double)(nf-1)/(double)(nm-1); std::cout<<"::: nm="< 1) { for (int i=1; i 1.0) ? r : 1.0; //r = .2; output << 2*r << " setlinewidth" << std::endl; output << "/d {moveto currentpoint" << r << " 0 360 arc fill} def % x y" << std::endl; output << "n" << std::endl; std::stringstream ps(std::ios::in | std::ios::out); //ps << std::scientific; //ps.precision(2); for (int i=0; iBegin(); jt != it->End(); ++jt) ps_ij (row,jt->first); row++; } ps_file (file, NULL, NULL); } #endif //#define PS_MATR_SELFTEST_CRS #if defined (PS_MATR_SELFTEST_CRS) int main () { // [ 3 -1 -1 0 ] // A = [ -1 3 0 -1 ] // [ -1 0 3 -1 ] // [ 0 -1 -1 3 ] static int n=4; // nza=12; int ia[5] = { 0, 3, 6, 9, 12 }; //ia[n+1] int ja[12] = { 1,2,3, 1,2,4, 1,3,4, 2,3,4 }; //ja[nza] int nbl=2, ibl[3]={0,2,4}; ps_crs (n,nbl,ibl,ia,ja,"z.ps"); } #endif //#define PS_MATR_SELFTEST_0 #if defined (PS_MATR_SELFTEST_0) int main () { int nbl=3, ibl[4]={0,30,60,100}; ps_init (100); ps_ij (0,0); ps_ij (1,1); ps_ij (2,2); ps_ij (12,17); ps_ij (79,89); ps_ij (99,99); ps_file ("z.ps",nbl,ibl); } #endif int main(int argc, char **argv) { int processRank = 0, processorsCount = 1; ... ... @@ -29,12 +171,16 @@ int main(int argc, char **argv) { std::string vectorXFileName = ""; std::string parametersFileName = ""; std::string solverName = "inner_ilu2"; std::string orderingFileName = ""; bool matrixFound = false; bool vectorBFound = false; bool vectorXFound = false; bool parametersFound = false; bool typeFound = false; bool saveVector = false; bool orderingFound = false; //Parse argv parameters if (argc == 1) goto helpMessage; ... ... @@ -51,8 +197,10 @@ int main(int argc, char **argv) { std::cout << "Optional: " << std::endl; std::cout << "-b, --bvector " << std::endl; std::cout << "-x, --xvector " << std::endl; std::cout << "-p, --parameters " << std::endl; std::cout << "-d, --database " << std::endl; std::cout << "-t, --type " << std::endl; std::cout << "-ord, --ordering " << std::endl; std::cout << "-s, --save" << std::endl; std::cout << " Available solvers:" << std::endl; Solver::Initialize(NULL, NULL, NULL); std::vector availableSolvers = Solver::getAvailableSolvers(); ... ... @@ -102,8 +250,8 @@ int main(int argc, char **argv) { i++; continue; } //Parameters file name found with -p or --parameters options if (strcmp(argv[i], "-p") == 0 || strcmp(argv[i], "--parameters") == 0) { //Parameters file name found with -d or --database options if (strcmp(argv[i], "-d") == 0 || strcmp(argv[i], "--database") == 0) { if (processRank == 0) { std::cout << "Solver parameters file found: " << argv[i + 1] << std::endl; } ... ... @@ -112,6 +260,20 @@ int main(int argc, char **argv) { i++; continue; } //Ordering file name found with -ord or --parameters options if (strcmp(argv[i], "-ord") == 0 || strcmp(argv[i], "--ordering") == 0) { if (processRank == 0) { std::cout << "Ordering file found: " << argv[i + 1] << std::endl; } orderingFound = true; orderingFileName = std::string(argv[i + 1]); i++; continue; } if (strcmp(argv[i], "-s") == 0 || strcmp(argv[i], "--save") == 0) { saveVector = true; continue; } //Solver type found with -t ot --type options if (strcmp(argv[i], "-t") == 0 || strcmp(argv[i], "--type") == 0) { if (processRank == 0) { ... ... @@ -171,14 +333,28 @@ int main(int argc, char **argv) { Sparse::Vector b("rhs"); // Declare the right-hand side vector Sparse::Vector x("sol"); // Declare the solution vector double tempTimer = Timer(), solvingTimer; if (orderingFound) { if (processRank == 0) { std::cout << "Using ordering file " << orderingFileName << std::endl; } mat.Load(matrixFileName, ENUMUNDEF, ENUMUNDEF, orderingFileName); } else { mat.Load(matrixFileName); //if interval parameters not set, matrix will be divided automatically } if (processorsCount == 1) { ps_inmost(mat, "a.ps"); //db !IK! } BARRIER if (processRank == 0) { std::cout << "load matrix: " << Timer() - tempTimer << std::endl; } tempTimer = Timer(); if (vectorBFound) { b.Load(vectorBFileName); // Load RHS vector if (orderingFound) { b.Load(vectorBFileName, ENUMUNDEF, ENUMUNDEF, orderingFileName); // Load RHS vector with ordering } else { b.Load(vectorBFileName); //if interval parameters not set, matrix will be divided automatically } //b.Save(vectorBFileName + "_saved_test.rhs"); } else { // Set local RHS to 1 if it was not specified INMOST_DATA_ENUM_TYPE mbeg, mend, k; ... ... @@ -210,7 +386,10 @@ int main(int argc, char **argv) { iters = solver.Iterations(); // Get the number of iterations performed resid = solver.Residual(); // Get the final residual achieved reason = solver.ReturnReason(); // Get the convergence reason //x.Save("output.sol"); // Save the solution if required if (saveVector) { x.Save("output.sol"); // Save the solution if required } // Compute the true residual double aresid = 0, bresid = 0; ... ...
 // developed by Igor Konshin #include #include #include #include #define NMAX 1024 // maximal pixel field dimention static int f[NMAX][NMAX]; // pixel field static int nm; // actual matrix dimention static int nf; // actual field dimention static double sc; // scaling indices from matrix to pixel field // Initialize print of matrix portrait into PS file void ps_init (int n) { nm = n; nf = (n <= NMAX) ? n : NMAX; sc = 1; if (nm > 1 && nm > nf) sc = (double)(nf-1)/(double)(nm-1); std::cout<<"::: nm="< 1) { for (int i=1; i 1.0) ? r : 1.0; //r = .2; output << 2*r << " setlinewidth" << std::endl; output << "/d {moveto currentpoint" << r << " 0 360 arc fill} def % x y" << std::endl; output << "n" << std::endl; std::stringstream ps(std::ios::in | std::ios::out); //ps << std::scientific; //ps.precision(2); for (int i=0; iBegin(); jt != it->End(); ++jt) ps_ij (row,jt->first); row++; } ps_file (file, NULL, NULL); } #endif //#define PS_MATR_SELFTEST_CRS #if defined (PS_MATR_SELFTEST_CRS) int main () { // [ 3 -1 -1 0 ] // A = [ -1 3 0 -1 ] // [ -1 0 3 -1 ] // [ 0 -1 -1 3 ] static int n=4; // nza=12; int ia[5] = { 0, 3, 6, 9, 12 }; //ia[n+1] int ja[12] = { 1,2,3, 1,2,4, 1,3,4, 2,3,4 }; //ja[nza] int nbl=2, ibl[3]={0,2,4}; ps_crs (n,nbl,ibl,ia,ja,"z.ps"); } #endif //#define PS_MATR_SELFTEST_0 #if defined (PS_MATR_SELFTEST_0) int main () { int nbl=3, ibl[4]={0,30,60,100}; ps_init (100); ps_ij (0,0); ps_ij (1,1); ps_ij (2,2); ps_ij (12,17); ps_ij (79,89); ps_ij (99,99); ps_file ("z.ps",nbl,ibl); } #endif
 ... ... @@ -100,7 +100,7 @@ namespace INMOST /// Load the vector from a single data file using the specified interval. /// If interval is not specified, then it will be automatically constructed, /// with the about equal block size (the last block may has larger dimension). void Load(std::string file, INMOST_DATA_ENUM_TYPE mbeg = ENUMUNDEF, INMOST_DATA_ENUM_TYPE mend = ENUMUNDEF); void Load(std::string file, INMOST_DATA_ENUM_TYPE mbeg = ENUMUNDEF, INMOST_DATA_ENUM_TYPE mend = ENUMUNDEF, std::string file_ord = ""); bool & isParallel() {return is_parallel;} /// Get the vector name specified in the main constructor. ... ... @@ -417,7 +417,7 @@ namespace INMOST /// Load the matrix from a single data file in MTX format using the specified interval. /// If interval is not specified, then it will be automatically constructed, /// with the about equal block size (the last block may has larger dimension). void Load(std::string file, INMOST_DATA_ENUM_TYPE beg = ENUMUNDEF, INMOST_DATA_ENUM_TYPE end = ENUMUNDEF); void Load(std::string file, INMOST_DATA_ENUM_TYPE beg = ENUMUNDEF, INMOST_DATA_ENUM_TYPE end = ENUMUNDEF, std::string file_ord = ""); /// Save the distributed matrix to a single data file in MTX format using parallel MPI I/O. /// @see http://math.nist.gov/MatrixMarket/formats.html void Save(std::string file, const AnnotationService * annotation = NULL); ... ...
 ... ... @@ -662,7 +662,7 @@ namespace INMOST { } void Vector::Load(std::string file, INMOST_DATA_ENUM_TYPE mbeg, INMOST_DATA_ENUM_TYPE mend) void Vector::Load(std::string file, INMOST_DATA_ENUM_TYPE mbeg, INMOST_DATA_ENUM_TYPE mend, std::string file_ord) { char str[16384]; std::ifstream input(file.c_str()); ... ... @@ -680,6 +680,30 @@ namespace INMOST MPI_Comm_size(GetCommunicator(),&size); } #endif int * ord = NULL; if (file_ord != "") { std::ifstream input_ord; input_ord.open(file_ord.c_str(), std::ifstream::in); if( input_ord.fail() ) throw -2; int n; input_ord >> n; ord = (int *) malloc(sizeof(int) * n); for (int i=0; i> ord[i]; int nbl; input_ord >> nbl; if( nbl != size ) throw -3; int * ibl; ibl = (int *) malloc(sizeof(int) * (nbl+1)); for (int i=0; i> ibl[i]; if( mbeg == ENUMUNDEF ) mbeg = ibl[rank]; if( mend == ENUMUNDEF ) mend = ibl[rank+1]; for (int i=0; iSize(); //~ std::cout << rank << " total nonzero " << max_lines << " my nonzero " << nonzero << std::endl; input.close(); if (file_ord != "") free(ord); } void Matrix::Save(std::string file, const AnnotationService * text) ... ... @@ -1149,7 +1179,7 @@ namespace INMOST ////////class HessianMatrix void HessianMatrix::Load(std::string file, INMOST_DATA_ENUM_TYPE mbeg, INMOST_DATA_ENUM_TYPE mend) void HessianMatrix::Load(std::string file, INMOST_DATA_ENUM_TYPE mbeg, INMOST_DATA_ENUM_TYPE mend, std::string file_ord) { char str[16384]; std::ifstream input(file.c_str()); ... ...
 ... ... @@ -71,6 +71,10 @@ if(USE_SOLVER_ANI) add_test(NAME solver_test000_serial_ani COMMAND \$ 0 ani) endif() if(SOLVER_DEFINITIONS MATCHES "^.*HAVE_SOLVER_FCBIILU2.*\$") add_test(NAME solver_test000_serial_fcbiilu2 COMMAND \$ 0 fcbiilu2) endif() if( USE_MPI ) if( EXISTS \${MPIEXEC} ) add_test(NAME solver_test000_parallel_normal_inner_ilu2 COMMAND \${MPIEXEC} -np 4 \$ 0 inner_ilu2) ... ... @@ -114,5 +118,10 @@ add_test(NAME solver_test000_parallel_permute2_trilinos_ml COMMAND \${MPIEXEC #add_test(NAME solver_test000_parallel_permute1_trilinos_belos COMMAND \${MPIEXEC} -np 4 \$ 1 6) #add_test(NAME solver_test000_parallel_permute2_trilinos_belos COMMAND \${MPIEXEC} -np 4 \$ 2 6) endif() if(SOLVER_DEFINITIONS MATCHES "^.*HAVE_SOLVER_FCBIILU2.*\$") add_test(NAME solver_test000_parallel_normal_fcbiilu2 COMMAND \${MPIEXEC} -np 4 \$ 0 fcbiilu2) endif() endif() endif()
 ... ... @@ -51,6 +51,9 @@ endif() if(HAVE_SOLVER_MPTILU2) add_test(NAME solver_test002_serial_inner_mptilu2 COMMAND \$ inner_mptilu2 20) endif() if(SOLVER_DEFINITIONS MATCHES "^.*HAVE_SOLVER_FCBIILU2.*\$") add_test(NAME solver_test002_serial_fcbiilu2 COMMAND \$ fcbiilu2 20) endif() if(USE_SOLVER_TRILINOS AND USE_MPI) add_test(NAME solver_test002_serial_trilinos_aztec COMMAND \$ trilinos_aztec 20) ... ... @@ -87,5 +90,9 @@ if(USE_SOLVER_PETSC) add_test(NAME solver_test002_parallel_petsc COMMAND \${MPIEXEC} -np 4 \$ petsc 20) endif() if(SOLVER_DEFINITIONS MATCHES "^.*HAVE_SOLVER_FCBIILU2.*\$") add_test(NAME solver_test002_parallel_fcbiilu2 COMMAND \$ fcbiilu2 20) endif() endif() endif()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment