Skip to content
Snippets Groups Projects
Commit 802c8f26 authored by Dominik Thoennes's avatar Dominik Thoennes
Browse files

add minimal example

parent 0e5132cf
No related branches found
No related tags found
No related merge requests found
Pipeline #56186 failed
test
image: i10git.cs.fau.de:5005/walberla/buildenvs/gcc-12
script:
- spack env activate /opt/spack-environment/
- spack load adios2
- mkdir build
- cd build
- cmake ..
- make
- mpirun --oversubscribe -n 8 ./adios2mini 20000
- bpls checkpoint.bp | wc -l
cmake_minimum_required(VERSION 3.12)
project(Adios2Minimal CXX C)
find_package(MPI REQUIRED)
find_package(ADIOS2 REQUIRED)
add_executable(adios2mini adios2-variable-problem.cpp)
target_link_libraries(adios2mini PRIVATE adios2::cxx11_mpi)
#include <iostream>
#include <iomanip>
#include <mpi.h>
#include <adios2.h>
std::string createVariable( adios2::IO& io, int counter, int rank, long unsigned int bufferSize ) {
std::stringstream sStream;
sStream << "Var-" << std::setfill('0') << std::setw(3) << counter << std::setw(3) << "_Rank-" << rank;
adios2::Variable< double > var = io.DefineVariable< double >( sStream.str(), {}, {}, {bufferSize} );
return sStream.str();
}
int main( int argc, char ** argv ) {
std::string outFile = "./checkpoint.bp";
// -----------
// MPI setup
// -----------
MPI_Init( &argc, &argv );
int commSize;
int commRank;
MPI_Comm_size( MPI_COMM_WORLD, &commSize );
MPI_Comm_rank( MPI_COMM_WORLD, &commRank );
if( commRank == 0 ) {
std::cout << "Executing test with " << commSize << " MPI processes" << std::endl;
}
// determine number of variables to create
if( argc != 2 ) {
MPI_Abort( MPI_COMM_WORLD, -1 );
}
int numVarTotal = atoi( argv[1] );
int numVarLocal = numVarTotal / commSize;
if( commRank == 0 ) {
std::cout << "Total variables asked for = " << numVarTotal << std::endl;
std::cout << "Local variables to create = " << numVarLocal << std::endl;
numVarLocal += numVarTotal - numVarLocal * commSize;
}
// -------------
// ADIOS setup
// -------------
adios2::ADIOS adios( MPI_COMM_WORLD );
adios2::IO output = adios.DeclareIO( "Writer" );
output.SetEngine( "BP5" );
adios2::Engine writer = output.Open( outFile, adios2::Mode::Write );
int counter = 0;
unsigned long int bufferSize = 100u;
std::vector< double > buffer( bufferSize, 2.0 );
for( int k = 1; k <= numVarLocal; ++k ) {
double* address = buffer.data();
std::string var = createVariable( output, counter++, commRank, bufferSize );
writer.Put< double >( var, address );
}
int numVariables = counter;
MPI_Reduce( &counter, &numVariables, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD );
if( commRank == 0 ) {
std::cout << "Total variables created = " << numVariables << std::endl;
}
// ----------
// Shutdown
// ----------
writer.Close();
MPI_Finalize();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment