Skip to content
Snippets Groups Projects
Commit c0316813 authored by Dmitri Naumov's avatar Dmitri Naumov
Browse files

[SimpleTests] Tabs to whitespaces.

parent 7bb833c4
No related branches found
No related tags found
No related merge requests found
Showing
with 1026 additions and 1026 deletions
if(CMAKE_USE_PTHREADS_INIT) if(CMAKE_USE_PTHREADS_INIT)
set(HAVE_PTHREADS TRUE) set(HAVE_PTHREADS TRUE)
endif() endif()
# Create the executable # Create the executable
add_executable(MatMult add_executable(MatMult
MatMult.cpp MatMult.cpp
${SOURCES} ${SOURCES}
${HEADERS} ${HEADERS}
) )
set_target_properties(MatMult PROPERTIES FOLDER SimpleTests) set_target_properties(MatMult PROPERTIES FOLDER SimpleTests)
target_link_libraries(MatMult logog) target_link_libraries(MatMult logog)
if(HAVE_PTHREADS) if(HAVE_PTHREADS)
add_executable(MatVecMultPthreads add_executable(MatVecMultPthreads
MatVecMultPthreads.cpp MatVecMultPthreads.cpp
${SOURCES} ${SOURCES}
${HEADERS} ${HEADERS}
) )
set_target_properties(MatVecMultPthreads PROPERTIES FOLDER SimpleTests) set_target_properties(MatVecMultPthreads PROPERTIES FOLDER SimpleTests)
target_link_libraries(MatVecMultPthreads target_link_libraries(MatVecMultPthreads
pthread pthread
BaseLib BaseLib
MathLib MathLib
logog logog
) )
endif() endif()
set_target_properties(MatMult PROPERTIES FOLDER SimpleTests) set_target_properties(MatMult PROPERTIES FOLDER SimpleTests)
target_link_libraries(MatMult target_link_libraries(MatMult
logog logog
BaseLib BaseLib
MathLib MathLib
) )
add_executable(MatTestRemoveRowsCols add_executable(MatTestRemoveRowsCols
MatTestRemoveRowsCols.cpp MatTestRemoveRowsCols.cpp
${SOURCES} ${SOURCES}
${HEADERS} ${HEADERS}
) )
set_target_properties(MatTestRemoveRowsCols PROPERTIES FOLDER SimpleTests) set_target_properties(MatTestRemoveRowsCols PROPERTIES FOLDER SimpleTests)
target_link_libraries(MatTestRemoveRowsCols target_link_libraries(MatTestRemoveRowsCols
BaseLib BaseLib
MathLib MathLib
) )
if(METIS_FOUND) if(METIS_FOUND)
add_executable(MatVecMultNDPerm add_executable(MatVecMultNDPerm
MatVecMultNDPerm.cpp MatVecMultNDPerm.cpp
${SOURCES} ${SOURCES}
${HEADERS} ${HEADERS}
) )
set_target_properties(MatVecMultNDPerm PROPERTIES FOLDER SimpleTests) set_target_properties(MatVecMultNDPerm PROPERTIES FOLDER SimpleTests)
target_link_libraries(MatVecMultNDPerm target_link_libraries(MatVecMultNDPerm
BaseLib BaseLib
MathLib MathLib
logog logog
${METIS_LIBRARIES} ${METIS_LIBRARIES}
) )
if(OPENMP_FOUND) if(OPENMP_FOUND)
add_executable(MatVecMultNDPermOpenMP add_executable(MatVecMultNDPermOpenMP
MatVecMultNDPermOpenMP.cpp MatVecMultNDPermOpenMP.cpp
${SOURCES} ${SOURCES}
${HEADERS} ${HEADERS}
) )
set_target_properties(MatVecMultNDPermOpenMP PROPERTIES FOLDER SimpleTests) set_target_properties(MatVecMultNDPermOpenMP PROPERTIES FOLDER SimpleTests)
target_link_libraries(MatVecMultNDPermOpenMP target_link_libraries(MatVecMultNDPermOpenMP
BaseLib BaseLib
MathLib MathLib
logog logog
${METIS_LIBRARIES} ${METIS_LIBRARIES}
) )
endif() endif()
endif() endif()
add_executable(DenseGaussEliminationChecker add_executable(DenseGaussEliminationChecker
DenseGaussEliminationChecker.cpp DenseGaussEliminationChecker.cpp
${SOURCES} ${SOURCES}
${HEADERS} ${HEADERS}
) )
set_target_properties(DenseGaussEliminationChecker PROPERTIES FOLDER SimpleTests) set_target_properties(DenseGaussEliminationChecker PROPERTIES FOLDER SimpleTests)
target_link_libraries(DenseGaussEliminationChecker target_link_libraries(DenseGaussEliminationChecker
logog logog
BaseLib BaseLib
MathLib MathLib
) )
...@@ -23,61 +23,61 @@ ...@@ -23,61 +23,61 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
LOGOG_INITIALIZE(); LOGOG_INITIALIZE();
BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter); BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter);
logog::Cout *logogCout(new logog::Cout); logog::Cout *logogCout(new logog::Cout);
logogCout->SetFormatter(*custom_format); logogCout->SetFormatter(*custom_format);
TCLAP::CmdLine cmd("Simple direct matrix solver test.\n\ TCLAP::CmdLine cmd("Simple direct matrix solver test.\n\
It consists of the following steps:\n\ It consists of the following steps:\n\
(1) Read a matrix A from ascii format\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\ (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"); (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"); TCLAP::ValueArg<std::string> matrix_arg("m", "matrix", "input matrix file (ascii format)", true, "", "string");
cmd.add( matrix_arg ); cmd.add( matrix_arg );
cmd.parse( argc, argv ); cmd.parse( argc, argv );
// *** reading dense matrix in ascii format from file // *** reading dense matrix in ascii format from file
std::string const fname_mat(matrix_arg.getValue()); std::string const fname_mat(matrix_arg.getValue());
std::ifstream in(fname_mat.c_str()); std::ifstream in(fname_mat.c_str());
if (!in) { if (!in) {
INFO("error reading matrix from %s", fname_mat.c_str()); INFO("error reading matrix from %s", fname_mat.c_str());
return -1; return -1;
} }
INFO("reading matrix from %s ...", fname_mat.c_str()); INFO("reading matrix from %s ...", fname_mat.c_str());
std::size_t n_rows(0), n_cols(0); std::size_t n_rows(0), n_cols(0);
in >> n_rows; in >> n_rows;
in >> n_cols; in >> n_cols;
MathLib::DenseMatrix<double, std::size_t> mat(n_rows, 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 i(0); i<mat.getNRows(); ++i) {
for (std::size_t j(0); j<mat.getNCols(); ++j) { for (std::size_t j(0); j<mat.getNCols(); ++j) {
in >> mat(i,j); in >> mat(i,j);
} }
} }
{ {
std::stringstream stream; std::stringstream stream;
stream << mat; stream << mat;
INFO("read matrix:\n%s", stream.str().c_str()); INFO("read matrix:\n%s", stream.str().c_str());
} }
std::vector<double> x(n_cols,1.0), b; std::vector<double> x(n_cols,1.0), b;
b.resize(n_rows); b.resize(n_rows);
b = mat * x; b = mat * x;
MathLib::GaussAlgorithm<MathLib::DenseMatrix<double, std::size_t>> gauss; MathLib::GaussAlgorithm<MathLib::DenseMatrix<double, std::size_t>> gauss;
gauss.solve(mat, b, true); gauss.solve(mat, b, true);
{ {
std::stringstream stream; std::stringstream stream;
std::copy(b.begin(), b.end(), std::ostream_iterator<double>(stream, " ")); std::copy(b.begin(), b.end(), std::ostream_iterator<double>(stream, " "));
stream << std::endl; stream << std::endl;
INFO("solution vector:\n%s", stream.str().c_str()); INFO("solution vector:\n%s", stream.str().c_str());
} }
delete custom_format; delete custom_format;
delete logogCout; delete logogCout;
LOGOG_SHUTDOWN(); LOGOG_SHUTDOWN();
return 0; return 0;
} }
...@@ -52,141 +52,141 @@ class FormatterCustom : public logog::FormatterGCC ...@@ -52,141 +52,141 @@ class FormatterCustom : public logog::FormatterGCC
int main(int argc, char *argv[]) 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. // 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, // A value arg defines a flag and a type of value that it expects,
// such as "-m matrix". // such as "-m matrix".
TCLAP::ValueArg<std::string> matrix_arg("m", "matrix", "input matrix file", true, "", "string"); 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 // Add the argument mesh_arg to the CmdLine object. The CmdLine object
// uses this Arg to parse the command line. // uses this Arg to parse the command line.
cmd.add( matrix_arg ); cmd.add( matrix_arg );
TCLAP::ValueArg<unsigned> n_cores_arg("p", "number-cores", "number of cores to use", false, 1, "number"); TCLAP::ValueArg<unsigned> n_cores_arg("p", "number-cores", "number of cores to use", false, 1, "number");
cmd.add( n_cores_arg ); cmd.add( n_cores_arg );
TCLAP::ValueArg<unsigned> n_mults_arg("n", "number-of-multiplications", "number of multiplications to perform", true, 10, "number"); TCLAP::ValueArg<unsigned> n_mults_arg("n", "number-of-multiplications", "number of multiplications to perform", true, 10, "number");
cmd.add( n_mults_arg ); cmd.add( n_mults_arg );
TCLAP::ValueArg<std::string> output_arg("o", "output", "output file", false, "", "string"); TCLAP::ValueArg<std::string> output_arg("o", "output", "output file", false, "", "string");
cmd.add( output_arg ); cmd.add( output_arg );
TCLAP::ValueArg<unsigned> verbosity_arg("v", "verbose", "level of verbosity [0 very low information, 1 much information]", false, 0, "string"); 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.add( verbosity_arg );
cmd.parse( argc, argv ); cmd.parse( argc, argv );
// read the number of multiplication to execute // read the number of multiplication to execute
unsigned n_mults (n_mults_arg.getValue()); unsigned n_mults (n_mults_arg.getValue());
std::string fname_mat (matrix_arg.getValue()); std::string fname_mat (matrix_arg.getValue());
FormatterCustom *custom_format (new FormatterCustom); FormatterCustom *custom_format (new FormatterCustom);
logog::Cout *logogCout(new logog::Cout); logog::Cout *logogCout(new logog::Cout);
logogCout->SetFormatter(*custom_format); logogCout->SetFormatter(*custom_format);
logog::LogFile *logog_file(NULL); logog::LogFile *logog_file(NULL);
if (! output_arg.getValue().empty()) { if (! output_arg.getValue().empty()) {
logog_file = new logog::LogFile(output_arg.getValue().c_str()); logog_file = new logog::LogFile(output_arg.getValue().c_str());
logog_file->SetFormatter( *custom_format ); logog_file->SetFormatter( *custom_format );
} }
// read number of threads // read number of threads
unsigned n_threads (n_cores_arg.getValue()); unsigned n_threads (n_cores_arg.getValue());
INFO("%s was build with compiler %s", INFO("%s was build with compiler %s",
argv[0], argv[0],
BaseLib::BuildInfo::cmake_cxx_compiler.c_str()); BaseLib::BuildInfo::cmake_cxx_compiler.c_str());
#ifdef NDEBUG #ifdef NDEBUG
INFO("CXX_FLAGS: %s %s", INFO("CXX_FLAGS: %s %s",
BaseLib::BuildInfo::cmake_cxx_flags.c_str(), BaseLib::BuildInfo::cmake_cxx_flags.c_str(),
BaseLib::BuildInfo::cmake_cxx_flags_release.c_str()); BaseLib::BuildInfo::cmake_cxx_flags_release.c_str());
#else #else
INFO("CXX_FLAGS: %s %s", INFO("CXX_FLAGS: %s %s",
BaseLib::BuildInfo::cmake_cxx_flags.c_str(), BaseLib::BuildInfo::cmake_cxx_flags.c_str(),
BaseLib::BuildInfo::cmake_cxx_flags_debug.c_str()); BaseLib::BuildInfo::cmake_cxx_flags_debug.c_str());
#endif #endif
#ifdef UNIX #ifdef UNIX
const int max_host_name_len (255); const int max_host_name_len (255);
char *hostname(new char[max_host_name_len]); char *hostname(new char[max_host_name_len]);
if (gethostname(hostname, max_host_name_len) == 0) if (gethostname(hostname, max_host_name_len) == 0)
INFO("hostname: %s", hostname); INFO("hostname: %s", hostname);
delete [] host_name_len; delete [] host_name_len;
#endif #endif
// *** reading matrix in crs format from file // *** reading matrix in crs format from file
std::ifstream in(fname_mat.c_str(), std::ios::in | std::ios::binary); std::ifstream in(fname_mat.c_str(), std::ios::in | std::ios::binary);
double *A(NULL); double *A(NULL);
unsigned *iA(NULL), *jA(NULL), n; unsigned *iA(NULL), *jA(NULL), n;
if (in) { if (in) {
INFO("reading matrix from %s ...", fname_mat.c_str()); INFO("reading matrix from %s ...", fname_mat.c_str());
BaseLib::RunTime timer; BaseLib::RunTime timer;
timer.start(); timer.start();
CS_read(in, n, iA, jA, A); CS_read(in, n, iA, jA, A);
INFO("\t- took %e s", timer.elapsed()); INFO("\t- took %e s", timer.elapsed());
} else { } else {
INFO("error reading matrix from %s", fname_mat.c_str()); INFO("error reading matrix from %s", fname_mat.c_str());
return -1; return -1;
} }
unsigned nnz(iA[n]); unsigned nnz(iA[n]);
INFO("\tParameters read: n=%d, nnz=%d", n, nnz); INFO("\tParameters read: n=%d, nnz=%d", n, nnz);
#ifdef _OPENMP #ifdef _OPENMP
omp_set_num_threads(n_threads); omp_set_num_threads(n_threads);
unsigned *mat_entries_per_core(new unsigned[n_threads]); unsigned *mat_entries_per_core(new unsigned[n_threads]);
for (unsigned k(0); k<n_threads; k++) { for (unsigned k(0); k<n_threads; k++) {
mat_entries_per_core[k] = 0; mat_entries_per_core[k] = 0;
} }
OPENMP_LOOP_TYPE i; OPENMP_LOOP_TYPE i;
{ {
#pragma omp parallel for #pragma omp parallel for
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
mat_entries_per_core[omp_get_thread_num()] += iA[i + 1] - iA[i]; mat_entries_per_core[omp_get_thread_num()] += iA[i + 1] - iA[i];
} }
} }
INFO("*** work per core ***"); INFO("*** work per core ***");
for (unsigned k(0); k<n_threads; k++) { for (unsigned k(0); k<n_threads; k++) {
INFO("\t%d\t%d", k, mat_entries_per_core[k]); INFO("\t%d\t%d", k, mat_entries_per_core[k]);
} }
#endif #endif
#ifdef _OPENMP #ifdef _OPENMP
omp_set_num_threads(n_threads); omp_set_num_threads(n_threads);
MathLib::CRSMatrixOpenMP<double, unsigned> mat (n, iA, jA, A); MathLib::CRSMatrixOpenMP<double, unsigned> mat (n, iA, jA, A);
#else #else
MathLib::CRSMatrix<double, unsigned> mat (n, iA, jA, A); MathLib::CRSMatrix<double, unsigned> mat (n, iA, jA, A);
#endif #endif
double *x(new double[n]); double *x(new double[n]);
double *y(new double[n]); double *y(new double[n]);
for (unsigned k(0); k<n; ++k) for (unsigned k(0); k<n; ++k)
x[k] = 1.0; x[k] = 1.0;
INFO("*** %d matrix vector multiplications (MVM) with Toms amuxCRS (%d threads) ...", n_mults, n_threads); INFO("*** %d matrix vector multiplications (MVM) with Toms amuxCRS (%d threads) ...", n_mults, n_threads);
BaseLib::RunTime run_timer; BaseLib::RunTime run_timer;
BaseLib::CPUTime cpu_timer; BaseLib::CPUTime cpu_timer;
run_timer.start(); run_timer.start();
cpu_timer.start(); cpu_timer.start();
for (std::size_t k(0); k<n_mults; k++) { for (std::size_t k(0); k<n_mults; k++) {
mat.amux (1.0, x, y); 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 [] x;
delete [] y; delete [] y;
delete custom_format; delete custom_format;
delete logogCout; delete logogCout;
delete logog_file; delete logog_file;
LOGOG_SHUTDOWN(); LOGOG_SHUTDOWN();
return 0; return 0;
} }
...@@ -21,59 +21,59 @@ ...@@ -21,59 +21,59 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
if (argc < 3) { if (argc < 3) {
std::cout << "Usage: " << argv[0] << " input-matrix output-matrix" << std::endl; std::cout << "Usage: " << argv[0] << " input-matrix output-matrix" << std::endl;
return 1; return 1;
} }
std::string fname_mat (argv[1]); std::string fname_mat (argv[1]);
bool verbose (true); bool verbose (true);
// *** reading matrix in crs format from file // *** reading matrix in crs format from file
std::ifstream in(fname_mat.c_str(), std::ios::in | std::ios::binary); std::ifstream in(fname_mat.c_str(), std::ios::in | std::ios::binary);
double *A(NULL); double *A(NULL);
unsigned *iA(NULL), *jA(NULL), n = 0; unsigned *iA(NULL), *jA(NULL), n = 0;
if (in) { if (in) {
if (verbose) { if (verbose) {
std::cout << "reading matrix from " << fname_mat << " ... " << std::flush; std::cout << "reading matrix from " << fname_mat << " ... " << std::flush;
} }
BaseLib::RunTime timer; BaseLib::RunTime timer;
timer.start(); timer.start();
CS_read(in, n, iA, jA, A); CS_read(in, n, iA, jA, A);
in.close(); in.close();
if (verbose) { if (verbose) {
std::cout << "ok, " << timer.elapsed() << " s" << std::endl; std::cout << "ok, " << timer.elapsed() << " s" << std::endl;
} }
} else { } else {
std::cout << "error reading matrix from " << fname_mat << std::endl; std::cout << "error reading matrix from " << fname_mat << std::endl;
} }
unsigned nnz(iA[n]); unsigned nnz(iA[n]);
if (verbose) { if (verbose) {
std::cout << "Parameters read: n=" << n << ", nnz=" << nnz << std::endl; 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); const unsigned n_rows_cols_to_erase(300);
unsigned *rows_cols_to_erase(new unsigned[n_rows_cols_to_erase]); unsigned *rows_cols_to_erase(new unsigned[n_rows_cols_to_erase]);
for (unsigned k(0); k<n_rows_cols_to_erase; k++) { for (unsigned k(0); k<n_rows_cols_to_erase; k++) {
rows_cols_to_erase[k] = (k+1)*2; rows_cols_to_erase[k] = (k+1)*2;
} }
BaseLib::RunTime timer; BaseLib::RunTime timer;
std::cout << "erasing " << n_rows_cols_to_erase << " rows and columns ... " << std::flush; std::cout << "erasing " << n_rows_cols_to_erase << " rows and columns ... " << std::flush;
timer.start(); timer.start();
mat->eraseEntries(n_rows_cols_to_erase, rows_cols_to_erase); mat->eraseEntries(n_rows_cols_to_erase, rows_cols_to_erase);
std::cout << "ok, " << timer.elapsed() << " s" << std::endl; std::cout << "ok, " << timer.elapsed() << " s" << std::endl;
delete[] rows_cols_to_erase; delete[] rows_cols_to_erase;
fname_mat = argv[2]; fname_mat = argv[2];
std::ofstream out (fname_mat.c_str(), std::ios::binary); std::ofstream out (fname_mat.c_str(), std::ios::binary);
CS_write (out, mat->getNRows(), mat->getRowPtrArray(), mat->getColIdxArray(), mat->getEntryArray()); CS_write (out, mat->getNRows(), mat->getRowPtrArray(), mat->getColIdxArray(), mat->getEntryArray());
out.close(); 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;
} }
...@@ -34,155 +34,155 @@ ...@@ -34,155 +34,155 @@
int main(int argc, char *argv[]) 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. // 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, // A value arg defines a flag and a type of value that it expects,
// such as "-m matrix". // 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"); 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 // Add the argument matrix_arg to the CmdLine object. The CmdLine object
// uses this Arg to parse the command line. // uses this Arg to parse the command line.
cmd.add( matrix_arg ); cmd.add( matrix_arg );
// TCLAP::ValueArg<unsigned> n_cores_arg("n", "number-cores", "number of cores to use", true, "1", "number"); // TCLAP::ValueArg<unsigned> n_cores_arg("n", "number-cores", "number of cores to use", true, "1", "number");
// cmd.add( n_cores_arg ); // 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"); 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 ); cmd.add( n_mults_arg );
TCLAP::ValueArg<std::string> output_arg("o", "output", "output file", false, "", "string"); TCLAP::ValueArg<std::string> output_arg("o", "output", "output file", false, "", "string");
cmd.add( output_arg ); cmd.add( output_arg );
TCLAP::ValueArg<bool> verbosity_arg("v", "verbose", "level of verbosity [0 very low information, 1 much information]", false, 0, "string"); 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.add( verbosity_arg );
cmd.parse( argc, argv ); cmd.parse( argc, argv );
// read the number of multiplication to execute // read the number of multiplication to execute
unsigned n_mults (n_mults_arg.getValue()); unsigned n_mults (n_mults_arg.getValue());
std::string fname_mat (matrix_arg.getValue()); std::string fname_mat (matrix_arg.getValue());
bool verbose (verbosity_arg.getValue()); bool verbose (verbosity_arg.getValue());
BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter); BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter);
logog::Cout *logogCout(new logog::Cout); logog::Cout *logogCout(new logog::Cout);
logogCout->SetFormatter(*custom_format); logogCout->SetFormatter(*custom_format);
INFO("%s was build with compiler %s", INFO("%s was build with compiler %s",
argv[0], argv[0],
BaseLib::BuildInfo::cmake_cxx_compiler.c_str()); BaseLib::BuildInfo::cmake_cxx_compiler.c_str());
#ifdef NDEBUG #ifdef NDEBUG
INFO("CXX_FLAGS: %s %s", INFO("CXX_FLAGS: %s %s",
BaseLib::BuildInfo::cmake_cxx_flags.c_str(), BaseLib::BuildInfo::cmake_cxx_flags.c_str(),
BaseLib::BuildInfo::cmake_cxx_flags_release.c_str()); BaseLib::BuildInfo::cmake_cxx_flags_release.c_str());
#else #else
INFO("CXX_FLAGS: %s %s", INFO("CXX_FLAGS: %s %s",
BaseLib::BuildInfo::cmake_cxx_flags.c_str(), BaseLib::BuildInfo::cmake_cxx_flags.c_str(),
BaseLib::BuildInfo::cmake_cxx_flags_debug.c_str()); BaseLib::BuildInfo::cmake_cxx_flags_debug.c_str());
#endif #endif
#ifdef UNIX #ifdef UNIX
const std::size_t length(256); const std::size_t length(256);
char *hostname(new char[length]); char *hostname(new char[length]);
gethostname (hostname, length); gethostname (hostname, length);
INFO("hostname: %s", hostname); INFO("hostname: %s", hostname);
delete [] hostname; delete [] hostname;
#endif #endif
// *** reading matrix in crs format from file // *** reading matrix in crs format from file
std::ifstream in(fname_mat.c_str(), std::ios::in | std::ios::binary); std::ifstream in(fname_mat.c_str(), std::ios::in | std::ios::binary);
double *A(NULL); double *A(NULL);
unsigned *iA(NULL), *jA(NULL), n; unsigned *iA(NULL), *jA(NULL), n;
if (in) { if (in) {
if (verbose) { if (verbose) {
INFO("reading matrix from %s ...", fname_mat.c_str()); INFO("reading matrix from %s ...", fname_mat.c_str());
} }
BaseLib::RunTime timer; BaseLib::RunTime timer;
timer.start(); timer.start();
CS_read(in, n, iA, jA, A); CS_read(in, n, iA, jA, A);
if (verbose) { if (verbose) {
INFO("\t- took %e s", timer.elapsed()); INFO("\t- took %e s", timer.elapsed());
} }
} else { } else {
ERR("error reading matrix from %s", fname_mat.c_str()); ERR("error reading matrix from %s", fname_mat.c_str());
return -1; return -1;
} }
unsigned nnz(iA[n]); unsigned nnz(iA[n]);
if (verbose) { if (verbose) {
INFO("\tParameters read: n=%d, nnz=%d", n, nnz); INFO("\tParameters read: n=%d, nnz=%d", n, nnz);
} }
MathLib::CRSMatrixReordered mat(n, iA, jA, A); MathLib::CRSMatrixReordered mat(n, iA, jA, A);
double *x(new double[n]); double *x(new double[n]);
double *y(new double[n]); double *y(new double[n]);
for (unsigned k(0); k<n; ++k) for (unsigned k(0); k<n; ++k)
x[k] = 1.0; x[k] = 1.0;
// create time measurement objects // create time measurement objects
BaseLib::RunTime run_timer; BaseLib::RunTime run_timer;
BaseLib::CPUTime cpu_timer; BaseLib::CPUTime cpu_timer;
// calculate the nested dissection reordering // calculate the nested dissection reordering
if (verbose) { if (verbose) {
INFO("*** calculating nested dissection (ND) permutation of matrix ..."); INFO("*** calculating nested dissection (ND) permutation of matrix ...");
} }
run_timer.start(); run_timer.start();
cpu_timer.start(); cpu_timer.start();
MathLib::Cluster cluster_tree(n, iA, jA); MathLib::Cluster cluster_tree(n, iA, jA);
unsigned *op_perm(new unsigned[n]); unsigned *op_perm(new unsigned[n]);
unsigned *po_perm(new unsigned[n]); unsigned *po_perm(new unsigned[n]);
for (unsigned k(0); k<n; k++) for (unsigned k(0); k<n; k++)
op_perm[k] = po_perm[k] = k; op_perm[k] = po_perm[k] = k;
cluster_tree.createClusterTree(op_perm, po_perm, 1000); cluster_tree.createClusterTree(op_perm, po_perm, 1000);
if (verbose) { if (verbose) {
INFO("\t[ND] - took %e sec \t%e sec", cpu_timer.elapsed(), run_timer.elapsed()); INFO("\t[ND] - took %e sec \t%e sec", cpu_timer.elapsed(), run_timer.elapsed());
} }
// applying the nested dissection reordering // applying the nested dissection reordering
if (verbose) { if (verbose) {
INFO("\t[ND] applying nested dissection permutation to FEM matrix ... "); INFO("\t[ND] applying nested dissection permutation to FEM matrix ... ");
} }
run_timer.start(); run_timer.start();
cpu_timer.start(); cpu_timer.start();
mat.reorderMatrix(op_perm, po_perm); mat.reorderMatrix(op_perm, po_perm);
if (verbose) { if (verbose) {
INFO("\t[ND]: - took %e sec\t%e sec", cpu_timer.elapsed(), run_timer.elapsed()); INFO("\t[ND]: - took %e sec\t%e sec", cpu_timer.elapsed(), run_timer.elapsed());
} }
#ifndef NDEBUG #ifndef NDEBUG
// std::string fname_mat_out(fname_mat.substr(0,fname_mat.length()-4)+"-reordered.bin"); // 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); // std::ofstream os (fname_mat_out.c_str(), std::ios::binary);
// if (os) { // if (os) {
// std::cout << "writing matrix to " << fname_mat_out << " ... " << std::flush; // std::cout << "writing matrix to " << fname_mat_out << " ... " << std::flush;
// CS_write(os, n, mat.getRowPtrArray(), mat.getColIdxArray(), mat.getEntryArray()); // CS_write(os, n, mat.getRowPtrArray(), mat.getColIdxArray(), mat.getEntryArray());
// std::cout << "done" << std::endl; // std::cout << "done" << std::endl;
// } // }
#endif #endif
if (verbose) { if (verbose) {
INFO("*** %d matrix vector multiplications (MVM) with Toms amuxCRS ... ", n_mults); INFO("*** %d matrix vector multiplications (MVM) with Toms amuxCRS ... ", n_mults);
} }
run_timer.start(); run_timer.start();
cpu_timer.start(); cpu_timer.start();
for (std::size_t k(0); k<n_mults; k++) { for (std::size_t k(0); k<n_mults; k++) {
mat.amux (1.0, x, y); mat.amux (1.0, x, y);
} }
if (verbose) { if (verbose) {
INFO("\t[MVM] - took %e sec\t %e sec", cpu_timer.elapsed(), run_timer.elapsed()); INFO("\t[MVM] - took %e sec\t %e sec", cpu_timer.elapsed(), run_timer.elapsed());
} }
delete [] x; delete [] x;
delete [] y; delete [] y;
delete custom_format; delete custom_format;
delete logogCout; delete logogCout;
LOGOG_SHUTDOWN(); LOGOG_SHUTDOWN();
return 0; return 0;
} }
...@@ -42,156 +42,156 @@ int main(int argc, char *argv[]) ...@@ -42,156 +42,156 @@ int main(int argc, char *argv[])
static_assert(false, "This code must be compiled with _OPENMP macro enabled."); static_assert(false, "This code must be compiled with _OPENMP macro enabled.");
#endif #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. // 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, // A value arg defines a flag and a type of value that it expects,
// such as "-m matrix". // 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"); 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 // Add the argument matrix_arg to the CmdLine object. The CmdLine object
// uses this Arg to parse the command line. // uses this Arg to parse the command line.
cmd.add( matrix_arg ); cmd.add( matrix_arg );
TCLAP::ValueArg<unsigned> n_cores_arg("p", "number-cores", "number of cores to use", true, 1, "number of cores"); TCLAP::ValueArg<unsigned> n_cores_arg("p", "number-cores", "number of cores to use", true, 1, "number of cores");
cmd.add( n_cores_arg ); 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"); 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 ); cmd.add( n_mults_arg );
TCLAP::ValueArg<std::string> output_arg("o", "output", "output file", false, "", "string"); TCLAP::ValueArg<std::string> output_arg("o", "output", "output file", false, "", "string");
cmd.add( output_arg ); cmd.add( output_arg );
TCLAP::ValueArg<bool> verbosity_arg("v", "verbose", "level of verbosity [0 very low information, 1 much information]", false, 0, "string"); 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.add( verbosity_arg );
cmd.parse( argc, argv ); cmd.parse( argc, argv );
// read the number of multiplication to execute // read the number of multiplication to execute
unsigned n_mults (n_mults_arg.getValue()); unsigned n_mults (n_mults_arg.getValue());
std::string fname_mat (matrix_arg.getValue()); std::string fname_mat (matrix_arg.getValue());
bool verbose (verbosity_arg.getValue()); bool verbose (verbosity_arg.getValue());
BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter); BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter);
logog::Cout *logogCout(new logog::Cout); logog::Cout *logogCout(new logog::Cout);
logogCout->SetFormatter(*custom_format); logogCout->SetFormatter(*custom_format);
// read number of threads // read number of threads
unsigned n_threads (n_cores_arg.getValue()); unsigned n_threads (n_cores_arg.getValue());
INFO("%s was build with compiler %s", INFO("%s was build with compiler %s",
argv[0], argv[0],
BaseLib::BuildInfo::cmake_cxx_compiler.c_str()); BaseLib::BuildInfo::cmake_cxx_compiler.c_str());
#ifdef NDEBUG #ifdef NDEBUG
INFO("CXX_FLAGS: %s %s", INFO("CXX_FLAGS: %s %s",
BaseLib::BuildInfo::cmake_cxx_flags.c_str(), BaseLib::BuildInfo::cmake_cxx_flags.c_str(),
BaseLib::BuildInfo::cmake_cxx_flags_release.c_str()); BaseLib::BuildInfo::cmake_cxx_flags_release.c_str());
#else #else
INFO("CXX_FLAGS: %s %s", INFO("CXX_FLAGS: %s %s",
BaseLib::BuildInfo::cmake_cxx_flags.c_str(), BaseLib::BuildInfo::cmake_cxx_flags.c_str(),
BaseLib::BuildInfo::cmake_cxx_flags_debug.c_str()); BaseLib::BuildInfo::cmake_cxx_flags_debug.c_str());
#endif #endif
#ifdef UNIX #ifdef UNIX
const std::size_t length(256); const std::size_t length(256);
char *hostname(new char[length]); char *hostname(new char[length]);
gethostname (hostname, length); gethostname (hostname, length);
INFO("hostname: %s", hostname); INFO("hostname: %s", hostname);
delete [] hostname; delete [] hostname;
#endif #endif
// *** reading matrix in crs format from file // *** reading matrix in crs format from file
std::ifstream in(fname_mat.c_str(), std::ios::in | std::ios::binary); std::ifstream in(fname_mat.c_str(), std::ios::in | std::ios::binary);
double *A(NULL); double *A(NULL);
unsigned *iA(NULL), *jA(NULL), n; unsigned *iA(NULL), *jA(NULL), n;
if (in) { if (in) {
if (verbose) { if (verbose) {
INFO("reading matrix from %s ...", fname_mat.c_str()); INFO("reading matrix from %s ...", fname_mat.c_str());
} }
BaseLib::RunTime timer; BaseLib::RunTime timer;
timer.start(); timer.start();
CS_read(in, n, iA, jA, A); CS_read(in, n, iA, jA, A);
if (verbose) { if (verbose) {
INFO("\t- took %e s", timer.elapsed()); INFO("\t- took %e s", timer.elapsed());
} }
} else { } else {
ERR("error reading matrix from %s", fname_mat.c_str()); ERR("error reading matrix from %s", fname_mat.c_str());
return -1; return -1;
} }
unsigned nnz(iA[n]); unsigned nnz(iA[n]);
if (verbose) { if (verbose) {
INFO("\tParameters read: n=%d, nnz=%d", n, nnz); INFO("\tParameters read: n=%d, nnz=%d", n, nnz);
} }
#ifdef _OPENMP #ifdef _OPENMP
omp_set_num_threads(n_threads); omp_set_num_threads(n_threads);
MathLib::CRSMatrixReorderedOpenMP mat(n, iA, jA, A); MathLib::CRSMatrixReorderedOpenMP mat(n, iA, jA, A);
#else #else
delete [] iA; delete [] iA;
delete [] jA; delete [] jA;
delete [] A; delete [] A;
ERROR("program is not using OpenMP"); ERROR("program is not using OpenMP");
return -1; return -1;
#endif #endif
double *x(new double[n]); double *x(new double[n]);
double *y(new double[n]); double *y(new double[n]);
for (unsigned k(0); k<n; ++k) for (unsigned k(0); k<n; ++k)
x[k] = 1.0; x[k] = 1.0;
// create time measurement objects // create time measurement objects
BaseLib::RunTime run_timer; BaseLib::RunTime run_timer;
BaseLib::CPUTime cpu_timer; BaseLib::CPUTime cpu_timer;
// calculate the nested dissection reordering // calculate the nested dissection reordering
if (verbose) { if (verbose) {
INFO("*** calculating nested dissection (ND) permutation of matrix ..."); INFO("*** calculating nested dissection (ND) permutation of matrix ...");
} }
run_timer.start(); run_timer.start();
cpu_timer.start(); cpu_timer.start();
MathLib::Cluster cluster_tree(n, iA, jA); MathLib::Cluster cluster_tree(n, iA, jA);
unsigned *op_perm(new unsigned[n]); unsigned *op_perm(new unsigned[n]);
unsigned *po_perm(new unsigned[n]); unsigned *po_perm(new unsigned[n]);
for (unsigned k(0); k<n; k++) for (unsigned k(0); k<n; k++)
op_perm[k] = po_perm[k] = k; op_perm[k] = po_perm[k] = k;
cluster_tree.createClusterTree(op_perm, po_perm, 1000); cluster_tree.createClusterTree(op_perm, po_perm, 1000);
if (verbose) { if (verbose) {
INFO("\t[ND] - took %e sec \t%e sec", cpu_timer.elapsed(), run_timer.elapsed()); INFO("\t[ND] - took %e sec \t%e sec", cpu_timer.elapsed(), run_timer.elapsed());
} }
// applying the nested dissection reordering // applying the nested dissection reordering
if (verbose) { if (verbose) {
INFO("\t[ND] applying nested dissection permutation to FEM matrix ... "); INFO("\t[ND] applying nested dissection permutation to FEM matrix ... ");
} }
run_timer.start(); run_timer.start();
cpu_timer.start(); cpu_timer.start();
mat.reorderMatrix(op_perm, po_perm); mat.reorderMatrix(op_perm, po_perm);
if (verbose) { if (verbose) {
INFO("\t[ND]: - took %e sec\t%e sec", cpu_timer.elapsed(), run_timer.elapsed()); INFO("\t[ND]: - took %e sec\t%e sec", cpu_timer.elapsed(), run_timer.elapsed());
} }
if (verbose) { if (verbose) {
INFO("*** %d matrix vector multiplications (MVM) with Toms amuxCRS (%d threads)... ", n_mults, n_threads); INFO("*** %d matrix vector multiplications (MVM) with Toms amuxCRS (%d threads)... ", n_mults, n_threads);
} }
run_timer.start(); run_timer.start();
cpu_timer.start(); cpu_timer.start();
for (std::size_t k(0); k<n_mults; k++) { for (std::size_t k(0); k<n_mults; k++) {
mat.amux (1.0, x, y); mat.amux (1.0, x, y);
} }
if (verbose) { if (verbose) {
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 [] x;
delete [] y; delete [] y;
delete custom_format; delete custom_format;
delete logogCout; delete logogCout;
LOGOG_SHUTDOWN(); LOGOG_SHUTDOWN();
return 0; return 0;
} }
...@@ -38,115 +38,115 @@ ...@@ -38,115 +38,115 @@
int main(int argc, char *argv[]) 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. // 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, // A value arg defines a flag and a type of value that it expects,
// such as "-m matrix". // such as "-m matrix".
TCLAP::ValueArg<std::string> matrix_arg("m", "matrix", "input matrix file", true, "", "string"); 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 // Add the argument mesh_arg to the CmdLine object. The CmdLine object
// uses this Arg to parse the command line. // uses this Arg to parse the command line.
cmd.add( matrix_arg ); cmd.add( matrix_arg );
TCLAP::ValueArg<unsigned> n_cores_arg("p", "number-cores", "number of cores to use", false, 1, "number"); TCLAP::ValueArg<unsigned> n_cores_arg("p", "number-cores", "number of cores to use", false, 1, "number");
cmd.add( n_cores_arg ); cmd.add( n_cores_arg );
TCLAP::ValueArg<unsigned> n_mults_arg("n", "number-of-multiplications", "number of multiplications to perform", true, 10, "number"); TCLAP::ValueArg<unsigned> n_mults_arg("n", "number-of-multiplications", "number of multiplications to perform", true, 10, "number");
cmd.add( n_mults_arg ); cmd.add( n_mults_arg );
TCLAP::ValueArg<std::string> output_arg("o", "output", "output file", false, "", "string"); TCLAP::ValueArg<std::string> output_arg("o", "output", "output file", false, "", "string");
cmd.add( output_arg ); cmd.add( output_arg );
TCLAP::ValueArg<bool> verbosity_arg("v", "verbose", "level of verbosity [0 very low information, 1 much information]", false, 0, "string"); 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.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); BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter);
logog::Cout *logogCout(new logog::Cout); logog::Cout *logogCout(new logog::Cout);
logogCout->SetFormatter(*custom_format); logogCout->SetFormatter(*custom_format);
logog::LogFile *logog_file(nullptr); logog::LogFile *logog_file(nullptr);
if (! output_arg.getValue().empty()) { if (! output_arg.getValue().empty()) {
logog_file = new logog::LogFile(output_arg.getValue().c_str()); logog_file = new logog::LogFile(output_arg.getValue().c_str());
logog_file->SetFormatter( *custom_format ); logog_file->SetFormatter( *custom_format );
} }
INFO("%s was build with compiler %s", INFO("%s was build with compiler %s",
argv[0], argv[0],
BaseLib::BuildInfo::cmake_cxx_compiler.c_str()); BaseLib::BuildInfo::cmake_cxx_compiler.c_str());
#ifdef NDEBUG #ifdef NDEBUG
INFO("CXX_FLAGS: %s %s", INFO("CXX_FLAGS: %s %s",
BaseLib::BuildInfo::cmake_cxx_flags.c_str(), BaseLib::BuildInfo::cmake_cxx_flags.c_str(),
BaseLib::BuildInfo::cmake_cxx_flags_release.c_str()); BaseLib::BuildInfo::cmake_cxx_flags_release.c_str());
#else #else
INFO("CXX_FLAGS: %s %s", INFO("CXX_FLAGS: %s %s",
BaseLib::BuildInfo::cmake_cxx_flags.c_str(), BaseLib::BuildInfo::cmake_cxx_flags.c_str(),
BaseLib::BuildInfo::cmake_cxx_flags_debug.c_str()); BaseLib::BuildInfo::cmake_cxx_flags_debug.c_str());
#endif #endif
#ifdef UNIX #ifdef UNIX
const int max_host_name_len (255); const int max_host_name_len (255);
char *hostname(new char[max_host_name_len]); char *hostname(new char[max_host_name_len]);
if (gethostname(hostname, max_host_name_len) == 0) if (gethostname(hostname, max_host_name_len) == 0)
INFO("hostname: %s", hostname); INFO("hostname: %s", hostname);
delete [] host_name_len; delete [] host_name_len;
#endif #endif
// *** reading matrix in crs format from file // *** reading matrix in crs format from file
std::ifstream in(fname_mat.c_str(), std::ios::in | std::ios::binary); std::ifstream in(fname_mat.c_str(), std::ios::in | std::ios::binary);
double *A(NULL); double *A(NULL);
unsigned *iA(NULL), *jA(NULL), n; unsigned *iA(NULL), *jA(NULL), n;
if (in) { if (in) {
INFO("reading matrix from %s ...", fname_mat.c_str()); INFO("reading matrix from %s ...", fname_mat.c_str());
BaseLib::RunTime timer; BaseLib::RunTime timer;
timer.start(); timer.start();
CS_read(in, n, iA, jA, A); CS_read(in, n, iA, jA, A);
INFO("\t- took %e s", timer.elapsed()); INFO("\t- took %e s", timer.elapsed());
} else { } else {
INFO("error reading matrix from %s", fname_mat.c_str()); INFO("error reading matrix from %s", fname_mat.c_str());
return -1; return -1;
} }
unsigned nnz(iA[n]); unsigned nnz(iA[n]);
INFO("\tParameters read: n=%d, nnz=%d", n, nnz); INFO("\tParameters read: n=%d, nnz=%d", n, nnz);
#ifdef HAVE_PTHREADS #ifdef HAVE_PTHREADS
unsigned n_threads(n_cores_arg.getValue()); unsigned n_threads(n_cores_arg.getValue());
MathLib::CRSMatrixPThreads<double> mat (n, iA, jA, A, n_threads); MathLib::CRSMatrixPThreads<double> mat (n, iA, jA, A, n_threads);
double *x(new double[n]); double *x(new double[n]);
double *y(new double[n]); double *y(new double[n]);
for (unsigned k(0); k<n; ++k) for (unsigned k(0); k<n; ++k)
x[k] = 1.0; x[k] = 1.0;
// read the number of multiplication to execute // read the number of multiplication to execute
unsigned n_mults (n_mults_arg.getValue()); unsigned n_mults (n_mults_arg.getValue());
INFO("*** %d matrix vector multiplications (MVM) with Toms amuxCRS (%d threads) ...", n_mults, n_threads); INFO("*** %d matrix vector multiplications (MVM) with Toms amuxCRS (%d threads) ...", n_mults, n_threads);
BaseLib::RunTime run_timer; BaseLib::RunTime run_timer;
BaseLib::CPUTime cpu_timer; BaseLib::CPUTime cpu_timer;
run_timer.start(); run_timer.start();
cpu_timer.start(); cpu_timer.start();
for (std::size_t k(0); k<n_mults; k++) { for (std::size_t k(0); k<n_mults; k++) {
mat.amux (1.0, x, y); 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 [] x;
delete [] y; delete [] y;
#endif #endif
delete custom_format; delete custom_format;
delete logogCout; delete logogCout;
delete logog_file; delete logog_file;
LOGOG_SHUTDOWN(); LOGOG_SHUTDOWN();
return 0; return 0;
} }
# Create the executable # Create the executable
add_executable(MeshRead add_executable(MeshRead
MeshRead.cpp MeshRead.cpp
${SOURCES} ${SOURCES}
${HEADERS} ${HEADERS}
) )
target_link_libraries(MeshRead target_link_libraries(MeshRead
MeshLib MeshLib
FileIO FileIO
MathLib MathLib
BaseLib BaseLib
GeoLib GeoLib
${BOOST_LIBRARIES} ${BOOST_LIBRARIES}
) )
# Create MeshSearchTest executable # Create MeshSearchTest executable
add_executable(MeshSearchTest add_executable(MeshSearchTest
MeshSearchTest.cpp MeshSearchTest.cpp
${SOURCES} ${SOURCES}
${HEADERS} ${HEADERS}
) )
target_link_libraries(MeshSearchTest target_link_libraries(MeshSearchTest
MeshLib MeshLib
FileIO FileIO
MathLib MathLib
BaseLib BaseLib
GeoLib GeoLib
${BOOST_LIBRARIES} ${BOOST_LIBRARIES}
) )
add_executable(test_node_partitioned_mesh add_executable(test_node_partitioned_mesh
NodePartitionedMeshTester.cpp NodePartitionedMeshTester.cpp
) )
target_link_libraries(test_node_partitioned_mesh target_link_libraries(test_node_partitioned_mesh
MeshLib MeshLib
FileIO FileIO
${ADDITIONAL_LIBS} ${ADDITIONAL_LIBS}
${BOOST_LIBRARIES} ${BOOST_LIBRARIES}
) )
if(OGS_USE_PETSC) if(OGS_USE_PETSC)
target_link_libraries(test_node_partitioned_mesh ${PETSC_LIBRARIES}) target_link_libraries(test_node_partitioned_mesh ${PETSC_LIBRARIES})
endif() endif()
if(OGS_USE_MPI) 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() endif()
AddTest( AddTest(
NAME NodePartitionedMeshTestASCII NAME NodePartitionedMeshTestASCII
PATH NodePartitionedMesh/ASCII PATH NodePartitionedMesh/ASCII
EXECUTABLE test_node_partitioned_mesh EXECUTABLE test_node_partitioned_mesh
EXECUTABLE_ARGS mesh_3d ${Data_BINARY_DIR}/NodePartitionedMesh/ASCII EXECUTABLE_ARGS mesh_3d ${Data_BINARY_DIR}/NodePartitionedMesh/ASCII
WRAPPER mpirun WRAPPER mpirun
WRAPPER_ARGS -np 3 WRAPPER_ARGS -np 3
TESTER diff TESTER diff
DIFF_DATA mesh_3d_partition_0.msh mesh_3d_partition_1.msh mesh_3d_partition_2.msh DIFF_DATA mesh_3d_partition_0.msh mesh_3d_partition_1.msh mesh_3d_partition_2.msh
) )
AddTest( AddTest(
NAME NodePartitionedMeshTestBinary NAME NodePartitionedMeshTestBinary
PATH NodePartitionedMesh/Binary PATH NodePartitionedMesh/Binary
EXECUTABLE test_node_partitioned_mesh EXECUTABLE test_node_partitioned_mesh
EXECUTABLE_ARGS mesh_3d ${Data_BINARY_DIR}/NodePartitionedMesh/Binary EXECUTABLE_ARGS mesh_3d ${Data_BINARY_DIR}/NodePartitionedMesh/Binary
WRAPPER mpirun WRAPPER mpirun
WRAPPER_ARGS -np 3 WRAPPER_ARGS -np 3
TESTER diff TESTER diff
DIFF_DATA mesh_3d_partition_0.msh mesh_3d_partition_1.msh mesh_3d_partition_2.msh DIFF_DATA mesh_3d_partition_0.msh mesh_3d_partition_1.msh mesh_3d_partition_2.msh
) )
...@@ -30,57 +30,57 @@ ...@@ -30,57 +30,57 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
LOGOG_INITIALIZE(); LOGOG_INITIALIZE();
BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter); BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter);
logog::Cout *logogCout(new logog::Cout); logog::Cout *logogCout(new logog::Cout);
logogCout->SetFormatter(*custom_format); 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. // 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, // A value arg defines a flag and a type of value that it expects,
// such as "-m meshfile". // such as "-m meshfile".
TCLAP::ValueArg<std::string> mesh_arg("m","mesh","input mesh file",true,"homer","string"); 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 // Add the argument mesh_arg to the CmdLine object. The CmdLine object
// uses this Arg to parse the command line. // uses this Arg to parse the command line.
cmd.add( mesh_arg ); 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 #ifndef WIN32
BaseLib::MemWatch mem_watch; BaseLib::MemWatch mem_watch;
unsigned long mem_without_mesh (mem_watch.getVirtMemUsage()); unsigned long mem_without_mesh (mem_watch.getVirtMemUsage());
#endif #endif
BaseLib::RunTime run_time; BaseLib::RunTime run_time;
run_time.start(); run_time.start();
MeshLib::Mesh* mesh = MeshLib::IO::readMeshFromFile(fname); MeshLib::Mesh* mesh = MeshLib::IO::readMeshFromFile(fname);
#ifndef WIN32 #ifndef WIN32
unsigned long mem_with_mesh (mem_watch.getVirtMemUsage()); unsigned long mem_with_mesh (mem_watch.getVirtMemUsage());
// std::cout << "mem for mesh: " << (mem_with_mesh - mem_without_mesh)/(1024*1024) << " MB" << std::endl; // 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)); INFO ("mem for mesh: %i MB", (mem_with_mesh - mem_without_mesh)/(1024*1024));
#endif #endif
// std::cout << "time for reading: " << run_time.elapsed() << " s" << std::endl; // std::cout << "time for reading: " << run_time.elapsed() << " s" << std::endl;
INFO ("time for reading: %f s", run_time.elapsed()); INFO ("time for reading: %f s", run_time.elapsed());
/* /*
unsigned elem_id = 25000; unsigned elem_id = 25000;
const MeshLib::Element* e = mesh->getElement(elem_id); const MeshLib::Element* e = mesh->getElement(elem_id);
const std::size_t nElems = mesh->getNElements(); const std::size_t nElems = mesh->getNElements();
for (unsigned i=0; i< e->getNNeighbors(); i++) for (unsigned i=0; i< e->getNNeighbors(); i++)
{ {
for (unsigned j=0; j< nElems; j++) for (unsigned j=0; j< nElems; j++)
if (mesh->getElement(j) == e->getNeighbor(i)) if (mesh->getElement(j) == e->getNeighbor(i))
std::cout << "neighbour of element " << elem_id << " : " << j << std::endl; std::cout << "neighbour of element " << elem_id << " : " << j << std::endl;
} }
*/ */
delete mesh; delete mesh;
delete logogCout; delete logogCout;
delete custom_format; delete custom_format;
LOGOG_SHUTDOWN(); LOGOG_SHUTDOWN();
} }
...@@ -25,128 +25,128 @@ ...@@ -25,128 +25,128 @@
#include "MeshLib/Mesh.h" #include "MeshLib/Mesh.h"
void testMeshGridAlgorithm(MeshLib::Mesh const*const mesh, void testMeshGridAlgorithm(MeshLib::Mesh const*const mesh,
std::vector<GeoLib::Point*>& pnts_for_search, std::vector<GeoLib::Point*>& pnts_for_search,
std::vector<std::size_t> &idx_found_nodes, bool contiguous) std::vector<std::size_t> &idx_found_nodes, bool contiguous)
{ {
// constructing Grid // constructing Grid
INFO ("[MeshGridAlgorithm] constructing mesh grid object ..."); INFO ("[MeshGridAlgorithm] constructing mesh grid object ...");
if (contiguous) { if (contiguous) {
std::vector<MeshLib::Node> mesh_nodes; std::vector<MeshLib::Node> mesh_nodes;
std::size_t n_nodes(mesh->getNodes().size()); std::size_t n_nodes(mesh->getNodes().size());
mesh_nodes.reserve(n_nodes); mesh_nodes.reserve(n_nodes);
for (std::size_t k(0); k<n_nodes; k++) { for (std::size_t k(0); k<n_nodes; k++) {
mesh_nodes.push_back(MeshLib::Node(*(mesh->getNodes()[k]))); mesh_nodes.push_back(MeshLib::Node(*(mesh->getNodes()[k])));
} }
#ifndef WIN32 #ifndef WIN32
BaseLib::MemWatch mem_watch; BaseLib::MemWatch mem_watch;
unsigned long mem_without_mesh (mem_watch.getVirtMemUsage()); unsigned long mem_without_mesh (mem_watch.getVirtMemUsage());
#endif #endif
clock_t start_grid_construction = clock(); clock_t start_grid_construction = clock();
GeoLib::Grid<MeshLib::Node> mesh_grid(mesh_nodes.begin(), mesh_nodes.end(), 511); GeoLib::Grid<MeshLib::Node> mesh_grid(mesh_nodes.begin(), mesh_nodes.end(), 511);
clock_t end_grid_construction = clock(); clock_t end_grid_construction = clock();
#ifndef WIN32 #ifndef WIN32
unsigned long mem_with_mesh (mem_watch.getVirtMemUsage()); unsigned long mem_with_mesh (mem_watch.getVirtMemUsage());
#endif #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 #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 #endif
const std::size_t n_pnts_for_search(pnts_for_search.size()); const std::size_t n_pnts_for_search(pnts_for_search.size());
INFO ("[MeshGridAlgorithm] searching %d points ...", pnts_for_search.size()); INFO ("[MeshGridAlgorithm] searching %d points ...", pnts_for_search.size());
clock_t start = clock(); clock_t start = clock();
for (std::size_t k(0); k<n_pnts_for_search; k++) { for (std::size_t k(0); k<n_pnts_for_search; k++) {
MeshLib::Node const* node(mesh_grid.getNearestPoint(*(pnts_for_search[k]))); MeshLib::Node const* node(mesh_grid.getNearestPoint(*(pnts_for_search[k])));
idx_found_nodes.push_back(node->getID()); idx_found_nodes.push_back(node->getID());
} }
clock_t stop = clock(); clock_t stop = clock();
INFO("\tdone, search time: %f seconds", (stop-start)/(double)(CLOCKS_PER_SEC)); INFO("\tdone, search time: %f seconds", (stop-start)/(double)(CLOCKS_PER_SEC));
} else { } else {
#ifndef WIN32 #ifndef WIN32
BaseLib::MemWatch mem_watch; BaseLib::MemWatch mem_watch;
unsigned long mem_without_mesh (mem_watch.getVirtMemUsage()); unsigned long mem_without_mesh (mem_watch.getVirtMemUsage());
#endif #endif
clock_t start_grid_construction = clock(); clock_t start_grid_construction = clock();
GeoLib::Grid<MeshLib::Node> mesh_grid(mesh->getNodes().begin(), mesh->getNodes().end(), 511); GeoLib::Grid<MeshLib::Node> mesh_grid(mesh->getNodes().begin(), mesh->getNodes().end(), 511);
clock_t end_grid_construction = clock(); clock_t end_grid_construction = clock();
#ifndef WIN32 #ifndef WIN32
unsigned long mem_with_mesh (mem_watch.getVirtMemUsage()); unsigned long mem_with_mesh (mem_watch.getVirtMemUsage());
#endif #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 #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 #endif
const std::size_t n_pnts_for_search(pnts_for_search.size()); const std::size_t n_pnts_for_search(pnts_for_search.size());
INFO ("[MeshGridAlgorithm] searching %d points ...", pnts_for_search.size()); INFO ("[MeshGridAlgorithm] searching %d points ...", pnts_for_search.size());
clock_t start = clock(); clock_t start = clock();
for (std::size_t k(0); k<n_pnts_for_search; k++) { for (std::size_t k(0); k<n_pnts_for_search; k++) {
MeshLib::Node const* node(mesh_grid.getNearestPoint(*(pnts_for_search[k]))); MeshLib::Node const* node(mesh_grid.getNearestPoint(*(pnts_for_search[k])));
idx_found_nodes.push_back(node->getID()); idx_found_nodes.push_back(node->getID());
} }
clock_t stop = clock(); clock_t stop = clock();
INFO("\tdone, search time: %f seconds", (stop-start)/(double)(CLOCKS_PER_SEC)); INFO("\tdone, search time: %f seconds", (stop-start)/(double)(CLOCKS_PER_SEC));
} }
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
LOGOG_INITIALIZE(); LOGOG_INITIALIZE();
logog::Cout* logog_cout (new logog::Cout); logog::Cout* logog_cout (new logog::Cout);
BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter); BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter);
logog_cout->SetFormatter(*custom_format); 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. // 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, // A value arg defines a flag and a type of value that it expects,
// such as "-m meshfile". // such as "-m meshfile".
TCLAP::ValueArg<std::string> mesh_arg("m","mesh","input mesh file",true,"test.msh","string"); 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 // Add the argument mesh_arg to the CmdLine object. The CmdLine object
// uses this Arg to parse the command line. // uses this Arg to parse the command line.
cmd.add( mesh_arg ); cmd.add( mesh_arg );
TCLAP::ValueArg<unsigned> number_arg("n","number-of-test-points","the number of test points",true,10000,"positive number"); TCLAP::ValueArg<unsigned> number_arg("n","number-of-test-points","the number of test points",true,10000,"positive number");
cmd.add( number_arg ); 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"); 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.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 #ifndef WIN32
BaseLib::MemWatch mem_watch; BaseLib::MemWatch mem_watch;
unsigned long mem_without_mesh (mem_watch.getVirtMemUsage()); unsigned long mem_without_mesh (mem_watch.getVirtMemUsage());
#endif #endif
BaseLib::RunTime run_time; BaseLib::RunTime run_time;
run_time.start(); run_time.start();
MeshLib::Mesh* mesh (mesh_io.loadMeshFromFile(fname)); MeshLib::Mesh* mesh (mesh_io.loadMeshFromFile(fname));
#ifndef WIN32 #ifndef WIN32
unsigned long mem_with_mesh (mem_watch.getVirtMemUsage()); unsigned long mem_with_mesh (mem_watch.getVirtMemUsage());
INFO ("mem for mesh: %i MB", (mem_with_mesh - mem_without_mesh)/(1024*1024)); INFO ("mem for mesh: %i MB", (mem_with_mesh - mem_without_mesh)/(1024*1024));
#endif #endif
INFO ("time for reading: %f s", run_time.elapsed()); INFO ("time for reading: %f s", run_time.elapsed());
// *** preparing test data // *** preparing test data
std::vector<MeshLib::Node*> const& nodes(mesh->getNodes()); std::vector<MeshLib::Node*> const& nodes(mesh->getNodes());
std::vector<GeoLib::Point*> pnts_for_search; std::vector<GeoLib::Point*> pnts_for_search;
unsigned n(std::min(static_cast<unsigned>(nodes.size()), number_arg.getValue())); unsigned n(std::min(static_cast<unsigned>(nodes.size()), number_arg.getValue()));
for (std::size_t k(0); k<n; k++) { for (std::size_t k(0); k<n; k++) {
pnts_for_search.push_back(new GeoLib::Point(*(nodes[k]), k)); pnts_for_search.push_back(new GeoLib::Point(*(nodes[k]), k));
} }
std::vector<std::size_t> idx_found_nodes; std::vector<std::size_t> idx_found_nodes;
testMeshGridAlgorithm(mesh, pnts_for_search, idx_found_nodes, contiguous_arg.getValue()); testMeshGridAlgorithm(mesh, pnts_for_search, idx_found_nodes, contiguous_arg.getValue());
for (std::size_t k(0); k<n; k++) { for (std::size_t k(0); k<n; k++) {
delete pnts_for_search[k]; delete pnts_for_search[k];
} }
delete mesh; delete mesh;
delete custom_format; delete custom_format;
delete logog_cout; delete logog_cout;
LOGOG_SHUTDOWN(); LOGOG_SHUTDOWN();
} }
...@@ -16,68 +16,68 @@ ...@@ -16,68 +16,68 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
if (argc != 4) { if (argc != 4) {
std::cout << "Usage: " << argv[0] << " matrix rhs number-of-threads" << std::endl; std::cout << "Usage: " << argv[0] << " matrix rhs number-of-threads" << std::endl;
return -1; return -1;
} }
// read number of threads // read number of threads
// unsigned num_omp_threads (1); // unsigned num_omp_threads (1);
// num_omp_threads = atoi (argv[3]); // num_omp_threads = atoi (argv[3]);
// *** reading matrix in crs format from file // *** reading matrix in crs format from file
std::string fname(argv[1]); std::string fname(argv[1]);
MathLib::CRSMatrixDiagPrecond *mat (new MathLib::CRSMatrixDiagPrecond(fname)); MathLib::CRSMatrixDiagPrecond *mat (new MathLib::CRSMatrixDiagPrecond(fname));
unsigned n (mat->getNRows()); unsigned n (mat->getNRows());
bool verbose (true); bool verbose (true);
if (verbose) if (verbose)
std::cout << "Parameters read: n=" << n << std::endl; std::cout << "Parameters read: n=" << n << std::endl;
double *x(new double[n]); double *x(new double[n]);
double *b(new double[n]); double *b(new double[n]);
// *** init start vector x // *** init start vector x
for (std::size_t k(0); k<n; k++) { for (std::size_t k(0); k<n; k++) {
x[k] = 1.0; x[k] = 1.0;
} }
// *** read rhs // *** read rhs
fname = argv[2]; fname = argv[2];
std::ifstream in(fname.c_str()); std::ifstream in(fname.c_str());
if (in) { if (in) {
read (in, n, b); read (in, n, b);
in.close(); in.close();
} else { } else {
std::cout << "problem reading rhs - initializing b with 1.0" << std::endl; std::cout << "problem reading rhs - initializing b with 1.0" << std::endl;
for (std::size_t k(0); k<n; k++) { for (std::size_t k(0); k<n; k++) {
b[k] = 1.0; b[k] = 1.0;
} }
} }
if (verbose) if (verbose)
std::cout << "solving system with BiCGStab method (diagonal preconditioner) ... " << std::flush; std::cout << "solving system with BiCGStab method (diagonal preconditioner) ... " << std::flush;
double eps (1.0e-6); double eps (1.0e-6);
unsigned steps (4000); unsigned steps (4000);
BaseLib::RunTime run_timer; BaseLib::RunTime run_timer;
BaseLib::CPUTime cpu_timer; BaseLib::CPUTime cpu_timer;
run_timer.start(); run_timer.start();
cpu_timer.start(); cpu_timer.start();
MathLib::BiCGStab ((*mat), b, x, eps, steps); MathLib::BiCGStab ((*mat), b, x, eps, steps);
if (verbose) { if (verbose) {
std::cout << " in " << steps << " iterations" << std::endl; 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; std::cout << "\t(residuum is " << eps << ") took " << cpu_timer.elapsed() << " sec time and " << run_timer.elapsed() << " sec" << std::endl;
} else { } else {
std::cout << cpu_timer.elapsed() << std::endl; std::cout << cpu_timer.elapsed() << std::endl;
} }
delete mat; delete mat;
delete [] x; delete [] x;
delete [] b; delete [] b;
return 0; return 0;
} }
add_executable(ConjugateGradientUnpreconditioned add_executable(ConjugateGradientUnpreconditioned
ConjugateGradientUnpreconditioned.cpp ConjugateGradientUnpreconditioned.cpp
${SOURCES} ${SOURCES}
${HEADERS} ${HEADERS}
) )
set_target_properties(ConjugateGradientUnpreconditioned PROPERTIES FOLDER SimpleTests) set_target_properties(ConjugateGradientUnpreconditioned PROPERTIES FOLDER SimpleTests)
add_executable(ConjugateGradientDiagPrecond add_executable(ConjugateGradientDiagPrecond
ConjugateGradientDiagonalPreconditioned.cpp ConjugateGradientDiagonalPreconditioned.cpp
${SOURCES} ${SOURCES}
${HEADERS} ${HEADERS}
) )
set_target_properties(ConjugateGradientDiagPrecond PROPERTIES FOLDER SimpleTests) set_target_properties(ConjugateGradientDiagPrecond PROPERTIES FOLDER SimpleTests)
add_executable(BiCGStabDiagPrecond add_executable(BiCGStabDiagPrecond
BiCGStabDiagPrecond.cpp BiCGStabDiagPrecond.cpp
${SOURCES} ${SOURCES}
${HEADERS} ${HEADERS}
) )
set_target_properties(BiCGStabDiagPrecond PROPERTIES FOLDER SimpleTests) set_target_properties(BiCGStabDiagPrecond PROPERTIES FOLDER SimpleTests)
add_executable(GMResDiagPrecond add_executable(GMResDiagPrecond
GMResDiagPrecond.cpp GMResDiagPrecond.cpp
${SOURCES} ${SOURCES}
${HEADERS} ${HEADERS}
) )
set_target_properties(GMResDiagPrecond PROPERTIES FOLDER SimpleTests) set_target_properties(GMResDiagPrecond PROPERTIES FOLDER SimpleTests)
target_link_libraries(ConjugateGradientUnpreconditioned target_link_libraries(ConjugateGradientUnpreconditioned
${BLAS_LIBRARIES} ${BLAS_LIBRARIES}
${LAPACK_LIBRARIES} ${LAPACK_LIBRARIES}
${ADDITIONAL_LIBS} ${ADDITIONAL_LIBS}
MathLib MathLib
BaseLib BaseLib
) )
target_link_libraries(ConjugateGradientDiagPrecond target_link_libraries(ConjugateGradientDiagPrecond
${BLAS_LIBRARIES} ${BLAS_LIBRARIES}
${LAPACK_LIBRARIES} ${LAPACK_LIBRARIES}
${ADDITIONAL_LIBS} ${ADDITIONAL_LIBS}
MathLib MathLib
BaseLib BaseLib
) )
target_link_libraries(BiCGStabDiagPrecond target_link_libraries(BiCGStabDiagPrecond
${BLAS_LIBRARIES} ${BLAS_LIBRARIES}
${LAPACK_LIBRARIES} ${LAPACK_LIBRARIES}
${ADDITIONAL_LIBS} ${ADDITIONAL_LIBS}
MathLib MathLib
BaseLib BaseLib
) )
target_link_libraries(GMResDiagPrecond target_link_libraries(GMResDiagPrecond
${BLAS_LIBRARIES} ${BLAS_LIBRARIES}
${LAPACK_LIBRARIES} ${LAPACK_LIBRARIES}
${ADDITIONAL_LIBS} ${ADDITIONAL_LIBS}
MathLib MathLib
BaseLib BaseLib
) )
...@@ -16,76 +16,76 @@ ...@@ -16,76 +16,76 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
if (argc != 4) { if (argc != 4) {
std::cout << "Usage: " << argv[0] << " matrix rhs number-of-threads" << std::endl; std::cout << "Usage: " << argv[0] << " matrix rhs number-of-threads" << std::endl;
return -1; return -1;
} }
// read number of threads // read number of threads
unsigned num_omp_threads (1); unsigned num_omp_threads (1);
num_omp_threads = atoi (argv[3]); num_omp_threads = atoi (argv[3]);
// *** reading matrix in crs format from file // *** reading matrix in crs format from file
std::string fname(argv[1]); std::string fname(argv[1]);
MathLib::CRSMatrixDiagPrecond *mat (new MathLib::CRSMatrixDiagPrecond(fname)); MathLib::CRSMatrixDiagPrecond *mat (new MathLib::CRSMatrixDiagPrecond(fname));
unsigned n (mat->getNRows()); unsigned n (mat->getNRows());
bool verbose (true); bool verbose (true);
if (verbose) if (verbose)
std::cout << "Parameters read: n=" << n << std::endl; std::cout << "Parameters read: n=" << n << std::endl;
double *x(new double[n]); double *x(new double[n]);
double *b(new double[n]); double *b(new double[n]);
// *** init start vector x // *** init start vector x
for (std::size_t k(0); k<n; k++) { for (std::size_t k(0); k<n; k++) {
x[k] = 0.0; x[k] = 0.0;
} }
// *** read rhs // *** read rhs
fname = argv[2]; fname = argv[2];
std::ifstream in(fname.c_str()); std::ifstream in(fname.c_str());
if (in) { if (in) {
read (in, n, b); read (in, n, b);
in.close(); in.close();
} else { } else {
std::cout << "problem reading rhs - initializing b with 1.0" << std::endl; std::cout << "problem reading rhs - initializing b with 1.0" << std::endl;
for (std::size_t k(0); k<n; k++) { for (std::size_t k(0); k<n; k++) {
b[k] = 1.0; b[k] = 1.0;
} }
} }
if (verbose) if (verbose)
std::cout << "solving system with PCG method (diagonal preconditioner) ... " << std::flush; std::cout << "solving system with PCG method (diagonal preconditioner) ... " << std::flush;
double eps (1.0e-6); double eps (1.0e-6);
unsigned steps (4000); unsigned steps (4000);
BaseLib::RunTime run_timer; BaseLib::RunTime run_timer;
BaseLib::CPUTime cpu_timer; BaseLib::CPUTime cpu_timer;
run_timer.start(); run_timer.start();
cpu_timer.start(); cpu_timer.start();
if (num_omp_threads == 1) { if (num_omp_threads == 1) {
MathLib::CG(mat, b, x, eps, steps); MathLib::CG(mat, b, x, eps, steps);
} else { } else {
#ifdef _OPENMP #ifdef _OPENMP
MathLib::CGParallel(mat, b, x, eps, steps); MathLib::CGParallel(mat, b, x, eps, steps);
#else #else
std::cout << "OpenMP is not switched on" << std::endl; std::cout << "OpenMP is not switched on" << std::endl;
#endif #endif
} }
if (verbose) { if (verbose) {
std::cout << " in " << steps << " iterations" << std::endl; 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; std::cout << "\t(residuum is " << eps << ") took " << cpu_timer.elapsed() << " sec time and " << run_timer.elapsed() << " sec" << std::endl;
} else { } else {
std::cout << cpu_timer.elapsed() << std::endl; std::cout << cpu_timer.elapsed() << std::endl;
} }
delete mat; delete mat;
delete [] x; delete [] x;
delete [] b; delete [] b;
return 0; return 0;
} }
...@@ -11,61 +11,61 @@ ...@@ -11,61 +11,61 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
(void) argc; (void) argc;
(void) argv; (void) argv;
// *** reading matrix in crs format from file // *** reading matrix in crs format from file
std::string fname("/work/Thomas Fischer/data/testmat.bin"); std::string fname("/work/Thomas Fischer/data/testmat.bin");
// std::ifstream in(fname.c_str(), std::ios::binary); // std::ifstream in(fname.c_str(), std::ios::binary);
MathLib::CRSMatrix<double, unsigned> *mat (new MathLib::CRSMatrix<double, unsigned>(fname)); MathLib::CRSMatrix<double, unsigned> *mat (new MathLib::CRSMatrix<double, unsigned>(fname));
/* double *A(NULL); /* double *A(NULL);
unsigned *iA(NULL), *jA(NULL), n; unsigned *iA(NULL), *jA(NULL), n;
if (in) { if (in) {
std::cout << "reading matrix from " << fname << " ... " << std::flush; std::cout << "reading matrix from " << fname << " ... " << std::flush;
CS_read(in, n, iA, jA, A); CS_read(in, n, iA, jA, A);
in.close(); in.close();
std::cout << " ok" << std::endl; std::cout << " ok" << std::endl;
} }
unsigned nnz(iA[n]); unsigned nnz(iA[n]);
*/ */
unsigned n (mat->getNRows()); unsigned n (mat->getNRows());
std::cout << "Parameters read: n=" << n << std::endl; std::cout << "Parameters read: n=" << n << std::endl;
double *x(new double[n]); double *x(new double[n]);
double *b(new double[n]); double *b(new double[n]);
// *** init start vector x // *** init start vector x
for (std::size_t k(0); k<n; k++) { for (std::size_t k(0); k<n; k++) {
x[k] = 1.0; x[k] = 1.0;
} }
// *** read rhs // *** read rhs
fname = "/work/Thomas Fischer/data/rhs.dat"; fname = "/work/Thomas Fischer/data/rhs.dat";
std::ifstream in(fname.c_str()); std::ifstream in(fname.c_str());
if (in) { if (in) {
read (in, n, b); read (in, n, b);
in.close(); in.close();
} else { } else {
std::cout << "problem reading rhs - initializing b with 1.0" << std::endl; std::cout << "problem reading rhs - initializing b with 1.0" << std::endl;
for (std::size_t k(0); k<n; k++) { for (std::size_t k(0); k<n; k++) {
b[k] = 1.0; b[k] = 1.0;
} }
} }
std::cout << "solving system with CG method ... " << std::flush; std::cout << "solving system with CG method ... " << std::flush;
time_t start_time, end_time; time_t start_time, end_time;
time(&start_time); time(&start_time);
// double cg_time (cputime(0.0)); // double cg_time (cputime(0.0));
double eps (1.0e-6); double eps (1.0e-6);
unsigned steps (4000); unsigned steps (4000);
CG (mat, b, x, eps, steps); CG (mat, b, x, eps, steps);
// cg_time = cputime(cg_time); // cg_time = cputime(cg_time);
time(&end_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 << " in " << steps << " iterations (residuum is " << eps << ") took " << /*cg_time <<*/ " sec time and " << (end_time-start_time) << " sec" << std::endl;
delete mat; delete mat;
delete [] x; delete [] x;
delete [] b; delete [] b;
return 0; return 0;
} }
...@@ -23,66 +23,66 @@ ...@@ -23,66 +23,66 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
if (argc != 3) { if (argc != 3) {
std::cout << "Usage: " << argv[0] << " matrix rhs" << std::endl; std::cout << "Usage: " << argv[0] << " matrix rhs" << std::endl;
return -1; return -1;
} }
// *** reading matrix in crs format from file // *** reading matrix in crs format from file
std::string fname(argv[1]); std::string fname(argv[1]);
MathLib::CRSMatrixDiagPrecond *mat(new MathLib::CRSMatrixDiagPrecond(fname)); MathLib::CRSMatrixDiagPrecond *mat(new MathLib::CRSMatrixDiagPrecond(fname));
unsigned n(mat->getNRows()); unsigned n(mat->getNRows());
bool verbose(true); bool verbose(true);
if (verbose) std::cout << "Parameters read: n=" << n << std::endl; if (verbose) std::cout << "Parameters read: n=" << n << std::endl;
double *x(new double[n]); double *x(new double[n]);
double *b(new double[n]); double *b(new double[n]);
// *** init start vector x // *** init start vector x
for (std::size_t k(0); k < n; k++) { for (std::size_t k(0); k < n; k++) {
x[k] = 1.0; x[k] = 1.0;
} }
// *** read rhs // *** read rhs
fname = argv[2]; fname = argv[2];
std::ifstream in(fname.c_str()); std::ifstream in(fname.c_str());
if (in) { if (in) {
read(in, n, b); read(in, n, b);
in.close(); in.close();
} else { } else {
std::cout << "problem reading rhs - initializing b with 1.0" std::cout << "problem reading rhs - initializing b with 1.0"
<< std::endl; << std::endl;
for (std::size_t k(0); k < n; k++) { for (std::size_t k(0); k < n; k++) {
b[k] = 1.0; b[k] = 1.0;
} }
} }
if (verbose) if (verbose)
std::cout << "solving system with GMRes method (diagonal preconditioner) ... " std::cout << "solving system with GMRes method (diagonal preconditioner) ... "
<< std::flush; << std::flush;
double eps(1.0e-6); double eps(1.0e-6);
unsigned steps(4000); unsigned steps(4000);
BaseLib::RunTime run_timer; BaseLib::RunTime run_timer;
BaseLib::CPUTime cpu_timer; BaseLib::CPUTime cpu_timer;
run_timer.start(); run_timer.start();
cpu_timer.start(); cpu_timer.start();
MathLib::GMRes((*mat), b, x, eps, 30, steps); MathLib::GMRes((*mat), b, x, eps, 30, steps);
if (verbose) { if (verbose) {
std::cout << " in " << steps << " iterations" << std::endl; std::cout << " in " << steps << " iterations" << std::endl;
std::cout << "\t(residuum is " << eps << ") took " std::cout << "\t(residuum is " << eps << ") took "
<< cpu_timer.elapsed() << " sec time and " << cpu_timer.elapsed() << " sec time and "
<< run_timer.elapsed() << " sec" << std::endl; << run_timer.elapsed() << " sec" << std::endl;
} else { } else {
std::cout << cpu_timer.elapsed() << std::endl; std::cout << cpu_timer.elapsed() << std::endl;
} }
delete mat; delete mat;
delete[] x; delete[] x;
delete[] b; delete[] b;
return 0; return 0;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment