Skip to content

Commit

Permalink
Testing (only printf testing for now)
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Mar 9, 2021
1 parent b4fbfc1 commit 8c7fc78
Show file tree
Hide file tree
Showing 2 changed files with 218 additions and 1 deletion.
69 changes: 69 additions & 0 deletions test/CoreTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# define OPENPMD_private public
# define OPENPMD_protected public
#endif

#include "openPMD/ChunkInfo.hpp"
#include "openPMD/openPMD.hpp"

#include <catch2/catch.hpp>
Expand All @@ -19,11 +21,78 @@

using namespace openPMD;

namespace test_chunk_assignment
{
using namespace openPMD::chunk_assignment;
struct Params
{
ChunkTable table;
RankMeta metaSource;
RankMeta metaSink;

void
init(
size_t sourceRanks,
size_t sinkRanks,
size_t in_per_host,
size_t out_per_host )
{
for( size_t rank = 0; rank < sourceRanks; ++rank )
{
table.emplace_back(
Offset{ rank, rank }, Extent{ rank, rank }, rank );
table.emplace_back(
Offset{ rank, 100 * rank }, Extent{ rank, 100 * rank }, rank );
metaSource.emplace( rank, std::to_string( rank / in_per_host ) );
}
for( size_t rank = 0; rank < sinkRanks; ++rank )
{
metaSink.emplace( rank, std::to_string( rank / out_per_host ) );
}
}
};
void print( RankMeta const & meta, ChunkTable const & table )
{
for( auto const & chunk : table )
{
std::cout << "[HOST: " << meta.at( chunk.sourceID )
<< ",\tRank: " << chunk.sourceID << ",\tOffset: ";
for( auto offset : chunk.offset )
{
std::cout << offset << ", ";
}
std::cout << "\tExtent: ";
for( auto extent : chunk.extent )
{
std::cout << extent << ", ";
}
std::cout << "]" << std::endl;
}
}
} // namespace test_chunk_assignment

TEST_CASE( "chunk_assignment", "[core]" )
{
using namespace chunk_assignment;
test_chunk_assignment::Params params;
params.init( 6, 2, 2, 1 );
test_chunk_assignment::print( params.metaSource, params.table );
ByHostname byHostname( make_unique< RoundRobin >() );
FromPartialStrategy fullStrategy(
make_unique< ByHostname >( std::move( byHostname ) ),
make_unique< BinPacking >() );
ChunkTable res = assignChunks(
params.table, params.metaSource, params.metaSink, fullStrategy );
std::cout << "\nRESULTS:" << std::endl;
test_chunk_assignment::print( params.metaSink, res );
}

TEST_CASE( "versions_test", "[core]" )
{
auto const apiVersion = getVersion( );
REQUIRE(2u == std::count_if(apiVersion.begin(), apiVersion.end(), []( char const c ){ return c == '.';}));


auto const standard = getStandard( );
REQUIRE(standard == "1.1.0");

Expand Down
150 changes: 149 additions & 1 deletion test/ParallelIOTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "openPMD/auxiliary/Environment.hpp"
#include "openPMD/auxiliary/Filesystem.hpp"
#include "openPMD/openPMD.hpp"
// @todo change includes
#include "openPMD/benchmark/mpi/OneDimensionalBlockSlicer.hpp"
#include <catch2/catch.hpp>

#if openPMD_HAVE_MPI
Expand Down Expand Up @@ -1108,4 +1110,150 @@ TEST_CASE( "adios2_ssc", "[parallel][adios2]" )
{
adios2_ssc();
}
#endif

void adios2_chunk_distribution()
{
int mpi_size{ -1 };
int mpi_rank{ -1 };
MPI_Comm_size( MPI_COMM_WORLD, &mpi_size );
MPI_Comm_rank( MPI_COMM_WORLD, &mpi_rank );

chunk_assignment::RankMeta writingRanksHostnames, readingRanksHostnames;
for( int i = 0; i < mpi_size; ++i )
{
// 0, 0, 1, 1, 2, 2, 3, 3 ...
writingRanksHostnames[ i ] = "node" + std::to_string( i / 2 );
// 0, 0, 0, 0, 2, 2, 2, 2 ...
readingRanksHostnames[ i ] = "node" + std::to_string( i / 4 * 2 );
}

std::string filename = "../samples/adios2_chunk_distribution.bp";
// simulate a stream
std::stringstream parameters;
parameters << R"END(
{
"adios2":
{
"engine":
{
"type": "bp4",
"parameters":
{
"NumAggregators":)END"
<< "\"" << std::to_string( mpi_size ) << "\""
<< R"END(
}
}
}
}
)END";

