diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..fc9dee7620bad7a0b4a2d32b06f3af71f509881e --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,11 @@ +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 diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..001454c1086cdf31074bdfc35059f5dc2a6c3611 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,8 @@ +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) diff --git a/adios2-variable-problem.cpp b/adios2-variable-problem.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1bee245469d29ebfe7e6d3a9513f2bfbc4d34988 --- /dev/null +++ b/adios2-variable-problem.cpp @@ -0,0 +1,75 @@ +#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(); + +}