Skip to content

Commit

Permalink
Some visual testing
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Feb 23, 2021
1 parent 342f898 commit aa403ca
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
10 changes: 10 additions & 0 deletions include/openPMD/ChunkInfo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,16 @@ namespace chunk_assignment
assign( PartialAssignment, RankMeta const & in, RankMeta const & out )
override;
};

/**
* C++11 doesn't have it and it's useful for some of these.
*/
template< typename T, typename... Args >
std::unique_ptr< T >
make_unique( Args &&... args )
{
return std::unique_ptr< T >( new T( std::forward< Args >( args )... ) );
}
} // namespace chunk_assignment

namespace host_info
Expand Down
5 changes: 5 additions & 0 deletions src/ChunkInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ namespace chunk_assignment
RankMeta const &, // ignored parameter
RankMeta const & out )
{
if( out.size() == 0 )
{
throw std::runtime_error(
"[RoundRobin] Cannot round-robin to zero ranks." );
}
auto it = out.begin();
auto nextRank = [ &it, &out ]() {
if( it == out.end() )
Expand Down
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/Chunk.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( ChunkTable const & table )
{
for( auto const & chunk : table )
{
std::cout << "[Rank: " << chunk.mpi_rank << ",\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.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( 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

0 comments on commit aa403ca

Please sign in to comment.