Skip to content
Snippets Groups Projects
Commit 2a83efd7 authored by Gregor Weiss's avatar Gregor Weiss
Browse files

ENH: reading and data in file tests for MPI IO

parent d429b2da
No related merge requests found
......@@ -54,22 +54,20 @@ void IOmpiLevel0::read( const int step,
std::vector<double>& buffer,
const Settings& s,
MPI_Comm comm ) {
// We avoid extending the IO interface by a file pointer reset functionality
// by restoring the file pointer when reading the first time step.
// Definitly violates SRP.
if ( step == 0 )
{
// Set initial rank-related offset
MPI_Offset offset = _rank * _buffercount * sizeof( double );
MPI_File_seek( _filehandle, offset, MPI_SEEK_SET );
}
_outputfilename = MakeFilename( s.outputfile, ".mpiio_write", -1, step );
// Open file and set initial rank-related offset
MPI_File_open( comm,
_outputfilename.c_str(),
MPI_MODE_RDONLY,
MPI_INFO_NULL,
&_filehandle );
MPI_Offset offset = _rank * _buffercount * sizeof( double );
MPI_File_seek( _filehandle, offset, MPI_SEEK_SET );
MPI_File_read( _filehandle, buffer.data(), _buffercount, MPI_DOUBLE, MPI_STATUS_IGNORE);
// Set file pointer to next time step. Assumes sequentiell reads!
// Prevents MPI_Offset overflow.
MPI_Offset offset = ( _nprocs - 1 ) * _buffercount * sizeof( double );
MPI_File_seek( _filehandle, offset, MPI_SEEK_CUR );
MPI_File_close( &_filehandle );
}
void IOmpiLevel0::remove( const int step ) {
......
......@@ -108,7 +108,28 @@ void IOmpiLevel3::read( const int step,
std::vector<double>& buffer,
const Settings& s,
MPI_Comm comm ) {
MPI_File_read_all( _filehandle, buffer.data(), _buffercount, MPI_DOUBLE, MPI_STATUS_IGNORE);
_outputfilename = MakeFilename( s.outputfile, ".mpiio_write_all", -1, step );
// Open file and set file view
MPI_File filehandle_onestep;
MPI_File_open( comm,
_outputfilename.c_str(),
MPI_MODE_RDONLY,
MPI_INFO_NULL,
&filehandle_onestep );
MPI_File_set_view( filehandle_onestep,
0,
MPI_DOUBLE,
_fileview._filetype,
"native",
MPI_INFO_NULL);
MPI_File_read_all( filehandle_onestep,
buffer.data(),
_buffercount,
MPI_DOUBLE,
MPI_STATUS_IGNORE);
MPI_File_close( &filehandle_onestep );
}
void IOmpiLevel3::remove( const int step ) {
......
......@@ -107,18 +107,24 @@ int main( int argc, char* argv[] ) {
settings.format.compare( "adios2" ) == 0
||
settings.format.compare( "binary" ) == 0
||
settings.format.compare( "level0" ) == 0
||
settings.format.compare( "level3" ) == 0
)
{
IO<IOVariant> istream( settings, MPI_COMM_WORLD);
istream.chooseFormat( settings.format );
std::vector<double> input_buffer( settings.ndx * settings.ndy, -1.0 );
istream.read( t, input_buffer, settings, MPI_COMM_WORLD );
bool equal = std::equal( std::begin( input_buffer ),
std::end( input_buffer ),
std::begin( ht.data_noghost() ) );
if ( !equal ) {
std::cout << "WARNING: read data is not equal to written data" << std::endl;
}
IO<IOVariant> istream( settings, MPI_COMM_WORLD );
istream.chooseFormat( settings.format );
std::vector<double> input_buffer( settings.ndx * settings.ndy, -1.0 );
istream.read( t, input_buffer, settings, MPI_COMM_WORLD );
bool equal = std::equal( std::begin( input_buffer ),
std::end( input_buffer ),
std::begin( ht.data_noghost() ) );
if ( !equal ) {
std::cout << "WARNING: read data is not equal to written data" << std::endl;
}
}
io.remove( t );
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment