Skip to content
Snippets Groups Projects
Commit 5a02d5cc authored by Tom Fischer's avatar Tom Fischer
Browse files

[file SimpleTests/MatrixTests/MatVecMultNDPerm.cpp]

- fixed a typo
- print host info under Unix
- fixed some memory leaks

[file SimpleTests/MatrixTests/MatVecMultNDPermOpenMP.cpp]
- added TCLAP and logog to file
- added Copyright and License notice
parent 45a4dac3
No related branches found
No related tags found
No related merge requests found
...@@ -60,6 +60,7 @@ IF (METIS_FOUND) ...@@ -60,6 +60,7 @@ IF (METIS_FOUND)
TARGET_LINK_LIBRARIES ( MatVecMultNDPermOpenMP TARGET_LINK_LIBRARIES ( MatVecMultNDPermOpenMP
BaseLib BaseLib
MathLib MathLib
logog
${METIS_LIBRARIES} ${METIS_LIBRARIES}
${ADDITIONAL_LIBS} ${ADDITIONAL_LIBS}
) )
......
...@@ -13,6 +13,9 @@ ...@@ -13,6 +13,9 @@
#ifdef OGS_BUILD_INFO #ifdef OGS_BUILD_INFO
#include "BuildInfo.h" #include "BuildInfo.h"
#endif
#ifdef UNIX
#include <sys/unistd.h> #include <sys/unistd.h>
#endif #endif
...@@ -56,7 +59,7 @@ int main(int argc, char *argv[]) ...@@ -56,7 +59,7 @@ int main(int argc, char *argv[])
// 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 mesh_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 );
...@@ -90,6 +93,9 @@ int main(int argc, char *argv[]) ...@@ -90,6 +93,9 @@ int main(int argc, char *argv[])
} else { } else {
INFO("CXX_FLAGS: %s %s", CMAKE_CXX_FLAGS, CMAKE_CXX_FLAGS_DEBUG); INFO("CXX_FLAGS: %s %s", CMAKE_CXX_FLAGS, CMAKE_CXX_FLAGS_DEBUG);
} }
#endif
#ifdef UNIX
const size_t length(256); const size_t length(256);
char *hostname(new char[length]); char *hostname(new char[length]);
gethostname (hostname, length); gethostname (hostname, length);
...@@ -192,5 +198,10 @@ int main(int argc, char *argv[]) ...@@ -192,5 +198,10 @@ int main(int argc, char *argv[])
delete [] x; delete [] x;
delete [] y; delete [] y;
delete custom_format;
delete logogCout;
LOGOG_SHUTDOWN();
return 0; return 0;
} }
/** /**
* MatVecMultNDPermOpenMP.cpp * Copyright (c) 2012, OpenGeoSys Community (http://www.opengeosys.net)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.net/LICENSE.txt
*
* \qfile MatVecMultNDPermOpenMP.cpp
* *
* Created on 2012-01-20 by Thomas Fischer * Created on 2012-01-20 by Thomas Fischer
*/ */
...@@ -9,6 +14,11 @@ ...@@ -9,6 +14,11 @@
// BaseLib // BaseLib
#include "RunTime.h" #include "RunTime.h"
#include "CPUTime.h" #include "CPUTime.h"
// BaseLib/tclap
#include "tclap/CmdLine.h"
// BaseLib/logog
#include "logog.hpp"
#include "formatter.hpp"
// MathLib // MathLib
#include "sparse.h" #include "sparse.h"
...@@ -17,20 +27,83 @@ ...@@ -17,20 +27,83 @@
#include "LinAlg/Sparse/NestedDissectionPermutation/CRSMatrixReorderedOpenMP.h" #include "LinAlg/Sparse/NestedDissectionPermutation/CRSMatrixReorderedOpenMP.h"
#include "LinAlg/Sparse/NestedDissectionPermutation/Cluster.h" #include "LinAlg/Sparse/NestedDissectionPermutation/Cluster.h"
#ifdef UNIX
#include <sys/unistd.h>
#endif
#ifdef OGS_BUILD_INFO
#include "BuildInfo.h"
#endif
/**
* new formatter for logog
*/
class FormatterCustom : public logog::FormatterGCC
{
virtual TOPIC_FLAGS GetTopicFlags( const logog::Topic &topic )
{
return ( Formatter::GetTopicFlags( topic ) &
~( TOPIC_FILE_NAME_FLAG | TOPIC_LINE_NUMBER_FLAG ));
}
};
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
if (argc < 4) { LOGOG_INITIALIZE();
std::cout << "Usage: " << argv[0] << " matrix number_of_multiplications resultfile" << std::endl;
return 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");
// 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 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<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 );
cmd.parse( argc, argv );
// read the number of multiplication to execute // read the number of multiplication to execute
unsigned n_mults (0); unsigned n_mults (n_mults_arg.getValue());
n_mults = atoi (argv[2]); std::string fname_mat (matrix_arg.getValue());
bool verbose (verbosity_arg.getValue());
FormatterCustom *custom_format (new FormatterCustom);
logog::Cout *logogCout(new logog::Cout);
logogCout->SetFormatter(*custom_format);
std::string fname_mat (argv[1]); // read number of threads
unsigned n_threads (n_cores_arg.getValue());
bool verbose (true); #ifdef OGS_BUILD_INFO
INFO("%s was build with compiler %s", argv[0], CMAKE_CXX_COMPILER);
if (std::string(CMAKE_BUILD_TYPE).compare("Release") == 0) {
INFO("CXX_FLAGS: %s %s", CMAKE_CXX_FLAGS, CMAKE_CXX_FLAGS_RELEASE);
} else {
INFO("CXX_FLAGS: %s %s", CMAKE_CXX_FLAGS, CMAKE_CXX_FLAGS_DEBUG);
}
#endif
#ifdef UNIX
const 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 // *** 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);
...@@ -38,21 +111,22 @@ int main(int argc, char *argv[]) ...@@ -38,21 +111,22 @@ int main(int argc, char *argv[])
unsigned *iA(NULL), *jA(NULL), n; unsigned *iA(NULL), *jA(NULL), n;
if (in) { if (in) {
if (verbose) { if (verbose) {
std::cout << "reading matrix from " << fname_mat << " ... " << std::flush; 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);
timer.stop(); timer.stop();
if (verbose) { if (verbose) {
std::cout << "ok, [wclock: " << timer.elapsed() << " s]" << std::endl; INFO("\t- took %e s", timer.elapsed());
} }
} else { } else {
std::cout << "error reading matrix from " << fname_mat << std::endl; ERR("error reading matrix from %s", fname_mat.c_str());
return -1;
} }
unsigned nnz(iA[n]); unsigned nnz(iA[n]);
if (verbose) { if (verbose) {
std::cout << "Parameters read: n=" << n << ", nnz=" << nnz << std::endl; INFO("\tParameters read: n=%d, nnz=%d", n, nnz);
} }
MathLib::CRSMatrixReorderedOpenMP mat(n, iA, jA, A); MathLib::CRSMatrixReorderedOpenMP mat(n, iA, jA, A);
...@@ -69,7 +143,7 @@ int main(int argc, char *argv[]) ...@@ -69,7 +143,7 @@ int main(int argc, char *argv[])
// calculate the nested dissection reordering // calculate the nested dissection reordering
if (verbose) { if (verbose) {
std::cout << "calculating nested dissection permutation of matrix ... " << std::flush; INFO("*** calculating nested dissection (ND) permutation of matrix ...");
} }
run_timer.start(); run_timer.start();
cpu_timer.start(); cpu_timer.start();
...@@ -82,45 +156,26 @@ int main(int argc, char *argv[]) ...@@ -82,45 +156,26 @@ int main(int argc, char *argv[])
cpu_timer.stop(); cpu_timer.stop();
run_timer.stop(); run_timer.stop();
if (verbose) { if (verbose) {
std::cout << cpu_timer.elapsed() << "\t" << run_timer.elapsed() << std::endl; INFO("\t[ND] - took %e sec \t%e sec", cpu_timer.elapsed(), run_timer.elapsed());
} else {
if (argc == 4) {
std::ofstream result_os(argv[3], std::ios::app);
if (result_os) {
result_os << cpu_timer.elapsed() << "\t" << run_timer.elapsed() << " calc nested dissection perm" << std::endl;
}
result_os.close();
} else {
std::cout << cpu_timer.elapsed() << "\t" << run_timer.elapsed() << " calc nested dissection perm" << std::endl;
}
} }
// applying the nested dissection reordering // applying the nested dissection reordering
if (verbose) { if (verbose) {
std::cout << "applying nested dissection permutation to FEM matrix ... " << std::flush; 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);
cpu_timer.stop(); cpu_timer.stop();
run_timer.stop(); run_timer.stop();
if (verbose) std::cout << cpu_timer.elapsed() << "\t" << run_timer.elapsed() << std::endl; if (verbose) {
else { INFO("\t[ND]: - took %e sec\t%e sec", cpu_timer.elapsed(), run_timer.elapsed());
if (argc == 4) {
std::ofstream result_os(argv[3], std::ios::app);
if (result_os) {
result_os << cpu_timer.elapsed() << "\t" << run_timer.elapsed() << " applying nested dissection perm" << std::endl;
}
result_os.close();
} else {
std::cout << cpu_timer.elapsed() << "\t" << run_timer.elapsed() << std::endl;
}
} }
if (verbose) { if (verbose) {
std::cout << "matrix vector multiplication with Toms amuxCRS ... " << std::flush; 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 (size_t k(0); k<n_mults; k++) { for (size_t k(0); k<n_mults; k++) {
...@@ -130,22 +185,15 @@ int main(int argc, char *argv[]) ...@@ -130,22 +185,15 @@ int main(int argc, char *argv[])
run_timer.stop(); run_timer.stop();
if (verbose) { if (verbose) {
std::cout << "done [" << cpu_timer.elapsed() << " sec cpu time], [wclock: " INFO("\t[MVM] - took %e sec\t %e sec", cpu_timer.elapsed(), run_timer.elapsed());
<< run_timer.elapsed() << " sec]" << std::endl;
} else {
if (argc == 4) {
std::ofstream result_os (argv[3], std::ios::app);
if (result_os) {
result_os << cpu_timer.elapsed() << "\t" << run_timer.elapsed() << " " << n_mults << " MatVecMults, matrix " << fname_mat << std::endl;
}
result_os.close();
} else {
std::cout << cpu_timer.elapsed() << "\t" << run_timer.elapsed() << std::endl;
}
} }
delete [] x; delete [] x;
delete [] y; delete [] y;
delete custom_format;
delete logogCout;
LOGOG_SHUTDOWN();
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