auto printAssignment = [ mpi_rank ](
std::string const & strategyName,
ChunkTable const & table,
chunk_assignment::RankMeta const & meta )
{
if( mpi_rank != 0 )
{
return;
}
std::cout << "WITH STRATEGY '" << strategyName << "':\n";
for( auto const & chunk : table )
{
std::cout << "[HOST: " << meta.at( chunk.sourceID )
<< ",\tRank: " << chunk.sourceID << ",\tOffset: ";
for( auto offset : chunk.offset )
{
std::cout << offset << ", ";
}
std::cout << "\tExtent: ";
for( auto extent : chunk.extent )
{
std::cout << extent << ", ";
}
std::cout << "]" << std::endl;
}
};

{
Series series(
filename,
openPMD::Access::CREATE,
MPI_COMM_WORLD,
parameters.str() );
series.setMpiRanksMetaInfo( writingRanksHostnames.at( mpi_rank ) );

auto E_x = series.iterations[ 0 ].meshes[ "E" ][ "x" ];
openPMD::Dataset ds(
openPMD::Datatype::INT, { unsigned( mpi_size ), 10 } );
E_x.resetDataset( ds );
std::vector< int > data( 10, 0 );
std::iota( data.begin(), data.end(), 0 );
E_x.storeChunk( data, { unsigned( mpi_rank ), 0 }, { 1, 10 } );
series.flush();
}

{
Series series( filename, openPMD::Access::READ_ONLY, MPI_COMM_WORLD );
auto rankMetaIn = series.mpiRanksMetaInfo();
REQUIRE( rankMetaIn == writingRanksHostnames );

auto E_x = series.iterations[ 0 ].meshes[ "E" ][ "x" ];
auto const chunkTable = E_x.availableChunks();

printAssignment( "INPUT", chunkTable, rankMetaIn );

using namespace chunk_assignment;

RoundRobin roundRobinStrategy;
auto roundRobinAssignment = assignChunks(
chunkTable, rankMetaIn, readingRanksHostnames, roundRobinStrategy );
printAssignment(
"ROUND ROBIN", roundRobinAssignment, readingRanksHostnames );

ByHostname byHostname(
std::make_unique< BinPacking >( /* splitAlongDimension = */ 1 ) );
auto byHostnamePartialAssignment = assignChunks(
chunkTable, rankMetaIn, readingRanksHostnames, byHostname );
printAssignment(
"HOSTNAME, ASSIGNED",
byHostnamePartialAssignment.assigned,
readingRanksHostnames );
printAssignment(
"HOSTNAME, LEFTOVER",
byHostnamePartialAssignment.notAssigned,
rankMetaIn );

FromPartialStrategy fromPartialStrategy(
std::make_unique< ByHostname >( std::move( byHostname ) ),
std::make_unique< BinPacking >( /* splitAlongDimension = */ 1 ) );
auto fromPartialAssignment = assignChunks(
chunkTable,
rankMetaIn,
readingRanksHostnames,
fromPartialStrategy );
printAssignment(
"HOSTNAME WITH SECOND PASS",
fromPartialAssignment,
readingRanksHostnames );

ByCuboidSlice cuboidSliceStrategy(
std::make_unique< OneDimensionalBlockSlicer >( 1 ),
E_x.getExtent(),
mpi_rank,
mpi_size );
auto cuboidSliceAssignment = assignChunks(
chunkTable,
rankMetaIn,
readingRanksHostnames,
cuboidSliceStrategy );
printAssignment(
"CUBOID SLICE", cuboidSliceAssignment, readingRanksHostnames );
}
}

TEST_CASE( "adios2_chunk_distribution", "[parallel][adios2]" )
{
adios2_chunk_distribution();
}
#endif // openPMD_HAVE_ADIOS2 && openPMD_HAVE_MPI

0 comments on commit 8c7fc78

Please sign in to comment.