Skip to content
Snippets Groups Projects
Commit 987a0ff6 authored by Lukas Cejka's avatar Lukas Cejka Committed by Tomáš Oberhuber
Browse files

Implemented for the benchmark to write the output of MatrixReader into the log...

Implemented for the benchmark to write the output of MatrixReader into the log file. BUG: Every other error message added into the Benchmark doesn't have a '!' as a prefix in the log file.
parent 1a798c60
No related branches found
No related tags found
1 merge request!45Matrices revision
...@@ -30,7 +30,7 @@ namespace Benchmarks { ...@@ -30,7 +30,7 @@ namespace Benchmarks {
template< typename Real, typename Device, typename Index > template< typename Real, typename Device, typename Index >
using SlicedEllpack = Matrices::SlicedEllpack< Real, Device, Index >; using SlicedEllpack = Matrices::SlicedEllpack< Real, Device, Index >;
// Get only the name of the format from getType(). // Get only the name of the format from getType()
template< typename Matrix > template< typename Matrix >
std::string getMatrixFormat( const Matrix& matrix ) std::string getMatrixFormat( const Matrix& matrix )
{ {
...@@ -70,44 +70,100 @@ benchmarkSpMV( Benchmark & benchmark, ...@@ -70,44 +70,100 @@ benchmarkSpMV( Benchmark & benchmark,
try try
{ {
// Start a buffer to capture the output of MatrixReader
std::stringstream buffer;
std::streambuf * old = std::cerr.rdbuf(buffer.rdbuf());
if( ! MatrixReader< HostMatrix >::readMtxFile( inputFileName, hostMatrix ) ) if( ! MatrixReader< HostMatrix >::readMtxFile( inputFileName, hostMatrix ) )
{ {
std::cerr << "Failed to read the matrix file " << inputFileName << "." << std::endl; // Capture the original output of MatrixReader, so it isn't printed by console.
std::string errorMsgBuffer = buffer.str();
// Reset the buffer
std::cerr.rdbuf( old );
std::string matrixFormat = getMatrixFormat( hostMatrix ); std::string matrixFormat = getMatrixFormat( hostMatrix );
std::string stringErrorMsg = "Failed to read the matrix file " + //https://stackoverflow.com/questions/5419356/redirect-stdout-stderr-to-a-string
std::stringstream buffer;
std::streambuf * old = std::cerr.rdbuf(buffer.rdbuf());
MatrixReader< HostMatrix >::readMtxFile( inputFileName, hostMatrix );
errorMsgBuffer = buffer.str();
// Reset the buffer
std::cerr.rdbuf( old );
std::string stringErrorMsg = "Benchmark failed: Unable to read the matrix.\n"
"matrix format: " + matrixFormat +
"\nFailed to read the matrix file " +
( std::string )inputFileName + ".\n" + ( std::string )inputFileName + ".\n" +
"matrix format: " + matrixFormat + errorMsgBuffer;
"\nBenchmark failed: Unable to read the matrix.";
//https://stackoverflow.com/questions/1488775/c-remove-new-line-from-multiline-string
if ( ! stringErrorMsg.empty() && stringErrorMsg[ stringErrorMsg.length() - 1 ] == '\n' )
stringErrorMsg.erase( stringErrorMsg.length() - 1 );
// https://stackoverflow.com/questions/7352099/stdstring-to-char
char* errorMsg = &stringErrorMsg[0u];
char *errorMsg = &stringErrorMsg[0u]; // FIXME: Every other benchmark, the errorMsg doesn't have a "!" as
// a prefix in the log file.
// (Try adding more benchmarks in benchmarkSpmvSynthetic(...)
// and you'll see)
benchmark.addErrorMessage( errorMsg, 1 );
std::cout << std::endl;
benchmark.addErrorMessage( errorMsg, 3 );
return false; return false;
} }
std::cerr.rdbuf( old );
} }
catch( std::bad_alloc ) catch( std::bad_alloc )
{ {
std::cerr << "Failed to allocate memory to read the matrix file " << inputFileName << "." << std::endl;
std::string matrixFormat = getMatrixFormat( hostMatrix ); std::string matrixFormat = getMatrixFormat( hostMatrix );
std::string stringErrorMsg = "Failed to allocate memory to read the matrix file " + //https://stackoverflow.com/questions/5419356/redirect-stdout-stderr-to-a-string
( std::string )inputFileName + ".\n" + std::stringstream buffer;
std::streambuf * old = std::cerr.rdbuf(buffer.rdbuf());
MatrixReader< HostMatrix >::readMtxFile( inputFileName, hostMatrix );
std::string errorMsgBuffer = buffer.str();
// Reset the buffer
std::cerr.rdbuf( old );
std::string stringErrorMsg = "Benchmark failed: Not enough memory.\n"
"matrix format: " + matrixFormat + "matrix format: " + matrixFormat +
"\nBenchmark failed: Not enough memory."; "\nFailed to allocate memory to read the matrix file " +
( std::string )inputFileName + ".\n" +
errorMsgBuffer;
//https://stackoverflow.com/questions/1488775/c-remove-new-line-from-multiline-string
if ( ! stringErrorMsg.empty() && stringErrorMsg[ stringErrorMsg.length() - 1 ] == '\n' )
stringErrorMsg.erase( stringErrorMsg.length() - 1 );
// https://stackoverflow.com/questions/7352099/stdstring-to-char
char *errorMsg = &stringErrorMsg[0u]; char *errorMsg = &stringErrorMsg[0u];
benchmark.addErrorMessage( errorMsg, 3 ); // FIXME: Every other benchmark, the errorMsg doesn't have a "!" as
// a prefix in the log file.
// (Try adding more benchmarks in benchmarkSpmvSynthetic(...)
// and you'll see)
benchmark.addErrorMessage( errorMsg, 1 );
std::cout << std::endl;
return false; return false;
} }
// printMatrixInfo is redundant, because all the information is in the Benchmark's MetadataColumns. // printMatrixInfo is redundant, because all the information is in the Benchmark's MetadataColumns
// printMatrixInfo( hostMatrix, std::cout ); // printMatrixInfo( hostMatrix, std::cout );
#ifdef HAVE_CUDA #ifdef HAVE_CUDA
// FIXME: This doesn't work for ChunkedEllpack, because // FIXME: This doesn't work for ChunkedEllpack, because
// its cross-device assignment is not implemented yet. // its cross-device assignment is not implemented yet
deviceMatrix = hostMatrix; deviceMatrix = hostMatrix;
#endif #endif
......
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