diff --git a/SimpleTests/MatrixTests/CMakeLists.txt b/SimpleTests/MatrixTests/CMakeLists.txt index 46b7b4260f4d8257225209b618c63f6d43717c3a..445aa4d05c7ed75887ec4857e03048966adac296 100644 --- a/SimpleTests/MatrixTests/CMakeLists.txt +++ b/SimpleTests/MatrixTests/CMakeLists.txt @@ -1,90 +1,90 @@ if(CMAKE_USE_PTHREADS_INIT) - set(HAVE_PTHREADS TRUE) + set(HAVE_PTHREADS TRUE) endif() # Create the executable add_executable(MatMult - MatMult.cpp - ${SOURCES} - ${HEADERS} + MatMult.cpp + ${SOURCES} + ${HEADERS} ) set_target_properties(MatMult PROPERTIES FOLDER SimpleTests) target_link_libraries(MatMult logog) if(HAVE_PTHREADS) - add_executable(MatVecMultPthreads - MatVecMultPthreads.cpp - ${SOURCES} - ${HEADERS} - ) - set_target_properties(MatVecMultPthreads PROPERTIES FOLDER SimpleTests) - target_link_libraries(MatVecMultPthreads - pthread - BaseLib - MathLib - logog - ) + add_executable(MatVecMultPthreads + MatVecMultPthreads.cpp + ${SOURCES} + ${HEADERS} + ) + set_target_properties(MatVecMultPthreads PROPERTIES FOLDER SimpleTests) + target_link_libraries(MatVecMultPthreads + pthread + BaseLib + MathLib + logog + ) endif() set_target_properties(MatMult PROPERTIES FOLDER SimpleTests) target_link_libraries(MatMult - logog - BaseLib - MathLib + logog + BaseLib + MathLib ) add_executable(MatTestRemoveRowsCols - MatTestRemoveRowsCols.cpp - ${SOURCES} - ${HEADERS} + MatTestRemoveRowsCols.cpp + ${SOURCES} + ${HEADERS} ) set_target_properties(MatTestRemoveRowsCols PROPERTIES FOLDER SimpleTests) target_link_libraries(MatTestRemoveRowsCols - BaseLib - MathLib + BaseLib + MathLib ) if(METIS_FOUND) - add_executable(MatVecMultNDPerm - MatVecMultNDPerm.cpp - ${SOURCES} - ${HEADERS} - ) - set_target_properties(MatVecMultNDPerm PROPERTIES FOLDER SimpleTests) + add_executable(MatVecMultNDPerm + MatVecMultNDPerm.cpp + ${SOURCES} + ${HEADERS} + ) + set_target_properties(MatVecMultNDPerm PROPERTIES FOLDER SimpleTests) - target_link_libraries(MatVecMultNDPerm - BaseLib - MathLib - logog - ${METIS_LIBRARIES} - ) + target_link_libraries(MatVecMultNDPerm + BaseLib + MathLib + logog + ${METIS_LIBRARIES} + ) - if(OPENMP_FOUND) - add_executable(MatVecMultNDPermOpenMP - MatVecMultNDPermOpenMP.cpp - ${SOURCES} - ${HEADERS} - ) - set_target_properties(MatVecMultNDPermOpenMP PROPERTIES FOLDER SimpleTests) + if(OPENMP_FOUND) + add_executable(MatVecMultNDPermOpenMP + MatVecMultNDPermOpenMP.cpp + ${SOURCES} + ${HEADERS} + ) + set_target_properties(MatVecMultNDPermOpenMP PROPERTIES FOLDER SimpleTests) - target_link_libraries(MatVecMultNDPermOpenMP - BaseLib - MathLib - logog - ${METIS_LIBRARIES} - ) - endif() + target_link_libraries(MatVecMultNDPermOpenMP + BaseLib + MathLib + logog + ${METIS_LIBRARIES} + ) + endif() endif() add_executable(DenseGaussEliminationChecker - DenseGaussEliminationChecker.cpp - ${SOURCES} - ${HEADERS} + DenseGaussEliminationChecker.cpp + ${SOURCES} + ${HEADERS} ) set_target_properties(DenseGaussEliminationChecker PROPERTIES FOLDER SimpleTests) target_link_libraries(DenseGaussEliminationChecker - logog - BaseLib - MathLib + logog + BaseLib + MathLib ) diff --git a/SimpleTests/MatrixTests/DenseGaussEliminationChecker.cpp b/SimpleTests/MatrixTests/DenseGaussEliminationChecker.cpp index 646869a7cfd8039689b0650f30be7f9d733ee748..936ae7d4df665ddd193036f5b397e5c62ea30c92 100644 --- a/SimpleTests/MatrixTests/DenseGaussEliminationChecker.cpp +++ b/SimpleTests/MatrixTests/DenseGaussEliminationChecker.cpp @@ -23,61 +23,61 @@ int main(int argc, char *argv[]) { - LOGOG_INITIALIZE(); - BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter); - logog::Cout *logogCout(new logog::Cout); - logogCout->SetFormatter(*custom_format); + LOGOG_INITIALIZE(); + BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter); + logog::Cout *logogCout(new logog::Cout); + logogCout->SetFormatter(*custom_format); - TCLAP::CmdLine cmd("Simple direct matrix solver test.\n\ - It consists of the following steps:\n\ - (1) Read a matrix A from ascii format\n\ - (2) Set all entries of a vector x to one and compute b = A * x\n\ - (3) Solve the system of linear equations -> result have to be (1,...,1)", ' ', "0.1"); - TCLAP::ValueArg<std::string> matrix_arg("m", "matrix", "input matrix file (ascii format)", true, "", "string"); - cmd.add( matrix_arg ); - cmd.parse( argc, argv ); + TCLAP::CmdLine cmd("Simple direct matrix solver test.\n\ + It consists of the following steps:\n\ + (1) Read a matrix A from ascii format\n\ + (2) Set all entries of a vector x to one and compute b = A * x\n\ + (3) Solve the system of linear equations -> result have to be (1,...,1)", ' ', "0.1"); + TCLAP::ValueArg<std::string> matrix_arg("m", "matrix", "input matrix file (ascii format)", true, "", "string"); + cmd.add( matrix_arg ); + cmd.parse( argc, argv ); - // *** reading dense matrix in ascii format from file - std::string const fname_mat(matrix_arg.getValue()); - std::ifstream in(fname_mat.c_str()); - if (!in) { - INFO("error reading matrix from %s", fname_mat.c_str()); - return -1; - } - INFO("reading matrix from %s ...", fname_mat.c_str()); - std::size_t n_rows(0), n_cols(0); - in >> n_rows; - in >> n_cols; - MathLib::DenseMatrix<double, std::size_t> mat(n_rows, n_cols); - for (std::size_t i(0); i<mat.getNRows(); ++i) { - for (std::size_t j(0); j<mat.getNCols(); ++j) { - in >> mat(i,j); - } - } - { - std::stringstream stream; - stream << mat; - INFO("read matrix:\n%s", stream.str().c_str()); - } + // *** reading dense matrix in ascii format from file + std::string const fname_mat(matrix_arg.getValue()); + std::ifstream in(fname_mat.c_str()); + if (!in) { + INFO("error reading matrix from %s", fname_mat.c_str()); + return -1; + } + INFO("reading matrix from %s ...", fname_mat.c_str()); + std::size_t n_rows(0), n_cols(0); + in >> n_rows; + in >> n_cols; + MathLib::DenseMatrix<double, std::size_t> mat(n_rows, n_cols); + for (std::size_t i(0); i<mat.getNRows(); ++i) { + for (std::size_t j(0); j<mat.getNCols(); ++j) { + in >> mat(i,j); + } + } + { + std::stringstream stream; + stream << mat; + INFO("read matrix:\n%s", stream.str().c_str()); + } - std::vector<double> x(n_cols,1.0), b; - b.resize(n_rows); - b = mat * x; + std::vector<double> x(n_cols,1.0), b; + b.resize(n_rows); + b = mat * x; - MathLib::GaussAlgorithm<MathLib::DenseMatrix<double, std::size_t>> gauss; - gauss.solve(mat, b, true); + MathLib::GaussAlgorithm<MathLib::DenseMatrix<double, std::size_t>> gauss; + gauss.solve(mat, b, true); - { - std::stringstream stream; - std::copy(b.begin(), b.end(), std::ostream_iterator<double>(stream, " ")); - stream << std::endl; - INFO("solution vector:\n%s", stream.str().c_str()); - } + { + std::stringstream stream; + std::copy(b.begin(), b.end(), std::ostream_iterator<double>(stream, " ")); + stream << std::endl; + INFO("solution vector:\n%s", stream.str().c_str()); + } - delete custom_format; - delete logogCout; - LOGOG_SHUTDOWN(); + delete custom_format; + delete logogCout; + LOGOG_SHUTDOWN(); - return 0; + return 0; } diff --git a/SimpleTests/MatrixTests/MatMult.cpp b/SimpleTests/MatrixTests/MatMult.cpp index 8a3ed344ff690d3bdd9463b1d9ac1ceddfaa892e..26dfd4780094e730edf14435d25358071c556eb1 100644 --- a/SimpleTests/MatrixTests/MatMult.cpp +++ b/SimpleTests/MatrixTests/MatMult.cpp @@ -52,141 +52,141 @@ class FormatterCustom : public logog::FormatterGCC int main(int argc, char *argv[]) { - LOGOG_INITIALIZE(); + LOGOG_INITIALIZE(); - TCLAP::CmdLine cmd("Simple matrix vector multiplication test", ' ', "0.1"); + TCLAP::CmdLine cmd("Simple matrix vector multiplication test", ' ', "0.1"); - // Define a value argument and add it to the command line. - // A value arg defines a flag and a type of value that it expects, - // such as "-m matrix". - TCLAP::ValueArg<std::string> matrix_arg("m", "matrix", "input matrix file", true, "", "string"); + // Define a value argument and add it to the command line. + // A value arg defines a flag and a type of value that it expects, + // such as "-m matrix". + TCLAP::ValueArg<std::string> matrix_arg("m", "matrix", "input matrix file", true, "", "string"); - // Add the argument mesh_arg to the CmdLine object. The CmdLine object - // uses this Arg to parse the command line. - cmd.add( matrix_arg ); + // Add the argument mesh_arg to the CmdLine object. The CmdLine object + // uses this Arg to parse the command line. + cmd.add( matrix_arg ); - TCLAP::ValueArg<unsigned> n_cores_arg("p", "number-cores", "number of cores to use", false, 1, "number"); - cmd.add( n_cores_arg ); + TCLAP::ValueArg<unsigned> n_cores_arg("p", "number-cores", "number of cores to use", false, 1, "number"); + cmd.add( n_cores_arg ); - TCLAP::ValueArg<unsigned> n_mults_arg("n", "number-of-multiplications", "number of multiplications to perform", true, 10, "number"); - cmd.add( n_mults_arg ); + TCLAP::ValueArg<unsigned> n_mults_arg("n", "number-of-multiplications", "number of multiplications to perform", true, 10, "number"); + cmd.add( n_mults_arg ); - TCLAP::ValueArg<std::string> output_arg("o", "output", "output file", false, "", "string"); - cmd.add( output_arg ); + TCLAP::ValueArg<std::string> output_arg("o", "output", "output file", false, "", "string"); + cmd.add( output_arg ); - TCLAP::ValueArg<unsigned> verbosity_arg("v", "verbose", "level of verbosity [0 very low information, 1 much information]", false, 0, "string"); - cmd.add( verbosity_arg ); + TCLAP::ValueArg<unsigned> verbosity_arg("v", "verbose", "level of verbosity [0 very low information, 1 much information]", false, 0, "string"); + cmd.add( verbosity_arg ); - cmd.parse( argc, argv ); + cmd.parse( argc, argv ); - // read the number of multiplication to execute - unsigned n_mults (n_mults_arg.getValue()); - std::string fname_mat (matrix_arg.getValue()); + // read the number of multiplication to execute + unsigned n_mults (n_mults_arg.getValue()); + std::string fname_mat (matrix_arg.getValue()); - FormatterCustom *custom_format (new FormatterCustom); - logog::Cout *logogCout(new logog::Cout); - logogCout->SetFormatter(*custom_format); + FormatterCustom *custom_format (new FormatterCustom); + logog::Cout *logogCout(new logog::Cout); + logogCout->SetFormatter(*custom_format); - logog::LogFile *logog_file(NULL); - if (! output_arg.getValue().empty()) { - logog_file = new logog::LogFile(output_arg.getValue().c_str()); - logog_file->SetFormatter( *custom_format ); - } + logog::LogFile *logog_file(NULL); + if (! output_arg.getValue().empty()) { + logog_file = new logog::LogFile(output_arg.getValue().c_str()); + logog_file->SetFormatter( *custom_format ); + } - // read number of threads - unsigned n_threads (n_cores_arg.getValue()); + // read number of threads + unsigned n_threads (n_cores_arg.getValue()); - INFO("%s was build with compiler %s", - argv[0], - BaseLib::BuildInfo::cmake_cxx_compiler.c_str()); + INFO("%s was build with compiler %s", + argv[0], + BaseLib::BuildInfo::cmake_cxx_compiler.c_str()); #ifdef NDEBUG - INFO("CXX_FLAGS: %s %s", - BaseLib::BuildInfo::cmake_cxx_flags.c_str(), - BaseLib::BuildInfo::cmake_cxx_flags_release.c_str()); + INFO("CXX_FLAGS: %s %s", + BaseLib::BuildInfo::cmake_cxx_flags.c_str(), + BaseLib::BuildInfo::cmake_cxx_flags_release.c_str()); #else - INFO("CXX_FLAGS: %s %s", - BaseLib::BuildInfo::cmake_cxx_flags.c_str(), - BaseLib::BuildInfo::cmake_cxx_flags_debug.c_str()); + INFO("CXX_FLAGS: %s %s", + BaseLib::BuildInfo::cmake_cxx_flags.c_str(), + BaseLib::BuildInfo::cmake_cxx_flags_debug.c_str()); #endif #ifdef UNIX - const int max_host_name_len (255); - char *hostname(new char[max_host_name_len]); - if (gethostname(hostname, max_host_name_len) == 0) - INFO("hostname: %s", hostname); - delete [] host_name_len; + const int max_host_name_len (255); + char *hostname(new char[max_host_name_len]); + if (gethostname(hostname, max_host_name_len) == 0) + INFO("hostname: %s", hostname); + delete [] host_name_len; #endif - // *** reading matrix in crs format from file - std::ifstream in(fname_mat.c_str(), std::ios::in | std::ios::binary); - double *A(NULL); - unsigned *iA(NULL), *jA(NULL), n; - if (in) { - INFO("reading matrix from %s ...", fname_mat.c_str()); - BaseLib::RunTime timer; - timer.start(); - CS_read(in, n, iA, jA, A); - INFO("\t- took %e s", timer.elapsed()); - } else { - INFO("error reading matrix from %s", fname_mat.c_str()); - return -1; - } - unsigned nnz(iA[n]); - INFO("\tParameters read: n=%d, nnz=%d", n, nnz); + // *** reading matrix in crs format from file + std::ifstream in(fname_mat.c_str(), std::ios::in | std::ios::binary); + double *A(NULL); + unsigned *iA(NULL), *jA(NULL), n; + if (in) { + INFO("reading matrix from %s ...", fname_mat.c_str()); + BaseLib::RunTime timer; + timer.start(); + CS_read(in, n, iA, jA, A); + INFO("\t- took %e s", timer.elapsed()); + } else { + INFO("error reading matrix from %s", fname_mat.c_str()); + return -1; + } + unsigned nnz(iA[n]); + INFO("\tParameters read: n=%d, nnz=%d", n, nnz); #ifdef _OPENMP - omp_set_num_threads(n_threads); - unsigned *mat_entries_per_core(new unsigned[n_threads]); - for (unsigned k(0); k<n_threads; k++) { - mat_entries_per_core[k] = 0; - } - - OPENMP_LOOP_TYPE i; - { + omp_set_num_threads(n_threads); + unsigned *mat_entries_per_core(new unsigned[n_threads]); + for (unsigned k(0); k<n_threads; k++) { + mat_entries_per_core[k] = 0; + } + + OPENMP_LOOP_TYPE i; + { #pragma omp parallel for - for (i = 0; i < n; i++) { - mat_entries_per_core[omp_get_thread_num()] += iA[i + 1] - iA[i]; - } - } - - INFO("*** work per core ***"); - for (unsigned k(0); k<n_threads; k++) { - INFO("\t%d\t%d", k, mat_entries_per_core[k]); - } + for (i = 0; i < n; i++) { + mat_entries_per_core[omp_get_thread_num()] += iA[i + 1] - iA[i]; + } + } + + INFO("*** work per core ***"); + for (unsigned k(0); k<n_threads; k++) { + INFO("\t%d\t%d", k, mat_entries_per_core[k]); + } #endif #ifdef _OPENMP - omp_set_num_threads(n_threads); - MathLib::CRSMatrixOpenMP<double, unsigned> mat (n, iA, jA, A); + omp_set_num_threads(n_threads); + MathLib::CRSMatrixOpenMP<double, unsigned> mat (n, iA, jA, A); #else - MathLib::CRSMatrix<double, unsigned> mat (n, iA, jA, A); + MathLib::CRSMatrix<double, unsigned> mat (n, iA, jA, A); #endif - double *x(new double[n]); - double *y(new double[n]); + double *x(new double[n]); + double *y(new double[n]); - for (unsigned k(0); k<n; ++k) - x[k] = 1.0; + for (unsigned k(0); k<n; ++k) + x[k] = 1.0; - INFO("*** %d matrix vector multiplications (MVM) with Toms amuxCRS (%d threads) ...", n_mults, n_threads); - BaseLib::RunTime run_timer; - BaseLib::CPUTime cpu_timer; - run_timer.start(); - cpu_timer.start(); - for (std::size_t k(0); k<n_mults; k++) { - mat.amux (1.0, x, y); - } + INFO("*** %d matrix vector multiplications (MVM) with Toms amuxCRS (%d threads) ...", n_mults, n_threads); + BaseLib::RunTime run_timer; + BaseLib::CPUTime cpu_timer; + run_timer.start(); + cpu_timer.start(); + for (std::size_t k(0); k<n_mults; k++) { + mat.amux (1.0, x, y); + } - INFO("\t[MVM] - took %e sec cpu time, %e sec run time", cpu_timer.elapsed(), run_timer.elapsed()); + INFO("\t[MVM] - took %e sec cpu time, %e sec run time", cpu_timer.elapsed(), run_timer.elapsed()); - delete [] x; - delete [] y; + delete [] x; + delete [] y; - delete custom_format; - delete logogCout; - delete logog_file; - LOGOG_SHUTDOWN(); + delete custom_format; + delete logogCout; + delete logog_file; + LOGOG_SHUTDOWN(); - return 0; + return 0; } diff --git a/SimpleTests/MatrixTests/MatTestRemoveRowsCols.cpp b/SimpleTests/MatrixTests/MatTestRemoveRowsCols.cpp index 803dc2aeb1487beee5a14a9b8cb40e727fbb73a8..6bdcb27d5fa18b362502bf2d89f6c83ae9f5fd24 100644 --- a/SimpleTests/MatrixTests/MatTestRemoveRowsCols.cpp +++ b/SimpleTests/MatrixTests/MatTestRemoveRowsCols.cpp @@ -21,59 +21,59 @@ int main(int argc, char *argv[]) { - if (argc < 3) { - std::cout << "Usage: " << argv[0] << " input-matrix output-matrix" << std::endl; - return 1; - } + if (argc < 3) { + std::cout << "Usage: " << argv[0] << " input-matrix output-matrix" << std::endl; + return 1; + } - std::string fname_mat (argv[1]); - bool verbose (true); + std::string fname_mat (argv[1]); + bool verbose (true); - // *** reading matrix in crs format from file - std::ifstream in(fname_mat.c_str(), std::ios::in | std::ios::binary); - double *A(NULL); - unsigned *iA(NULL), *jA(NULL), n = 0; - if (in) { - if (verbose) { - std::cout << "reading matrix from " << fname_mat << " ... " << std::flush; - } - BaseLib::RunTime timer; - timer.start(); - CS_read(in, n, iA, jA, A); - in.close(); - if (verbose) { - std::cout << "ok, " << timer.elapsed() << " s" << std::endl; - } - } else { - std::cout << "error reading matrix from " << fname_mat << std::endl; - } - unsigned nnz(iA[n]); - if (verbose) { - std::cout << "Parameters read: n=" << n << ", nnz=" << nnz << std::endl; - } + // *** reading matrix in crs format from file + std::ifstream in(fname_mat.c_str(), std::ios::in | std::ios::binary); + double *A(NULL); + unsigned *iA(NULL), *jA(NULL), n = 0; + if (in) { + if (verbose) { + std::cout << "reading matrix from " << fname_mat << " ... " << std::flush; + } + BaseLib::RunTime timer; + timer.start(); + CS_read(in, n, iA, jA, A); + in.close(); + if (verbose) { + std::cout << "ok, " << timer.elapsed() << " s" << std::endl; + } + } else { + std::cout << "error reading matrix from " << fname_mat << std::endl; + } + unsigned nnz(iA[n]); + if (verbose) { + std::cout << "Parameters read: n=" << n << ", nnz=" << nnz << std::endl; + } - MathLib::CRSMatrix<double, unsigned> *mat (new MathLib::CRSMatrix<double, unsigned>(n, iA, jA, A)); + MathLib::CRSMatrix<double, unsigned> *mat (new MathLib::CRSMatrix<double, unsigned>(n, iA, jA, A)); - const unsigned n_rows_cols_to_erase(300); - unsigned *rows_cols_to_erase(new unsigned[n_rows_cols_to_erase]); + const unsigned n_rows_cols_to_erase(300); + unsigned *rows_cols_to_erase(new unsigned[n_rows_cols_to_erase]); - for (unsigned k(0); k<n_rows_cols_to_erase; k++) { - rows_cols_to_erase[k] = (k+1)*2; - } + for (unsigned k(0); k<n_rows_cols_to_erase; k++) { + rows_cols_to_erase[k] = (k+1)*2; + } - BaseLib::RunTime timer; - std::cout << "erasing " << n_rows_cols_to_erase << " rows and columns ... " << std::flush; - timer.start(); - mat->eraseEntries(n_rows_cols_to_erase, rows_cols_to_erase); - std::cout << "ok, " << timer.elapsed() << " s" << std::endl; - delete[] rows_cols_to_erase; + BaseLib::RunTime timer; + std::cout << "erasing " << n_rows_cols_to_erase << " rows and columns ... " << std::flush; + timer.start(); + mat->eraseEntries(n_rows_cols_to_erase, rows_cols_to_erase); + std::cout << "ok, " << timer.elapsed() << " s" << std::endl; + delete[] rows_cols_to_erase; - fname_mat = argv[2]; - std::ofstream out (fname_mat.c_str(), std::ios::binary); - CS_write (out, mat->getNRows(), mat->getRowPtrArray(), mat->getColIdxArray(), mat->getEntryArray()); - out.close(); + fname_mat = argv[2]; + std::ofstream out (fname_mat.c_str(), std::ios::binary); + CS_write (out, mat->getNRows(), mat->getRowPtrArray(), mat->getColIdxArray(), mat->getEntryArray()); + out.close(); - std::cout << "wrote " << fname_mat << " with " << mat->getNRows() << " rows and " << mat->getRowPtrArray()[mat->getNRows()] << " entries" << std::endl; + std::cout << "wrote " << fname_mat << " with " << mat->getNRows() << " rows and " << mat->getRowPtrArray()[mat->getNRows()] << " entries" << std::endl; - delete mat; + delete mat; } diff --git a/SimpleTests/MatrixTests/MatVecMultNDPerm.cpp b/SimpleTests/MatrixTests/MatVecMultNDPerm.cpp index d3f4cc78538a68242582f6a1353e48d49cb6406d..e64af5a77e8e6160ef82b5af803bddb66aa09247 100644 --- a/SimpleTests/MatrixTests/MatVecMultNDPerm.cpp +++ b/SimpleTests/MatrixTests/MatVecMultNDPerm.cpp @@ -34,155 +34,155 @@ int main(int argc, char *argv[]) { - LOGOG_INITIALIZE(); + LOGOG_INITIALIZE(); - TCLAP::CmdLine cmd("The purpose of this program is the speed test of sparse matrix vector multiplication (MVM), where the matrix is stored in CRS format. Before executing the MVM a nested dissection reordering is performed.", ' ', "0.1"); + TCLAP::CmdLine cmd("The purpose of this program is the speed test of sparse matrix vector multiplication (MVM), where the matrix is stored in CRS format. Before executing the MVM a nested dissection reordering is performed.", ' ', "0.1"); - // Define a value argument and add it to the command line. - // A value arg defines a flag and a type of value that it expects, - // such as "-m matrix". - TCLAP::ValueArg<std::string> matrix_arg("m","matrix","input matrix file in CRS format",true,"","file name of the matrix in CRS format"); + // Define a value argument and add it to the command line. + // A value arg defines a flag and a type of value that it expects, + // such as "-m matrix". + TCLAP::ValueArg<std::string> matrix_arg("m","matrix","input matrix file in CRS format",true,"","file name of the matrix in CRS format"); - // Add the argument matrix_arg to the CmdLine object. The CmdLine object - // uses this Arg to parse the command line. - cmd.add( matrix_arg ); + // Add the argument matrix_arg to the CmdLine object. The CmdLine object + // uses this Arg to parse the command line. + cmd.add( matrix_arg ); -// TCLAP::ValueArg<unsigned> n_cores_arg("n", "number-cores", "number of cores to use", true, "1", "number"); -// cmd.add( n_cores_arg ); +// TCLAP::ValueArg<unsigned> n_cores_arg("n", "number-cores", "number of cores to use", true, "1", "number"); +// cmd.add( n_cores_arg ); - TCLAP::ValueArg<unsigned> n_mults_arg("n", "number-of-multiplications", "number of multiplications to perform", true, 10, "number of multiplications"); - cmd.add( n_mults_arg ); + TCLAP::ValueArg<unsigned> n_mults_arg("n", "number-of-multiplications", "number of multiplications to perform", true, 10, "number of multiplications"); + cmd.add( n_mults_arg ); - TCLAP::ValueArg<std::string> output_arg("o", "output", "output file", false, "", "string"); - cmd.add( output_arg ); + TCLAP::ValueArg<std::string> output_arg("o", "output", "output file", false, "", "string"); + cmd.add( output_arg ); - TCLAP::ValueArg<bool> verbosity_arg("v", "verbose", "level of verbosity [0 very low information, 1 much information]", false, 0, "string"); - cmd.add( verbosity_arg ); + TCLAP::ValueArg<bool> verbosity_arg("v", "verbose", "level of verbosity [0 very low information, 1 much information]", false, 0, "string"); + cmd.add( verbosity_arg ); - cmd.parse( argc, argv ); + cmd.parse( argc, argv ); - // read the number of multiplication to execute - unsigned n_mults (n_mults_arg.getValue()); - std::string fname_mat (matrix_arg.getValue()); - bool verbose (verbosity_arg.getValue()); + // read the number of multiplication to execute + unsigned n_mults (n_mults_arg.getValue()); + std::string fname_mat (matrix_arg.getValue()); + bool verbose (verbosity_arg.getValue()); - BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter); - logog::Cout *logogCout(new logog::Cout); - logogCout->SetFormatter(*custom_format); + BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter); + logog::Cout *logogCout(new logog::Cout); + logogCout->SetFormatter(*custom_format); - INFO("%s was build with compiler %s", - argv[0], - BaseLib::BuildInfo::cmake_cxx_compiler.c_str()); + INFO("%s was build with compiler %s", + argv[0], + BaseLib::BuildInfo::cmake_cxx_compiler.c_str()); #ifdef NDEBUG - INFO("CXX_FLAGS: %s %s", - BaseLib::BuildInfo::cmake_cxx_flags.c_str(), - BaseLib::BuildInfo::cmake_cxx_flags_release.c_str()); + INFO("CXX_FLAGS: %s %s", + BaseLib::BuildInfo::cmake_cxx_flags.c_str(), + BaseLib::BuildInfo::cmake_cxx_flags_release.c_str()); #else - INFO("CXX_FLAGS: %s %s", - BaseLib::BuildInfo::cmake_cxx_flags.c_str(), - BaseLib::BuildInfo::cmake_cxx_flags_debug.c_str()); + INFO("CXX_FLAGS: %s %s", + BaseLib::BuildInfo::cmake_cxx_flags.c_str(), + BaseLib::BuildInfo::cmake_cxx_flags_debug.c_str()); #endif #ifdef UNIX - const std::size_t length(256); - char *hostname(new char[length]); - gethostname (hostname, length); - INFO("hostname: %s", hostname); - delete [] hostname; + const std::size_t length(256); + char *hostname(new char[length]); + gethostname (hostname, length); + INFO("hostname: %s", hostname); + delete [] hostname; #endif - // *** reading matrix in crs format from file - std::ifstream in(fname_mat.c_str(), std::ios::in | std::ios::binary); - double *A(NULL); - unsigned *iA(NULL), *jA(NULL), n; - if (in) { - if (verbose) { - INFO("reading matrix from %s ...", fname_mat.c_str()); - } - BaseLib::RunTime timer; - timer.start(); - CS_read(in, n, iA, jA, A); - if (verbose) { - INFO("\t- took %e s", timer.elapsed()); - } - } else { - ERR("error reading matrix from %s", fname_mat.c_str()); - return -1; - } - unsigned nnz(iA[n]); - if (verbose) { - INFO("\tParameters read: n=%d, nnz=%d", n, nnz); - } - - MathLib::CRSMatrixReordered mat(n, iA, jA, A); - - double *x(new double[n]); - double *y(new double[n]); - - for (unsigned k(0); k<n; ++k) - x[k] = 1.0; - - // create time measurement objects - BaseLib::RunTime run_timer; - BaseLib::CPUTime cpu_timer; - - // calculate the nested dissection reordering - if (verbose) { - INFO("*** calculating nested dissection (ND) permutation of matrix ..."); - } - run_timer.start(); - cpu_timer.start(); - MathLib::Cluster cluster_tree(n, iA, jA); - unsigned *op_perm(new unsigned[n]); - unsigned *po_perm(new unsigned[n]); - for (unsigned k(0); k<n; k++) - op_perm[k] = po_perm[k] = k; - cluster_tree.createClusterTree(op_perm, po_perm, 1000); - if (verbose) { - INFO("\t[ND] - took %e sec \t%e sec", cpu_timer.elapsed(), run_timer.elapsed()); - } - - // applying the nested dissection reordering - if (verbose) { - INFO("\t[ND] applying nested dissection permutation to FEM matrix ... "); - } - run_timer.start(); - cpu_timer.start(); - mat.reorderMatrix(op_perm, po_perm); - if (verbose) { - INFO("\t[ND]: - took %e sec\t%e sec", cpu_timer.elapsed(), run_timer.elapsed()); - } + // *** reading matrix in crs format from file + std::ifstream in(fname_mat.c_str(), std::ios::in | std::ios::binary); + double *A(NULL); + unsigned *iA(NULL), *jA(NULL), n; + if (in) { + if (verbose) { + INFO("reading matrix from %s ...", fname_mat.c_str()); + } + BaseLib::RunTime timer; + timer.start(); + CS_read(in, n, iA, jA, A); + if (verbose) { + INFO("\t- took %e s", timer.elapsed()); + } + } else { + ERR("error reading matrix from %s", fname_mat.c_str()); + return -1; + } + unsigned nnz(iA[n]); + if (verbose) { + INFO("\tParameters read: n=%d, nnz=%d", n, nnz); + } + + MathLib::CRSMatrixReordered mat(n, iA, jA, A); + + double *x(new double[n]); + double *y(new double[n]); + + for (unsigned k(0); k<n; ++k) + x[k] = 1.0; + + // create time measurement objects + BaseLib::RunTime run_timer; + BaseLib::CPUTime cpu_timer; + + // calculate the nested dissection reordering + if (verbose) { + INFO("*** calculating nested dissection (ND) permutation of matrix ..."); + } + run_timer.start(); + cpu_timer.start(); + MathLib::Cluster cluster_tree(n, iA, jA); + unsigned *op_perm(new unsigned[n]); + unsigned *po_perm(new unsigned[n]); + for (unsigned k(0); k<n; k++) + op_perm[k] = po_perm[k] = k; + cluster_tree.createClusterTree(op_perm, po_perm, 1000); + if (verbose) { + INFO("\t[ND] - took %e sec \t%e sec", cpu_timer.elapsed(), run_timer.elapsed()); + } + + // applying the nested dissection reordering + if (verbose) { + INFO("\t[ND] applying nested dissection permutation to FEM matrix ... "); + } + run_timer.start(); + cpu_timer.start(); + mat.reorderMatrix(op_perm, po_perm); + if (verbose) { + INFO("\t[ND]: - took %e sec\t%e sec", cpu_timer.elapsed(), run_timer.elapsed()); + } #ifndef NDEBUG -// std::string fname_mat_out(fname_mat.substr(0,fname_mat.length()-4)+"-reordered.bin"); -// std::ofstream os (fname_mat_out.c_str(), std::ios::binary); -// if (os) { -// std::cout << "writing matrix to " << fname_mat_out << " ... " << std::flush; -// CS_write(os, n, mat.getRowPtrArray(), mat.getColIdxArray(), mat.getEntryArray()); -// std::cout << "done" << std::endl; -// } +// std::string fname_mat_out(fname_mat.substr(0,fname_mat.length()-4)+"-reordered.bin"); +// std::ofstream os (fname_mat_out.c_str(), std::ios::binary); +// if (os) { +// std::cout << "writing matrix to " << fname_mat_out << " ... " << std::flush; +// CS_write(os, n, mat.getRowPtrArray(), mat.getColIdxArray(), mat.getEntryArray()); +// std::cout << "done" << std::endl; +// } #endif - if (verbose) { - INFO("*** %d matrix vector multiplications (MVM) with Toms amuxCRS ... ", n_mults); - } - run_timer.start(); - cpu_timer.start(); - for (std::size_t k(0); k<n_mults; k++) { - mat.amux (1.0, x, y); - } + if (verbose) { + INFO("*** %d matrix vector multiplications (MVM) with Toms amuxCRS ... ", n_mults); + } + run_timer.start(); + cpu_timer.start(); + for (std::size_t k(0); k<n_mults; k++) { + mat.amux (1.0, x, y); + } - if (verbose) { - INFO("\t[MVM] - took %e sec\t %e sec", cpu_timer.elapsed(), run_timer.elapsed()); - } + if (verbose) { + INFO("\t[MVM] - took %e sec\t %e sec", cpu_timer.elapsed(), run_timer.elapsed()); + } - delete [] x; - delete [] y; + delete [] x; + delete [] y; - delete custom_format; - delete logogCout; - LOGOG_SHUTDOWN(); + delete custom_format; + delete logogCout; + LOGOG_SHUTDOWN(); - return 0; + return 0; } diff --git a/SimpleTests/MatrixTests/MatVecMultNDPermOpenMP.cpp b/SimpleTests/MatrixTests/MatVecMultNDPermOpenMP.cpp index f15d46c4c0fdb694d1c0f70c211d91da2e304d7f..a9d8fdf312acedb744221ffa5d321cef1ce26190 100644 --- a/SimpleTests/MatrixTests/MatVecMultNDPermOpenMP.cpp +++ b/SimpleTests/MatrixTests/MatVecMultNDPermOpenMP.cpp @@ -42,156 +42,156 @@ int main(int argc, char *argv[]) static_assert(false, "This code must be compiled with _OPENMP macro enabled."); #endif - LOGOG_INITIALIZE(); + LOGOG_INITIALIZE(); - TCLAP::CmdLine cmd("The purpose of this program is the speed test of sparse matrix vector multiplication (MVM) employing OpenMP technique, where the matrix is stored in CRS format. Before executing the MVM a nested dissection reordering is performed.", ' ', "0.1"); + TCLAP::CmdLine cmd("The purpose of this program is the speed test of sparse matrix vector multiplication (MVM) employing OpenMP technique, where the matrix is stored in CRS format. Before executing the MVM a nested dissection reordering is performed.", ' ', "0.1"); - // Define a value argument and add it to the command line. - // A value arg defines a flag and a type of value that it expects, - // such as "-m matrix". - TCLAP::ValueArg<std::string> matrix_arg("m","matrix","input matrix file in CRS format",true,"","file name of the matrix in CRS format"); + // Define a value argument and add it to the command line. + // A value arg defines a flag and a type of value that it expects, + // such as "-m matrix". + TCLAP::ValueArg<std::string> matrix_arg("m","matrix","input matrix file in CRS format",true,"","file name of the matrix in CRS format"); - // Add the argument matrix_arg to the CmdLine object. The CmdLine object - // uses this Arg to parse the command line. - cmd.add( matrix_arg ); + // Add the argument matrix_arg to the CmdLine object. The CmdLine object + // uses this Arg to parse the command line. + cmd.add( matrix_arg ); - TCLAP::ValueArg<unsigned> n_cores_arg("p", "number-cores", "number of cores to use", true, 1, "number of cores"); - cmd.add( n_cores_arg ); + TCLAP::ValueArg<unsigned> n_cores_arg("p", "number-cores", "number of cores to use", true, 1, "number of cores"); + cmd.add( n_cores_arg ); - TCLAP::ValueArg<unsigned> n_mults_arg("n", "number-of-multiplications", "number of multiplications to perform", true, 10, "number of multiplications"); - cmd.add( n_mults_arg ); + TCLAP::ValueArg<unsigned> n_mults_arg("n", "number-of-multiplications", "number of multiplications to perform", true, 10, "number of multiplications"); + cmd.add( n_mults_arg ); - TCLAP::ValueArg<std::string> output_arg("o", "output", "output file", false, "", "string"); - cmd.add( output_arg ); + TCLAP::ValueArg<std::string> output_arg("o", "output", "output file", false, "", "string"); + cmd.add( output_arg ); - TCLAP::ValueArg<bool> verbosity_arg("v", "verbose", "level of verbosity [0 very low information, 1 much information]", false, 0, "string"); - cmd.add( verbosity_arg ); + TCLAP::ValueArg<bool> verbosity_arg("v", "verbose", "level of verbosity [0 very low information, 1 much information]", false, 0, "string"); + cmd.add( verbosity_arg ); - cmd.parse( argc, argv ); + cmd.parse( argc, argv ); - // read the number of multiplication to execute - unsigned n_mults (n_mults_arg.getValue()); - std::string fname_mat (matrix_arg.getValue()); - bool verbose (verbosity_arg.getValue()); + // read the number of multiplication to execute + unsigned n_mults (n_mults_arg.getValue()); + std::string fname_mat (matrix_arg.getValue()); + bool verbose (verbosity_arg.getValue()); - BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter); - logog::Cout *logogCout(new logog::Cout); - logogCout->SetFormatter(*custom_format); + BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter); + logog::Cout *logogCout(new logog::Cout); + logogCout->SetFormatter(*custom_format); - // read number of threads - unsigned n_threads (n_cores_arg.getValue()); + // read number of threads + unsigned n_threads (n_cores_arg.getValue()); - INFO("%s was build with compiler %s", - argv[0], - BaseLib::BuildInfo::cmake_cxx_compiler.c_str()); + INFO("%s was build with compiler %s", + argv[0], + BaseLib::BuildInfo::cmake_cxx_compiler.c_str()); #ifdef NDEBUG - INFO("CXX_FLAGS: %s %s", - BaseLib::BuildInfo::cmake_cxx_flags.c_str(), - BaseLib::BuildInfo::cmake_cxx_flags_release.c_str()); + INFO("CXX_FLAGS: %s %s", + BaseLib::BuildInfo::cmake_cxx_flags.c_str(), + BaseLib::BuildInfo::cmake_cxx_flags_release.c_str()); #else - INFO("CXX_FLAGS: %s %s", - BaseLib::BuildInfo::cmake_cxx_flags.c_str(), - BaseLib::BuildInfo::cmake_cxx_flags_debug.c_str()); + INFO("CXX_FLAGS: %s %s", + BaseLib::BuildInfo::cmake_cxx_flags.c_str(), + BaseLib::BuildInfo::cmake_cxx_flags_debug.c_str()); #endif #ifdef UNIX - const std::size_t length(256); - char *hostname(new char[length]); - gethostname (hostname, length); - INFO("hostname: %s", hostname); - delete [] hostname; + const std::size_t length(256); + char *hostname(new char[length]); + gethostname (hostname, length); + INFO("hostname: %s", hostname); + delete [] hostname; #endif - // *** reading matrix in crs format from file - std::ifstream in(fname_mat.c_str(), std::ios::in | std::ios::binary); - double *A(NULL); - unsigned *iA(NULL), *jA(NULL), n; - if (in) { - if (verbose) { - INFO("reading matrix from %s ...", fname_mat.c_str()); - } - BaseLib::RunTime timer; - timer.start(); - CS_read(in, n, iA, jA, A); - if (verbose) { - INFO("\t- took %e s", timer.elapsed()); - } - } else { - ERR("error reading matrix from %s", fname_mat.c_str()); - return -1; - } - unsigned nnz(iA[n]); - if (verbose) { - INFO("\tParameters read: n=%d, nnz=%d", n, nnz); - } + // *** reading matrix in crs format from file + std::ifstream in(fname_mat.c_str(), std::ios::in | std::ios::binary); + double *A(NULL); + unsigned *iA(NULL), *jA(NULL), n; + if (in) { + if (verbose) { + INFO("reading matrix from %s ...", fname_mat.c_str()); + } + BaseLib::RunTime timer; + timer.start(); + CS_read(in, n, iA, jA, A); + if (verbose) { + INFO("\t- took %e s", timer.elapsed()); + } + } else { + ERR("error reading matrix from %s", fname_mat.c_str()); + return -1; + } + unsigned nnz(iA[n]); + if (verbose) { + INFO("\tParameters read: n=%d, nnz=%d", n, nnz); + } #ifdef _OPENMP - omp_set_num_threads(n_threads); - MathLib::CRSMatrixReorderedOpenMP mat(n, iA, jA, A); + omp_set_num_threads(n_threads); + MathLib::CRSMatrixReorderedOpenMP mat(n, iA, jA, A); #else - delete [] iA; - delete [] jA; - delete [] A; - ERROR("program is not using OpenMP"); - return -1; + delete [] iA; + delete [] jA; + delete [] A; + ERROR("program is not using OpenMP"); + return -1; #endif - double *x(new double[n]); - double *y(new double[n]); - - for (unsigned k(0); k<n; ++k) - x[k] = 1.0; - - // create time measurement objects - BaseLib::RunTime run_timer; - BaseLib::CPUTime cpu_timer; - - // calculate the nested dissection reordering - if (verbose) { - INFO("*** calculating nested dissection (ND) permutation of matrix ..."); - } - run_timer.start(); - cpu_timer.start(); - MathLib::Cluster cluster_tree(n, iA, jA); - unsigned *op_perm(new unsigned[n]); - unsigned *po_perm(new unsigned[n]); - for (unsigned k(0); k<n; k++) - op_perm[k] = po_perm[k] = k; - cluster_tree.createClusterTree(op_perm, po_perm, 1000); - if (verbose) { - INFO("\t[ND] - took %e sec \t%e sec", cpu_timer.elapsed(), run_timer.elapsed()); - } - - // applying the nested dissection reordering - if (verbose) { - INFO("\t[ND] applying nested dissection permutation to FEM matrix ... "); - } - run_timer.start(); - cpu_timer.start(); - mat.reorderMatrix(op_perm, po_perm); - if (verbose) { - INFO("\t[ND]: - took %e sec\t%e sec", cpu_timer.elapsed(), run_timer.elapsed()); - } - - if (verbose) { - INFO("*** %d matrix vector multiplications (MVM) with Toms amuxCRS (%d threads)... ", n_mults, n_threads); - } - - run_timer.start(); - cpu_timer.start(); - for (std::size_t k(0); k<n_mults; k++) { - mat.amux (1.0, x, y); - } - - if (verbose) { - INFO("\t[MVM] - took %e sec cpu time, %e sec run time", cpu_timer.elapsed(), run_timer.elapsed()); - } - - delete [] x; - delete [] y; - - delete custom_format; - delete logogCout; - LOGOG_SHUTDOWN(); - - return 0; + double *x(new double[n]); + double *y(new double[n]); + + for (unsigned k(0); k<n; ++k) + x[k] = 1.0; + + // create time measurement objects + BaseLib::RunTime run_timer; + BaseLib::CPUTime cpu_timer; + + // calculate the nested dissection reordering + if (verbose) { + INFO("*** calculating nested dissection (ND) permutation of matrix ..."); + } + run_timer.start(); + cpu_timer.start(); + MathLib::Cluster cluster_tree(n, iA, jA); + unsigned *op_perm(new unsigned[n]); + unsigned *po_perm(new unsigned[n]); + for (unsigned k(0); k<n; k++) + op_perm[k] = po_perm[k] = k; + cluster_tree.createClusterTree(op_perm, po_perm, 1000); + if (verbose) { + INFO("\t[ND] - took %e sec \t%e sec", cpu_timer.elapsed(), run_timer.elapsed()); + } + + // applying the nested dissection reordering + if (verbose) { + INFO("\t[ND] applying nested dissection permutation to FEM matrix ... "); + } + run_timer.start(); + cpu_timer.start(); + mat.reorderMatrix(op_perm, po_perm); + if (verbose) { + INFO("\t[ND]: - took %e sec\t%e sec", cpu_timer.elapsed(), run_timer.elapsed()); + } + + if (verbose) { + INFO("*** %d matrix vector multiplications (MVM) with Toms amuxCRS (%d threads)... ", n_mults, n_threads); + } + + run_timer.start(); + cpu_timer.start(); + for (std::size_t k(0); k<n_mults; k++) { + mat.amux (1.0, x, y); + } + + if (verbose) { + INFO("\t[MVM] - took %e sec cpu time, %e sec run time", cpu_timer.elapsed(), run_timer.elapsed()); + } + + delete [] x; + delete [] y; + + delete custom_format; + delete logogCout; + LOGOG_SHUTDOWN(); + + return 0; } diff --git a/SimpleTests/MatrixTests/MatVecMultPthreads.cpp b/SimpleTests/MatrixTests/MatVecMultPthreads.cpp index 1b38483b3584500f54bfe0d3091a462824106752..aa50412972bc1576c8bc09a3b10c627be5b3c03d 100644 --- a/SimpleTests/MatrixTests/MatVecMultPthreads.cpp +++ b/SimpleTests/MatrixTests/MatVecMultPthreads.cpp @@ -38,115 +38,115 @@ int main(int argc, char *argv[]) { - LOGOG_INITIALIZE(); + LOGOG_INITIALIZE(); - TCLAP::CmdLine cmd("Simple matrix vector multiplication test employing pthreads", ' ', "0.1"); + TCLAP::CmdLine cmd("Simple matrix vector multiplication test employing pthreads", ' ', "0.1"); - // Define a value argument and add it to the command line. - // A value arg defines a flag and a type of value that it expects, - // such as "-m matrix". - TCLAP::ValueArg<std::string> matrix_arg("m", "matrix", "input matrix file", true, "", "string"); + // Define a value argument and add it to the command line. + // A value arg defines a flag and a type of value that it expects, + // such as "-m matrix". + TCLAP::ValueArg<std::string> matrix_arg("m", "matrix", "input matrix file", true, "", "string"); - // Add the argument mesh_arg to the CmdLine object. The CmdLine object - // uses this Arg to parse the command line. - cmd.add( matrix_arg ); + // Add the argument mesh_arg to the CmdLine object. The CmdLine object + // uses this Arg to parse the command line. + cmd.add( matrix_arg ); - TCLAP::ValueArg<unsigned> n_cores_arg("p", "number-cores", "number of cores to use", false, 1, "number"); - cmd.add( n_cores_arg ); + TCLAP::ValueArg<unsigned> n_cores_arg("p", "number-cores", "number of cores to use", false, 1, "number"); + cmd.add( n_cores_arg ); - TCLAP::ValueArg<unsigned> n_mults_arg("n", "number-of-multiplications", "number of multiplications to perform", true, 10, "number"); - cmd.add( n_mults_arg ); + TCLAP::ValueArg<unsigned> n_mults_arg("n", "number-of-multiplications", "number of multiplications to perform", true, 10, "number"); + cmd.add( n_mults_arg ); - TCLAP::ValueArg<std::string> output_arg("o", "output", "output file", false, "", "string"); - cmd.add( output_arg ); + TCLAP::ValueArg<std::string> output_arg("o", "output", "output file", false, "", "string"); + cmd.add( output_arg ); - TCLAP::ValueArg<bool> verbosity_arg("v", "verbose", "level of verbosity [0 very low information, 1 much information]", false, 0, "string"); - cmd.add( verbosity_arg ); + TCLAP::ValueArg<bool> verbosity_arg("v", "verbose", "level of verbosity [0 very low information, 1 much information]", false, 0, "string"); + cmd.add( verbosity_arg ); - cmd.parse( argc, argv ); + cmd.parse( argc, argv ); - std::string fname_mat (matrix_arg.getValue()); + std::string fname_mat (matrix_arg.getValue()); - BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter); - logog::Cout *logogCout(new logog::Cout); - logogCout->SetFormatter(*custom_format); + BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter); + logog::Cout *logogCout(new logog::Cout); + logogCout->SetFormatter(*custom_format); - logog::LogFile *logog_file(nullptr); - if (! output_arg.getValue().empty()) { - logog_file = new logog::LogFile(output_arg.getValue().c_str()); - logog_file->SetFormatter( *custom_format ); - } + logog::LogFile *logog_file(nullptr); + if (! output_arg.getValue().empty()) { + logog_file = new logog::LogFile(output_arg.getValue().c_str()); + logog_file->SetFormatter( *custom_format ); + } INFO("%s was build with compiler %s", - argv[0], - BaseLib::BuildInfo::cmake_cxx_compiler.c_str()); + argv[0], + BaseLib::BuildInfo::cmake_cxx_compiler.c_str()); #ifdef NDEBUG - INFO("CXX_FLAGS: %s %s", - BaseLib::BuildInfo::cmake_cxx_flags.c_str(), - BaseLib::BuildInfo::cmake_cxx_flags_release.c_str()); + INFO("CXX_FLAGS: %s %s", + BaseLib::BuildInfo::cmake_cxx_flags.c_str(), + BaseLib::BuildInfo::cmake_cxx_flags_release.c_str()); #else - INFO("CXX_FLAGS: %s %s", - BaseLib::BuildInfo::cmake_cxx_flags.c_str(), - BaseLib::BuildInfo::cmake_cxx_flags_debug.c_str()); + INFO("CXX_FLAGS: %s %s", + BaseLib::BuildInfo::cmake_cxx_flags.c_str(), + BaseLib::BuildInfo::cmake_cxx_flags_debug.c_str()); #endif #ifdef UNIX - const int max_host_name_len (255); - char *hostname(new char[max_host_name_len]); - if (gethostname(hostname, max_host_name_len) == 0) - INFO("hostname: %s", hostname); - delete [] host_name_len; + const int max_host_name_len (255); + char *hostname(new char[max_host_name_len]); + if (gethostname(hostname, max_host_name_len) == 0) + INFO("hostname: %s", hostname); + delete [] host_name_len; #endif - // *** reading matrix in crs format from file - std::ifstream in(fname_mat.c_str(), std::ios::in | std::ios::binary); - double *A(NULL); - unsigned *iA(NULL), *jA(NULL), n; - if (in) { - INFO("reading matrix from %s ...", fname_mat.c_str()); - BaseLib::RunTime timer; - timer.start(); - CS_read(in, n, iA, jA, A); - INFO("\t- took %e s", timer.elapsed()); - } else { - INFO("error reading matrix from %s", fname_mat.c_str()); - return -1; - } - unsigned nnz(iA[n]); - INFO("\tParameters read: n=%d, nnz=%d", n, nnz); + // *** reading matrix in crs format from file + std::ifstream in(fname_mat.c_str(), std::ios::in | std::ios::binary); + double *A(NULL); + unsigned *iA(NULL), *jA(NULL), n; + if (in) { + INFO("reading matrix from %s ...", fname_mat.c_str()); + BaseLib::RunTime timer; + timer.start(); + CS_read(in, n, iA, jA, A); + INFO("\t- took %e s", timer.elapsed()); + } else { + INFO("error reading matrix from %s", fname_mat.c_str()); + return -1; + } + unsigned nnz(iA[n]); + INFO("\tParameters read: n=%d, nnz=%d", n, nnz); #ifdef HAVE_PTHREADS - unsigned n_threads(n_cores_arg.getValue()); - MathLib::CRSMatrixPThreads<double> mat (n, iA, jA, A, n_threads); + unsigned n_threads(n_cores_arg.getValue()); + MathLib::CRSMatrixPThreads<double> mat (n, iA, jA, A, n_threads); - double *x(new double[n]); - double *y(new double[n]); + double *x(new double[n]); + double *y(new double[n]); - for (unsigned k(0); k<n; ++k) - x[k] = 1.0; + for (unsigned k(0); k<n; ++k) + x[k] = 1.0; - // read the number of multiplication to execute - unsigned n_mults (n_mults_arg.getValue()); + // read the number of multiplication to execute + unsigned n_mults (n_mults_arg.getValue()); - INFO("*** %d matrix vector multiplications (MVM) with Toms amuxCRS (%d threads) ...", n_mults, n_threads); - BaseLib::RunTime run_timer; - BaseLib::CPUTime cpu_timer; - run_timer.start(); - cpu_timer.start(); - for (std::size_t k(0); k<n_mults; k++) { - mat.amux (1.0, x, y); - } + INFO("*** %d matrix vector multiplications (MVM) with Toms amuxCRS (%d threads) ...", n_mults, n_threads); + BaseLib::RunTime run_timer; + BaseLib::CPUTime cpu_timer; + run_timer.start(); + cpu_timer.start(); + for (std::size_t k(0); k<n_mults; k++) { + mat.amux (1.0, x, y); + } - INFO("\t[MVM] - took %e sec cpu time, %e sec run time", cpu_timer.elapsed(), run_timer.elapsed()); + INFO("\t[MVM] - took %e sec cpu time, %e sec run time", cpu_timer.elapsed(), run_timer.elapsed()); - delete [] x; - delete [] y; + delete [] x; + delete [] y; #endif - delete custom_format; - delete logogCout; - delete logog_file; - LOGOG_SHUTDOWN(); + delete custom_format; + delete logogCout; + delete logog_file; + LOGOG_SHUTDOWN(); - return 0; + return 0; } diff --git a/SimpleTests/MeshTests/CMakeLists.txt b/SimpleTests/MeshTests/CMakeLists.txt index a8cb4900136bdf021b01e4f8473c81a6c0472f52..72e95ff5e0bd05e113675c4b6b2405a8df8a7364 100644 --- a/SimpleTests/MeshTests/CMakeLists.txt +++ b/SimpleTests/MeshTests/CMakeLists.txt @@ -1,31 +1,31 @@ # Create the executable add_executable(MeshRead - MeshRead.cpp - ${SOURCES} - ${HEADERS} + MeshRead.cpp + ${SOURCES} + ${HEADERS} ) target_link_libraries(MeshRead - MeshLib - FileIO - MathLib - BaseLib - GeoLib - ${BOOST_LIBRARIES} + MeshLib + FileIO + MathLib + BaseLib + GeoLib + ${BOOST_LIBRARIES} ) # Create MeshSearchTest executable add_executable(MeshSearchTest - MeshSearchTest.cpp - ${SOURCES} - ${HEADERS} + MeshSearchTest.cpp + ${SOURCES} + ${HEADERS} ) target_link_libraries(MeshSearchTest - MeshLib - FileIO - MathLib - BaseLib - GeoLib - ${BOOST_LIBRARIES} + MeshLib + FileIO + MathLib + BaseLib + GeoLib + ${BOOST_LIBRARIES} ) diff --git a/SimpleTests/MeshTests/MPI/CMakeLists.txt b/SimpleTests/MeshTests/MPI/CMakeLists.txt index 66ff53474fa1ddbd83f1556a61f495c3a3fcb5b5..56e30dfe9d1c9bc81d68594130399fad450aedb1 100644 --- a/SimpleTests/MeshTests/MPI/CMakeLists.txt +++ b/SimpleTests/MeshTests/MPI/CMakeLists.txt @@ -1,40 +1,40 @@ add_executable(test_node_partitioned_mesh - NodePartitionedMeshTester.cpp + NodePartitionedMeshTester.cpp ) target_link_libraries(test_node_partitioned_mesh - MeshLib - FileIO - ${ADDITIONAL_LIBS} - ${BOOST_LIBRARIES} + MeshLib + FileIO + ${ADDITIONAL_LIBS} + ${BOOST_LIBRARIES} ) if(OGS_USE_PETSC) - target_link_libraries(test_node_partitioned_mesh ${PETSC_LIBRARIES}) + target_link_libraries(test_node_partitioned_mesh ${PETSC_LIBRARIES}) endif() if(OGS_USE_MPI) - target_link_libraries(test_node_partitioned_mesh ${MPI_CXX_LIBRARIES}) + target_link_libraries(test_node_partitioned_mesh ${MPI_CXX_LIBRARIES}) endif() AddTest( - NAME NodePartitionedMeshTestASCII - PATH NodePartitionedMesh/ASCII - EXECUTABLE test_node_partitioned_mesh - EXECUTABLE_ARGS mesh_3d ${Data_BINARY_DIR}/NodePartitionedMesh/ASCII - WRAPPER mpirun - WRAPPER_ARGS -np 3 - TESTER diff - DIFF_DATA mesh_3d_partition_0.msh mesh_3d_partition_1.msh mesh_3d_partition_2.msh + NAME NodePartitionedMeshTestASCII + PATH NodePartitionedMesh/ASCII + EXECUTABLE test_node_partitioned_mesh + EXECUTABLE_ARGS mesh_3d ${Data_BINARY_DIR}/NodePartitionedMesh/ASCII + WRAPPER mpirun + WRAPPER_ARGS -np 3 + TESTER diff + DIFF_DATA mesh_3d_partition_0.msh mesh_3d_partition_1.msh mesh_3d_partition_2.msh ) AddTest( - NAME NodePartitionedMeshTestBinary - PATH NodePartitionedMesh/Binary - EXECUTABLE test_node_partitioned_mesh - EXECUTABLE_ARGS mesh_3d ${Data_BINARY_DIR}/NodePartitionedMesh/Binary - WRAPPER mpirun - WRAPPER_ARGS -np 3 - TESTER diff - DIFF_DATA mesh_3d_partition_0.msh mesh_3d_partition_1.msh mesh_3d_partition_2.msh + NAME NodePartitionedMeshTestBinary + PATH NodePartitionedMesh/Binary + EXECUTABLE test_node_partitioned_mesh + EXECUTABLE_ARGS mesh_3d ${Data_BINARY_DIR}/NodePartitionedMesh/Binary + WRAPPER mpirun + WRAPPER_ARGS -np 3 + TESTER diff + DIFF_DATA mesh_3d_partition_0.msh mesh_3d_partition_1.msh mesh_3d_partition_2.msh ) diff --git a/SimpleTests/MeshTests/MeshRead.cpp b/SimpleTests/MeshTests/MeshRead.cpp index ba64b1558b58ee05a6be9f07e223044a34c5e286..8f47cea427276e34ac0b35d90c005ae64290603c 100644 --- a/SimpleTests/MeshTests/MeshRead.cpp +++ b/SimpleTests/MeshTests/MeshRead.cpp @@ -30,57 +30,57 @@ int main(int argc, char *argv[]) { - LOGOG_INITIALIZE(); - BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter); - logog::Cout *logogCout(new logog::Cout); - logogCout->SetFormatter(*custom_format); + LOGOG_INITIALIZE(); + BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter); + logog::Cout *logogCout(new logog::Cout); + logogCout->SetFormatter(*custom_format); - TCLAP::CmdLine cmd("Simple mesh loading test", ' ', "0.1"); + TCLAP::CmdLine cmd("Simple mesh loading test", ' ', "0.1"); - // Define a value argument and add it to the command line. - // A value arg defines a flag and a type of value that it expects, - // such as "-m meshfile". - TCLAP::ValueArg<std::string> mesh_arg("m","mesh","input mesh file",true,"homer","string"); + // Define a value argument and add it to the command line. + // A value arg defines a flag and a type of value that it expects, + // such as "-m meshfile". + TCLAP::ValueArg<std::string> mesh_arg("m","mesh","input mesh file",true,"homer","string"); - // Add the argument mesh_arg to the CmdLine object. The CmdLine object - // uses this Arg to parse the command line. - cmd.add( mesh_arg ); + // Add the argument mesh_arg to the CmdLine object. The CmdLine object + // uses this Arg to parse the command line. + cmd.add( mesh_arg ); - cmd.parse( argc, argv ); + cmd.parse( argc, argv ); - std::string fname (mesh_arg.getValue()); + std::string fname (mesh_arg.getValue()); #ifndef WIN32 - BaseLib::MemWatch mem_watch; - unsigned long mem_without_mesh (mem_watch.getVirtMemUsage()); + BaseLib::MemWatch mem_watch; + unsigned long mem_without_mesh (mem_watch.getVirtMemUsage()); #endif - BaseLib::RunTime run_time; - run_time.start(); - MeshLib::Mesh* mesh = MeshLib::IO::readMeshFromFile(fname); + BaseLib::RunTime run_time; + run_time.start(); + MeshLib::Mesh* mesh = MeshLib::IO::readMeshFromFile(fname); #ifndef WIN32 - unsigned long mem_with_mesh (mem_watch.getVirtMemUsage()); -// std::cout << "mem for mesh: " << (mem_with_mesh - mem_without_mesh)/(1024*1024) << " MB" << std::endl; - INFO ("mem for mesh: %i MB", (mem_with_mesh - mem_without_mesh)/(1024*1024)); + unsigned long mem_with_mesh (mem_watch.getVirtMemUsage()); +// std::cout << "mem for mesh: " << (mem_with_mesh - mem_without_mesh)/(1024*1024) << " MB" << std::endl; + INFO ("mem for mesh: %i MB", (mem_with_mesh - mem_without_mesh)/(1024*1024)); #endif -// std::cout << "time for reading: " << run_time.elapsed() << " s" << std::endl; - INFO ("time for reading: %f s", run_time.elapsed()); +// std::cout << "time for reading: " << run_time.elapsed() << " s" << std::endl; + INFO ("time for reading: %f s", run_time.elapsed()); /* - unsigned elem_id = 25000; - const MeshLib::Element* e = mesh->getElement(elem_id); - const std::size_t nElems = mesh->getNElements(); - for (unsigned i=0; i< e->getNNeighbors(); i++) - { - for (unsigned j=0; j< nElems; j++) - if (mesh->getElement(j) == e->getNeighbor(i)) - std::cout << "neighbour of element " << elem_id << " : " << j << std::endl; - } + unsigned elem_id = 25000; + const MeshLib::Element* e = mesh->getElement(elem_id); + const std::size_t nElems = mesh->getNElements(); + for (unsigned i=0; i< e->getNNeighbors(); i++) + { + for (unsigned j=0; j< nElems; j++) + if (mesh->getElement(j) == e->getNeighbor(i)) + std::cout << "neighbour of element " << elem_id << " : " << j << std::endl; + } */ - delete mesh; - delete logogCout; - delete custom_format; - LOGOG_SHUTDOWN(); + delete mesh; + delete logogCout; + delete custom_format; + LOGOG_SHUTDOWN(); } diff --git a/SimpleTests/MeshTests/MeshSearchTest.cpp b/SimpleTests/MeshTests/MeshSearchTest.cpp index 52b0220959cb0b862a82c608655de51760f5637f..19cad90aff9ad237a79c2b14d7ec76a57ffcd9cf 100644 --- a/SimpleTests/MeshTests/MeshSearchTest.cpp +++ b/SimpleTests/MeshTests/MeshSearchTest.cpp @@ -25,128 +25,128 @@ #include "MeshLib/Mesh.h" void testMeshGridAlgorithm(MeshLib::Mesh const*const mesh, - std::vector<GeoLib::Point*>& pnts_for_search, - std::vector<std::size_t> &idx_found_nodes, bool contiguous) + std::vector<GeoLib::Point*>& pnts_for_search, + std::vector<std::size_t> &idx_found_nodes, bool contiguous) { - // constructing Grid - INFO ("[MeshGridAlgorithm] constructing mesh grid object ..."); - - if (contiguous) { - std::vector<MeshLib::Node> mesh_nodes; - std::size_t n_nodes(mesh->getNodes().size()); - mesh_nodes.reserve(n_nodes); - for (std::size_t k(0); k<n_nodes; k++) { - mesh_nodes.push_back(MeshLib::Node(*(mesh->getNodes()[k]))); - } + // constructing Grid + INFO ("[MeshGridAlgorithm] constructing mesh grid object ..."); + + if (contiguous) { + std::vector<MeshLib::Node> mesh_nodes; + std::size_t n_nodes(mesh->getNodes().size()); + mesh_nodes.reserve(n_nodes); + for (std::size_t k(0); k<n_nodes; k++) { + mesh_nodes.push_back(MeshLib::Node(*(mesh->getNodes()[k]))); + } #ifndef WIN32 - BaseLib::MemWatch mem_watch; - unsigned long mem_without_mesh (mem_watch.getVirtMemUsage()); + BaseLib::MemWatch mem_watch; + unsigned long mem_without_mesh (mem_watch.getVirtMemUsage()); #endif - clock_t start_grid_construction = clock(); - GeoLib::Grid<MeshLib::Node> mesh_grid(mesh_nodes.begin(), mesh_nodes.end(), 511); - clock_t end_grid_construction = clock(); + clock_t start_grid_construction = clock(); + GeoLib::Grid<MeshLib::Node> mesh_grid(mesh_nodes.begin(), mesh_nodes.end(), 511); + clock_t end_grid_construction = clock(); #ifndef WIN32 - unsigned long mem_with_mesh (mem_watch.getVirtMemUsage()); + unsigned long mem_with_mesh (mem_watch.getVirtMemUsage()); #endif - INFO("\tdone, construction time: %f seconds", (end_grid_construction-start_grid_construction)/(double)(CLOCKS_PER_SEC)); - #ifndef WIN32 - INFO ("[MeshGridAlgorithm] mem for mesh grid: %i MB", (mem_with_mesh - mem_without_mesh)/(1024*1024)); - #endif - const std::size_t n_pnts_for_search(pnts_for_search.size()); - INFO ("[MeshGridAlgorithm] searching %d points ...", pnts_for_search.size()); - clock_t start = clock(); - for (std::size_t k(0); k<n_pnts_for_search; k++) { - MeshLib::Node const* node(mesh_grid.getNearestPoint(*(pnts_for_search[k]))); - idx_found_nodes.push_back(node->getID()); - } - clock_t stop = clock(); - INFO("\tdone, search time: %f seconds", (stop-start)/(double)(CLOCKS_PER_SEC)); - } else { + INFO("\tdone, construction time: %f seconds", (end_grid_construction-start_grid_construction)/(double)(CLOCKS_PER_SEC)); + #ifndef WIN32 + INFO ("[MeshGridAlgorithm] mem for mesh grid: %i MB", (mem_with_mesh - mem_without_mesh)/(1024*1024)); + #endif + const std::size_t n_pnts_for_search(pnts_for_search.size()); + INFO ("[MeshGridAlgorithm] searching %d points ...", pnts_for_search.size()); + clock_t start = clock(); + for (std::size_t k(0); k<n_pnts_for_search; k++) { + MeshLib::Node const* node(mesh_grid.getNearestPoint(*(pnts_for_search[k]))); + idx_found_nodes.push_back(node->getID()); + } + clock_t stop = clock(); + INFO("\tdone, search time: %f seconds", (stop-start)/(double)(CLOCKS_PER_SEC)); + } else { #ifndef WIN32 - BaseLib::MemWatch mem_watch; - unsigned long mem_without_mesh (mem_watch.getVirtMemUsage()); + BaseLib::MemWatch mem_watch; + unsigned long mem_without_mesh (mem_watch.getVirtMemUsage()); #endif - clock_t start_grid_construction = clock(); - GeoLib::Grid<MeshLib::Node> mesh_grid(mesh->getNodes().begin(), mesh->getNodes().end(), 511); - clock_t end_grid_construction = clock(); + clock_t start_grid_construction = clock(); + GeoLib::Grid<MeshLib::Node> mesh_grid(mesh->getNodes().begin(), mesh->getNodes().end(), 511); + clock_t end_grid_construction = clock(); #ifndef WIN32 - unsigned long mem_with_mesh (mem_watch.getVirtMemUsage()); + unsigned long mem_with_mesh (mem_watch.getVirtMemUsage()); #endif - INFO("\tdone, construction time: %f seconds", (end_grid_construction-start_grid_construction)/(double)(CLOCKS_PER_SEC)); + INFO("\tdone, construction time: %f seconds", (end_grid_construction-start_grid_construction)/(double)(CLOCKS_PER_SEC)); #ifndef WIN32 - INFO ("[MeshGridAlgorithm] mem for mesh grid: %i MB", (mem_with_mesh - mem_without_mesh)/(1024*1024)); + INFO ("[MeshGridAlgorithm] mem for mesh grid: %i MB", (mem_with_mesh - mem_without_mesh)/(1024*1024)); #endif - const std::size_t n_pnts_for_search(pnts_for_search.size()); - INFO ("[MeshGridAlgorithm] searching %d points ...", pnts_for_search.size()); - clock_t start = clock(); - for (std::size_t k(0); k<n_pnts_for_search; k++) { - MeshLib::Node const* node(mesh_grid.getNearestPoint(*(pnts_for_search[k]))); - idx_found_nodes.push_back(node->getID()); - } - clock_t stop = clock(); - INFO("\tdone, search time: %f seconds", (stop-start)/(double)(CLOCKS_PER_SEC)); - } + const std::size_t n_pnts_for_search(pnts_for_search.size()); + INFO ("[MeshGridAlgorithm] searching %d points ...", pnts_for_search.size()); + clock_t start = clock(); + for (std::size_t k(0); k<n_pnts_for_search; k++) { + MeshLib::Node const* node(mesh_grid.getNearestPoint(*(pnts_for_search[k]))); + idx_found_nodes.push_back(node->getID()); + } + clock_t stop = clock(); + INFO("\tdone, search time: %f seconds", (stop-start)/(double)(CLOCKS_PER_SEC)); + } } int main(int argc, char *argv[]) { - LOGOG_INITIALIZE(); - logog::Cout* logog_cout (new logog::Cout); - BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter); - logog_cout->SetFormatter(*custom_format); + LOGOG_INITIALIZE(); + logog::Cout* logog_cout (new logog::Cout); + BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter); + logog_cout->SetFormatter(*custom_format); - TCLAP::CmdLine cmd("Simple mesh search test", ' ', "0.1"); + TCLAP::CmdLine cmd("Simple mesh search test", ' ', "0.1"); - // Define a value argument and add it to the command line. - // A value arg defines a flag and a type of value that it expects, - // such as "-m meshfile". - TCLAP::ValueArg<std::string> mesh_arg("m","mesh","input mesh file",true,"test.msh","string"); + // Define a value argument and add it to the command line. + // A value arg defines a flag and a type of value that it expects, + // such as "-m meshfile". + TCLAP::ValueArg<std::string> mesh_arg("m","mesh","input mesh file",true,"test.msh","string"); - // Add the argument mesh_arg to the CmdLine object. The CmdLine object - // uses this Arg to parse the command line. - cmd.add( mesh_arg ); + // Add the argument mesh_arg to the CmdLine object. The CmdLine object + // uses this Arg to parse the command line. + cmd.add( mesh_arg ); - TCLAP::ValueArg<unsigned> number_arg("n","number-of-test-points","the number of test points",true,10000,"positive number"); - cmd.add( number_arg ); + TCLAP::ValueArg<unsigned> number_arg("n","number-of-test-points","the number of test points",true,10000,"positive number"); + cmd.add( number_arg ); - TCLAP::ValueArg<bool> contiguous_arg("c","use-contiguous-memory","use a contiguous memory for the test",false,true,"yes or no | 1 or 0"); - cmd.add( contiguous_arg ); + TCLAP::ValueArg<bool> contiguous_arg("c","use-contiguous-memory","use a contiguous memory for the test",false,true,"yes or no | 1 or 0"); + cmd.add( contiguous_arg ); - cmd.parse( argc, argv ); + cmd.parse( argc, argv ); - std::string fname (mesh_arg.getValue()); + std::string fname (mesh_arg.getValue()); - MeshLib::IO::Legacy::MeshIO mesh_io; + MeshLib::IO::Legacy::MeshIO mesh_io; #ifndef WIN32 - BaseLib::MemWatch mem_watch; - unsigned long mem_without_mesh (mem_watch.getVirtMemUsage()); + BaseLib::MemWatch mem_watch; + unsigned long mem_without_mesh (mem_watch.getVirtMemUsage()); #endif - BaseLib::RunTime run_time; - run_time.start(); - MeshLib::Mesh* mesh (mesh_io.loadMeshFromFile(fname)); + BaseLib::RunTime run_time; + run_time.start(); + MeshLib::Mesh* mesh (mesh_io.loadMeshFromFile(fname)); #ifndef WIN32 - unsigned long mem_with_mesh (mem_watch.getVirtMemUsage()); - INFO ("mem for mesh: %i MB", (mem_with_mesh - mem_without_mesh)/(1024*1024)); + unsigned long mem_with_mesh (mem_watch.getVirtMemUsage()); + INFO ("mem for mesh: %i MB", (mem_with_mesh - mem_without_mesh)/(1024*1024)); #endif - INFO ("time for reading: %f s", run_time.elapsed()); - - // *** preparing test data - std::vector<MeshLib::Node*> const& nodes(mesh->getNodes()); - std::vector<GeoLib::Point*> pnts_for_search; - unsigned n(std::min(static_cast<unsigned>(nodes.size()), number_arg.getValue())); - for (std::size_t k(0); k<n; k++) { - pnts_for_search.push_back(new GeoLib::Point(*(nodes[k]), k)); - } - - std::vector<std::size_t> idx_found_nodes; - testMeshGridAlgorithm(mesh, pnts_for_search, idx_found_nodes, contiguous_arg.getValue()); - - for (std::size_t k(0); k<n; k++) { - delete pnts_for_search[k]; - } - - delete mesh; - delete custom_format; - delete logog_cout; - LOGOG_SHUTDOWN(); + INFO ("time for reading: %f s", run_time.elapsed()); + + // *** preparing test data + std::vector<MeshLib::Node*> const& nodes(mesh->getNodes()); + std::vector<GeoLib::Point*> pnts_for_search; + unsigned n(std::min(static_cast<unsigned>(nodes.size()), number_arg.getValue())); + for (std::size_t k(0); k<n; k++) { + pnts_for_search.push_back(new GeoLib::Point(*(nodes[k]), k)); + } + + std::vector<std::size_t> idx_found_nodes; + testMeshGridAlgorithm(mesh, pnts_for_search, idx_found_nodes, contiguous_arg.getValue()); + + for (std::size_t k(0); k<n; k++) { + delete pnts_for_search[k]; + } + + delete mesh; + delete custom_format; + delete logog_cout; + LOGOG_SHUTDOWN(); } diff --git a/SimpleTests/SolverTests/BiCGStabDiagPrecond.cpp b/SimpleTests/SolverTests/BiCGStabDiagPrecond.cpp index e69b5afd1d828803e8b78ac5501b6f171dcab7c0..1765f45eaceec739fb0ecf4674461b6eaa9bae8d 100644 --- a/SimpleTests/SolverTests/BiCGStabDiagPrecond.cpp +++ b/SimpleTests/SolverTests/BiCGStabDiagPrecond.cpp @@ -16,68 +16,68 @@ int main(int argc, char *argv[]) { - if (argc != 4) { - std::cout << "Usage: " << argv[0] << " matrix rhs number-of-threads" << std::endl; - return -1; - } - - // read number of threads -// unsigned num_omp_threads (1); -// num_omp_threads = atoi (argv[3]); - - // *** reading matrix in crs format from file - std::string fname(argv[1]); - MathLib::CRSMatrixDiagPrecond *mat (new MathLib::CRSMatrixDiagPrecond(fname)); - - unsigned n (mat->getNRows()); - bool verbose (true); - if (verbose) - std::cout << "Parameters read: n=" << n << std::endl; - - double *x(new double[n]); - double *b(new double[n]); - - // *** init start vector x - for (std::size_t k(0); k<n; k++) { - x[k] = 1.0; - } - // *** read rhs - fname = argv[2]; - std::ifstream in(fname.c_str()); - if (in) { - read (in, n, b); - in.close(); - } else { - std::cout << "problem reading rhs - initializing b with 1.0" << std::endl; - for (std::size_t k(0); k<n; k++) { - b[k] = 1.0; - } - } - - - if (verbose) - std::cout << "solving system with BiCGStab method (diagonal preconditioner) ... " << std::flush; - - double eps (1.0e-6); - unsigned steps (4000); - BaseLib::RunTime run_timer; - BaseLib::CPUTime cpu_timer; - run_timer.start(); - cpu_timer.start(); - - MathLib::BiCGStab ((*mat), b, x, eps, steps); - - if (verbose) { - std::cout << " in " << steps << " iterations" << std::endl; - std::cout << "\t(residuum is " << eps << ") took " << cpu_timer.elapsed() << " sec time and " << run_timer.elapsed() << " sec" << std::endl; - } else { - std::cout << cpu_timer.elapsed() << std::endl; - } - - delete mat; - delete [] x; - delete [] b; - - return 0; + if (argc != 4) { + std::cout << "Usage: " << argv[0] << " matrix rhs number-of-threads" << std::endl; + return -1; + } + + // read number of threads +// unsigned num_omp_threads (1); +// num_omp_threads = atoi (argv[3]); + + // *** reading matrix in crs format from file + std::string fname(argv[1]); + MathLib::CRSMatrixDiagPrecond *mat (new MathLib::CRSMatrixDiagPrecond(fname)); + + unsigned n (mat->getNRows()); + bool verbose (true); + if (verbose) + std::cout << "Parameters read: n=" << n << std::endl; + + double *x(new double[n]); + double *b(new double[n]); + + // *** init start vector x + for (std::size_t k(0); k<n; k++) { + x[k] = 1.0; + } + // *** read rhs + fname = argv[2]; + std::ifstream in(fname.c_str()); + if (in) { + read (in, n, b); + in.close(); + } else { + std::cout << "problem reading rhs - initializing b with 1.0" << std::endl; + for (std::size_t k(0); k<n; k++) { + b[k] = 1.0; + } + } + + + if (verbose) + std::cout << "solving system with BiCGStab method (diagonal preconditioner) ... " << std::flush; + + double eps (1.0e-6); + unsigned steps (4000); + BaseLib::RunTime run_timer; + BaseLib::CPUTime cpu_timer; + run_timer.start(); + cpu_timer.start(); + + MathLib::BiCGStab ((*mat), b, x, eps, steps); + + if (verbose) { + std::cout << " in " << steps << " iterations" << std::endl; + std::cout << "\t(residuum is " << eps << ") took " << cpu_timer.elapsed() << " sec time and " << run_timer.elapsed() << " sec" << std::endl; + } else { + std::cout << cpu_timer.elapsed() << std::endl; + } + + delete mat; + delete [] x; + delete [] b; + + return 0; } diff --git a/SimpleTests/SolverTests/CMakeLists.txt b/SimpleTests/SolverTests/CMakeLists.txt index cec6cda30aa788b92c6372e58827c79db913296d..e25b8f744c2edb5b8d19fa0836b1f6090c8a7e5e 100644 --- a/SimpleTests/SolverTests/CMakeLists.txt +++ b/SimpleTests/SolverTests/CMakeLists.txt @@ -1,59 +1,59 @@ add_executable(ConjugateGradientUnpreconditioned - ConjugateGradientUnpreconditioned.cpp - ${SOURCES} - ${HEADERS} + ConjugateGradientUnpreconditioned.cpp + ${SOURCES} + ${HEADERS} ) set_target_properties(ConjugateGradientUnpreconditioned PROPERTIES FOLDER SimpleTests) add_executable(ConjugateGradientDiagPrecond - ConjugateGradientDiagonalPreconditioned.cpp - ${SOURCES} - ${HEADERS} + ConjugateGradientDiagonalPreconditioned.cpp + ${SOURCES} + ${HEADERS} ) set_target_properties(ConjugateGradientDiagPrecond PROPERTIES FOLDER SimpleTests) add_executable(BiCGStabDiagPrecond - BiCGStabDiagPrecond.cpp - ${SOURCES} - ${HEADERS} + BiCGStabDiagPrecond.cpp + ${SOURCES} + ${HEADERS} ) set_target_properties(BiCGStabDiagPrecond PROPERTIES FOLDER SimpleTests) add_executable(GMResDiagPrecond - GMResDiagPrecond.cpp - ${SOURCES} - ${HEADERS} + GMResDiagPrecond.cpp + ${SOURCES} + ${HEADERS} ) set_target_properties(GMResDiagPrecond PROPERTIES FOLDER SimpleTests) target_link_libraries(ConjugateGradientUnpreconditioned - ${BLAS_LIBRARIES} - ${LAPACK_LIBRARIES} - ${ADDITIONAL_LIBS} - MathLib - BaseLib + ${BLAS_LIBRARIES} + ${LAPACK_LIBRARIES} + ${ADDITIONAL_LIBS} + MathLib + BaseLib ) target_link_libraries(ConjugateGradientDiagPrecond - ${BLAS_LIBRARIES} - ${LAPACK_LIBRARIES} - ${ADDITIONAL_LIBS} - MathLib - BaseLib + ${BLAS_LIBRARIES} + ${LAPACK_LIBRARIES} + ${ADDITIONAL_LIBS} + MathLib + BaseLib ) target_link_libraries(BiCGStabDiagPrecond - ${BLAS_LIBRARIES} - ${LAPACK_LIBRARIES} - ${ADDITIONAL_LIBS} - MathLib - BaseLib + ${BLAS_LIBRARIES} + ${LAPACK_LIBRARIES} + ${ADDITIONAL_LIBS} + MathLib + BaseLib ) target_link_libraries(GMResDiagPrecond - ${BLAS_LIBRARIES} - ${LAPACK_LIBRARIES} - ${ADDITIONAL_LIBS} - MathLib - BaseLib + ${BLAS_LIBRARIES} + ${LAPACK_LIBRARIES} + ${ADDITIONAL_LIBS} + MathLib + BaseLib ) diff --git a/SimpleTests/SolverTests/ConjugateGradientDiagonalPreconditioned.cpp b/SimpleTests/SolverTests/ConjugateGradientDiagonalPreconditioned.cpp index 049708bc00d4d443bb9eefa579e92fb0f0d73ab5..046074c7a81f7f3382ba03ea4a2122327b8fb9fe 100644 --- a/SimpleTests/SolverTests/ConjugateGradientDiagonalPreconditioned.cpp +++ b/SimpleTests/SolverTests/ConjugateGradientDiagonalPreconditioned.cpp @@ -16,76 +16,76 @@ int main(int argc, char *argv[]) { - if (argc != 4) { - std::cout << "Usage: " << argv[0] << " matrix rhs number-of-threads" << std::endl; - return -1; - } - - // read number of threads - unsigned num_omp_threads (1); - num_omp_threads = atoi (argv[3]); - - // *** reading matrix in crs format from file - std::string fname(argv[1]); - MathLib::CRSMatrixDiagPrecond *mat (new MathLib::CRSMatrixDiagPrecond(fname)); - - unsigned n (mat->getNRows()); - bool verbose (true); - if (verbose) - std::cout << "Parameters read: n=" << n << std::endl; - - double *x(new double[n]); - double *b(new double[n]); - - // *** init start vector x - for (std::size_t k(0); k<n; k++) { - x[k] = 0.0; - } - // *** read rhs - fname = argv[2]; - std::ifstream in(fname.c_str()); - if (in) { - read (in, n, b); - in.close(); - } else { - std::cout << "problem reading rhs - initializing b with 1.0" << std::endl; - for (std::size_t k(0); k<n; k++) { - b[k] = 1.0; - } - } - - - if (verbose) - std::cout << "solving system with PCG method (diagonal preconditioner) ... " << std::flush; - - double eps (1.0e-6); - unsigned steps (4000); - BaseLib::RunTime run_timer; - BaseLib::CPUTime cpu_timer; - run_timer.start(); - cpu_timer.start(); - - if (num_omp_threads == 1) { - MathLib::CG(mat, b, x, eps, steps); - } else { - #ifdef _OPENMP - MathLib::CGParallel(mat, b, x, eps, steps); - #else - std::cout << "OpenMP is not switched on" << std::endl; - #endif - } - - if (verbose) { - std::cout << " in " << steps << " iterations" << std::endl; - std::cout << "\t(residuum is " << eps << ") took " << cpu_timer.elapsed() << " sec time and " << run_timer.elapsed() << " sec" << std::endl; - } else { - std::cout << cpu_timer.elapsed() << std::endl; - } - - delete mat; - delete [] x; - delete [] b; - - return 0; + if (argc != 4) { + std::cout << "Usage: " << argv[0] << " matrix rhs number-of-threads" << std::endl; + return -1; + } + + // read number of threads + unsigned num_omp_threads (1); + num_omp_threads = atoi (argv[3]); + + // *** reading matrix in crs format from file + std::string fname(argv[1]); + MathLib::CRSMatrixDiagPrecond *mat (new MathLib::CRSMatrixDiagPrecond(fname)); + + unsigned n (mat->getNRows()); + bool verbose (true); + if (verbose) + std::cout << "Parameters read: n=" << n << std::endl; + + double *x(new double[n]); + double *b(new double[n]); + + // *** init start vector x + for (std::size_t k(0); k<n; k++) { + x[k] = 0.0; + } + // *** read rhs + fname = argv[2]; + std::ifstream in(fname.c_str()); + if (in) { + read (in, n, b); + in.close(); + } else { + std::cout << "problem reading rhs - initializing b with 1.0" << std::endl; + for (std::size_t k(0); k<n; k++) { + b[k] = 1.0; + } + } + + + if (verbose) + std::cout << "solving system with PCG method (diagonal preconditioner) ... " << std::flush; + + double eps (1.0e-6); + unsigned steps (4000); + BaseLib::RunTime run_timer; + BaseLib::CPUTime cpu_timer; + run_timer.start(); + cpu_timer.start(); + + if (num_omp_threads == 1) { + MathLib::CG(mat, b, x, eps, steps); + } else { + #ifdef _OPENMP + MathLib::CGParallel(mat, b, x, eps, steps); + #else + std::cout << "OpenMP is not switched on" << std::endl; + #endif + } + + if (verbose) { + std::cout << " in " << steps << " iterations" << std::endl; + std::cout << "\t(residuum is " << eps << ") took " << cpu_timer.elapsed() << " sec time and " << run_timer.elapsed() << " sec" << std::endl; + } else { + std::cout << cpu_timer.elapsed() << std::endl; + } + + delete mat; + delete [] x; + delete [] b; + + return 0; } diff --git a/SimpleTests/SolverTests/ConjugateGradientUnpreconditioned.cpp b/SimpleTests/SolverTests/ConjugateGradientUnpreconditioned.cpp index 18411789e5595db607744ef8ea0a532aa92b0a86..2f722b58c3fbeea2b65149007f4c301e16f39f48 100644 --- a/SimpleTests/SolverTests/ConjugateGradientUnpreconditioned.cpp +++ b/SimpleTests/SolverTests/ConjugateGradientUnpreconditioned.cpp @@ -11,61 +11,61 @@ int main(int argc, char *argv[]) { - (void) argc; - (void) argv; + (void) argc; + (void) argv; - // *** reading matrix in crs format from file - std::string fname("/work/Thomas Fischer/data/testmat.bin"); -// std::ifstream in(fname.c_str(), std::ios::binary); - MathLib::CRSMatrix<double, unsigned> *mat (new MathLib::CRSMatrix<double, unsigned>(fname)); -/* double *A(NULL); - unsigned *iA(NULL), *jA(NULL), n; - if (in) { - std::cout << "reading matrix from " << fname << " ... " << std::flush; - CS_read(in, n, iA, jA, A); - in.close(); - std::cout << " ok" << std::endl; - } - unsigned nnz(iA[n]); + // *** reading matrix in crs format from file + std::string fname("/work/Thomas Fischer/data/testmat.bin"); +// std::ifstream in(fname.c_str(), std::ios::binary); + MathLib::CRSMatrix<double, unsigned> *mat (new MathLib::CRSMatrix<double, unsigned>(fname)); +/* double *A(NULL); + unsigned *iA(NULL), *jA(NULL), n; + if (in) { + std::cout << "reading matrix from " << fname << " ... " << std::flush; + CS_read(in, n, iA, jA, A); + in.close(); + std::cout << " ok" << std::endl; + } + unsigned nnz(iA[n]); */ - unsigned n (mat->getNRows()); - std::cout << "Parameters read: n=" << n << std::endl; + unsigned n (mat->getNRows()); + std::cout << "Parameters read: n=" << n << std::endl; - double *x(new double[n]); - double *b(new double[n]); + double *x(new double[n]); + double *b(new double[n]); - // *** init start vector x - for (std::size_t k(0); k<n; k++) { - x[k] = 1.0; - } - // *** read rhs - fname = "/work/Thomas Fischer/data/rhs.dat"; - std::ifstream in(fname.c_str()); - if (in) { - read (in, n, b); - in.close(); - } else { - std::cout << "problem reading rhs - initializing b with 1.0" << std::endl; - for (std::size_t k(0); k<n; k++) { - b[k] = 1.0; - } - } + // *** init start vector x + for (std::size_t k(0); k<n; k++) { + x[k] = 1.0; + } + // *** read rhs + fname = "/work/Thomas Fischer/data/rhs.dat"; + std::ifstream in(fname.c_str()); + if (in) { + read (in, n, b); + in.close(); + } else { + std::cout << "problem reading rhs - initializing b with 1.0" << std::endl; + for (std::size_t k(0); k<n; k++) { + b[k] = 1.0; + } + } - std::cout << "solving system with CG method ... " << std::flush; - time_t start_time, end_time; - time(&start_time); -// double cg_time (cputime(0.0)); - double eps (1.0e-6); - unsigned steps (4000); - CG (mat, b, x, eps, steps); -// cg_time = cputime(cg_time); - time(&end_time); - std::cout << " in " << steps << " iterations (residuum is " << eps << ") took " << /*cg_time <<*/ " sec time and " << (end_time-start_time) << " sec" << std::endl; + std::cout << "solving system with CG method ... " << std::flush; + time_t start_time, end_time; + time(&start_time); +// double cg_time (cputime(0.0)); + double eps (1.0e-6); + unsigned steps (4000); + CG (mat, b, x, eps, steps); +// cg_time = cputime(cg_time); + time(&end_time); + std::cout << " in " << steps << " iterations (residuum is " << eps << ") took " << /*cg_time <<*/ " sec time and " << (end_time-start_time) << " sec" << std::endl; - delete mat; - delete [] x; - delete [] b; + delete mat; + delete [] x; + delete [] b; - return 0; + return 0; } diff --git a/SimpleTests/SolverTests/GMResDiagPrecond.cpp b/SimpleTests/SolverTests/GMResDiagPrecond.cpp index e4f9296ab5b227dce9dc5a1c5ede3ffe17057063..1680db2b5f3a9806113908829c37c493a27e8f33 100644 --- a/SimpleTests/SolverTests/GMResDiagPrecond.cpp +++ b/SimpleTests/SolverTests/GMResDiagPrecond.cpp @@ -23,66 +23,66 @@ int main(int argc, char *argv[]) { - if (argc != 3) { - std::cout << "Usage: " << argv[0] << " matrix rhs" << std::endl; - return -1; - } + if (argc != 3) { + std::cout << "Usage: " << argv[0] << " matrix rhs" << std::endl; + return -1; + } - // *** reading matrix in crs format from file - std::string fname(argv[1]); - MathLib::CRSMatrixDiagPrecond *mat(new MathLib::CRSMatrixDiagPrecond(fname)); + // *** reading matrix in crs format from file + std::string fname(argv[1]); + MathLib::CRSMatrixDiagPrecond *mat(new MathLib::CRSMatrixDiagPrecond(fname)); - unsigned n(mat->getNRows()); - bool verbose(true); - if (verbose) std::cout << "Parameters read: n=" << n << std::endl; + unsigned n(mat->getNRows()); + bool verbose(true); + if (verbose) std::cout << "Parameters read: n=" << n << std::endl; - double *x(new double[n]); - double *b(new double[n]); + double *x(new double[n]); + double *b(new double[n]); - // *** init start vector x - for (std::size_t k(0); k < n; k++) { - x[k] = 1.0; - } - // *** read rhs - fname = argv[2]; - std::ifstream in(fname.c_str()); - if (in) { - read(in, n, b); - in.close(); - } else { - std::cout << "problem reading rhs - initializing b with 1.0" - << std::endl; - for (std::size_t k(0); k < n; k++) { - b[k] = 1.0; - } - } + // *** init start vector x + for (std::size_t k(0); k < n; k++) { + x[k] = 1.0; + } + // *** read rhs + fname = argv[2]; + std::ifstream in(fname.c_str()); + if (in) { + read(in, n, b); + in.close(); + } else { + std::cout << "problem reading rhs - initializing b with 1.0" + << std::endl; + for (std::size_t k(0); k < n; k++) { + b[k] = 1.0; + } + } - if (verbose) - std::cout << "solving system with GMRes method (diagonal preconditioner) ... " - << std::flush; + if (verbose) + std::cout << "solving system with GMRes method (diagonal preconditioner) ... " + << std::flush; - double eps(1.0e-6); - unsigned steps(4000); - BaseLib::RunTime run_timer; - BaseLib::CPUTime cpu_timer; - run_timer.start(); - cpu_timer.start(); + double eps(1.0e-6); + unsigned steps(4000); + BaseLib::RunTime run_timer; + BaseLib::CPUTime cpu_timer; + run_timer.start(); + cpu_timer.start(); - MathLib::GMRes((*mat), b, x, eps, 30, steps); + MathLib::GMRes((*mat), b, x, eps, 30, steps); - if (verbose) { - std::cout << " in " << steps << " iterations" << std::endl; - std::cout << "\t(residuum is " << eps << ") took " - << cpu_timer.elapsed() << " sec time and " - << run_timer.elapsed() << " sec" << std::endl; - } else { - std::cout << cpu_timer.elapsed() << std::endl; - } + if (verbose) { + std::cout << " in " << steps << " iterations" << std::endl; + std::cout << "\t(residuum is " << eps << ") took " + << cpu_timer.elapsed() << " sec time and " + << run_timer.elapsed() << " sec" << std::endl; + } else { + std::cout << cpu_timer.elapsed() << std::endl; + } - delete mat; - delete[] x; - delete[] b; + delete mat; + delete[] x; + delete[] b; - return 0; + return 0; }