24 #include "openPMD/config.hpp"
27 #include "RandomDatasetFiller.hpp"
29 #include "openPMD/openPMD.hpp"
30 #include "openPMD/DatatypeHelpers.hpp"
31 #include "openPMD/benchmark/mpi/MPIBenchmarkReport.hpp"
32 #include "openPMD/benchmark/mpi/DatasetFiller.hpp"
33 #include "openPMD/benchmark/mpi/BlockSlicer.hpp"
56 template<
typename DatasetFillerProv
ider >
61 using extentT = Extent::value_type;
62 MPI_Comm communicator = MPI_COMM_WORLD;
69 std::shared_ptr< BlockSlicer > m_blockSlicer;
71 DatasetFillerProvider m_dfp;
91 std::shared_ptr< BlockSlicer > blockSlicer,
92 DatasetFillerProvider dfp,
93 MPI_Comm comm = MPI_COMM_WORLD
107 std::string compression,
108 uint8_t compressionLevel,
111 typename decltype( Series::iterations )::key_type iterations,
127 std::string compression,
128 uint8_t compressionLevel,
131 typename decltype( Series::iterations)::key_type iterations
134 void resetConfigurations( );
145 template<
typename Clock >
151 std::string m_basePath;
159 typename decltype( Series::iterations)::key_type>>
183 template<
typename Clock >
184 struct BenchmarkExecution
190 m_benchmark { benchmark }
209 typename Clock::duration writeBenchmark(
210 std::string
const & compression,
214 std::string
const & extension,
215 std::shared_ptr< DatasetFiller< T >> datasetFiller,
216 typename decltype( Series::iterations)::key_type iterations
231 typename Clock::duration readBenchmark(
234 std::string extension,
235 typename decltype( Series::iterations)::key_type iterations
238 template<
typename T >
240 MPIBenchmarkReport< typename Clock::duration > & report,
247 MPIBenchmarkReport< typename Clock::duration > &,
260 template<
typename DatasetFillerProv
ider >
261 template<
typename Clock >
262 MPIBenchmarkReport< typename Clock::duration >
268 BenchmarkExecution< Clock > exec {
this };
270 std::set< Datatype > datatypes;
271 for(
auto const & conf: m_configurations )
273 datatypes.insert( std::get< DTYPE >( conf ) );
289 template<
typename DatasetFillerProv
ider >
291 std::string basePath,
293 std::shared_ptr< BlockSlicer > blockSlicer,
294 DatasetFillerProvider dfp,
297 communicator { comm },
298 totalExtent { std::move( tExtent ) },
299 m_blockSlicer { std::move( blockSlicer ) },
301 m_basePath { std::move( basePath ) }
303 if( m_blockSlicer ==
nullptr )
304 throw std::runtime_error(
"Argument blockSlicer cannot be a nullptr!");
308 template<
typename DatasetFillerProv
ider >
312 > MPIBenchmark< DatasetFillerProvider >::slice(
int size )
336 template<
typename DatasetFillerProv
ider >
338 std::string compression,
339 uint8_t compressionLevel,
342 typename decltype( Series::iterations)::key_type iterations,
346 this->m_configurations
358 template<
typename DatasetFillerProv
ider >
360 std::string compression,
361 uint8_t compressionLevel,
364 typename decltype( Series::iterations)::key_type iterations
383 template<
typename DatasetFillerProv
ider >
391 template<
typename DatasetFillerProv
ider >
392 template<
typename Clock >
393 template<
typename T >
394 typename Clock::duration
395 MPIBenchmark< DatasetFillerProvider >::BenchmarkExecution< Clock >::writeBenchmark(
396 std::string
const & compression,
400 std::string
const & extension,
401 std::shared_ptr< DatasetFiller< T >> datasetFiller,
402 typename decltype( Series::iterations)::key_type iterations
405 MPI_Barrier( m_benchmark->communicator );
406 auto start = Clock::now( );
409 Series series = Series(
410 m_benchmark->m_basePath +
"." + extension,
412 m_benchmark->communicator
415 for(
typename decltype( Series::iterations)::key_type i = 0;
419 auto writeData = datasetFiller->produceData( );
424 series.iterations[i].meshes[
"id"][MeshRecordComponent::SCALAR];
426 Datatype datatype = determineDatatype( writeData );
427 Dataset dataset = Dataset(
431 if( !compression.empty( ) )
433 dataset.setCompression(
439 id.resetDataset( dataset );
451 MPI_Barrier( m_benchmark->communicator );
452 auto end = Clock::now( );
455 for(
typename decltype( Series::iterations)::key_type i = 0;
459 datasetFiller->produceData( );
461 auto deduct = Clock::now( );
463 return end - start - ( deduct - end );
467 template<
typename DatasetFillerProv
ider >
468 template<
typename Clock >
469 template<
typename T >
470 typename Clock::duration
471 MPIBenchmark< DatasetFillerProvider >::BenchmarkExecution< Clock >::readBenchmark(
474 std::string extension,
475 typename decltype( Series::iterations)::key_type iterations
478 MPI_Barrier( m_benchmark->communicator );
480 auto start = Clock::now( );
482 Series series = Series(
483 m_benchmark->m_basePath +
"." + extension,
485 m_benchmark->communicator
488 for(
typename decltype( Series::iterations)::key_type i = 0;
494 series.iterations[i].meshes[
"id"][MeshRecordComponent::SCALAR];
497 auto chunk_data =
id.loadChunk<
T >(
504 MPI_Barrier( m_benchmark->communicator );
505 auto end = Clock::now( );
510 template<
typename DatasetFillerProv
ider >
511 template<
typename Clock >
512 template<
typename T >
514 MPIBenchmark< DatasetFillerProvider >::BenchmarkExecution< Clock >::operator()(
515 MPIBenchmarkReport< typename Clock::duration > & report,
519 Datatype dt = determineDatatype< T >( );
520 auto dsf = std::dynamic_pointer_cast< DatasetFiller< T>>(
525 for(
auto const & config: m_benchmark->m_configurations )
527 std::string compression;
528 uint8_t compressionLevel;
532 typename decltype( Series::iterations)::key_type iterations;
547 auto localCuboid = m_benchmark->slice( size );
549 extentT blockSize = 1;
550 for(
auto ext: localCuboid.second )
554 dsf->setNumberOfItems( blockSize );
556 auto writeTime = writeBenchmark< T >(
565 auto readTime = readBenchmark< T >(
589 template<
typename DatasetFillerProv
ider >
590 template<
typename Clock >
593 MPIBenchmark< DatasetFillerProvider >::BenchmarkExecution< Clock >::operator()(
594 MPIBenchmarkReport< typename Clock::duration > &,
598 throw std::runtime_error(
"Unknown/unsupported datatype requested to be benchmarked." );