1#ifndef UTOPIA_MODELS_HDFBENCH_HH
2#define UTOPIA_MODELS_HDFBENCH_HH
14#include <boost/iterator/counting_iterator.hpp>
35 public Model<HdfBenchModel, HdfBenchModelTypes>
50 using Clock = std::chrono::high_resolution_clock;
53 using Time = std::chrono::high_resolution_clock::time_point;
80 std::map<std::string, double>
_times;
88 std::map<std::string, std::shared_ptr<DataSet>>
_dsets;
106 this->
_log->debug(
"Loading benchmark configurations ...");
107 std::map<std::string, Config> cfg;
110 this->
_log->trace(
"Loading benchmark configuration '{}' ...",
116 catch (std::exception &
e) {
117 std::cerr <<
"Could not find a benchmark configuration with "
118 "name '" <<
bname <<
"'! Make sure the given "
119 "configuration contains such an entry."
120 << std::endl <<
"Original error message: ";
125 this->
_log->debug(
"Got {} benchmark configurations.", cfg.size());
141 template<
class ParentModel>
143 const std::string& name,
170 if (_delete_afterwards) {
171 throw std::invalid_argument(
"delete_afterwards feature is not yet "
179 this->
_log->debug(
"Associating setup functions ...");
180 _setup_funcs[
"setup_nd"] =
setup_nd;
184 this->
_log->debug(
"Associating write functions ...");
188 this->
_log->debug(
"Associated {} setup and {} write function(s).",
194 this->
_log->debug(
"initial_write: {}, sleep_step: {}s, "
195 "sleep_bench: {}s", initial_write ?
"yes" :
"no",
198 this->
_log->info(
"Performing setup and initial benchmarks ...");
200 for (
const auto &
bname : _benchmarks) {
213 _dset_times->add_attribute(
"dim_name__1",
"benchmark");
218 this->
_log->debug(
"Finished constructing HdfBench '{}'.", this->
_name);
260 [
this](
const auto&
bname) {
261 return this->_times.at(bname);
271 template<
bool setup=false>
278 if constexpr (
setup) {
289 this->
_log->debug(
"Benchmark result {:>20s} {} : {:>10.3f} ms",
317 const auto start = Clock::now();
322 _dsets[
bname]->set_capacity(shape);
336 const auto start = Clock::now();
356 const auto it_len = std::accumulate(shape.begin(), shape.end(),
357 1, std::multiplies<std::size_t>());
359 const auto start = Clock::now();
363 _dsets[
bname]->write(boost::counting_iterator<std::size_t>(0),
364 boost::counting_iterator<std::size_t>(
it_len),
Base class interface for Models using the CRT Pattern.
Definition model.hh:112
const std::shared_ptr< DataGroup > _hdfgrp
The HDF group this model instance should write its data to.
Definition model.hh:176
Time get_time_max() const
Return the maximum time possible for this model.
Definition model.hh:403
typename ModelTypes::DataSet DataSet
Data type that is used for storing data.
Definition model.hh:125
const Config _cfg
Config node belonging to this model instance.
Definition model.hh:158
const std::string _name
Name of the model instance.
Definition model.hh:149
typename ModelTypes::Config Config
Data type that holds the configuration.
Definition model.hh:116
const std::shared_ptr< spdlog::logger > _log
The (model) logger.
Definition model.hh:164
std::shared_ptr< DataSet > create_dset(const std::string name, const std::shared_ptr< DataGroup > &hdfgrp, std::vector< hsize_t > add_write_shape, const std::size_t compression_level=1, const std::vector< hsize_t > chunksize={})
Create a new dataset within the given group.
Definition model.hh:752
The HdfBench Model.
Definition HdfBench.hh:36
void monitor()
Monitor model information.
Definition HdfBench.hh:249
const std::vector< std::string > _benchmarks
Names of benchmarks.
Definition HdfBench.hh:74
typename Base::DataSet DataSet
Data type for a dataset.
Definition HdfBench.hh:42
std::map< std::string, Config > load_benchmarks()
Load the benchmark configurations into a map.
Definition HdfBench.hh:105
std::map< std::string, double > _times
The results of the measurements, stored under the benchmark name.
Definition HdfBench.hh:80
double time_since(const Time start)
Returns the time (in seconds) since the given time point.
Definition HdfBench.hh:295
std::shared_ptr< DataSet > _dset_times
Dataset to store the write times in.
Definition HdfBench.hh:85
double benchmark(const std::string &bname)
Carries out the benchmark associated with the given name.
Definition HdfBench.hh:272
HdfBenchModel(const std::string &name, ParentModel &parent_model, const DataIO::Config &custom_cfg={})
Construct the HdfBench model.
Definition HdfBench.hh:142
std::function< double(const std::string, Config)> BenchFunc
Type of a benchmark function pointer.
Definition HdfBench.hh:59
Model< HdfBenchModel, HdfBenchModelTypes > Base
The base model type.
Definition HdfBench.hh:39
const std::chrono::duration< double > _sleep_step
Sleep time in seconds at the beginning of each step.
Definition HdfBench.hh:96
std::chrono::high_resolution_clock Clock
Type of clock.
Definition HdfBench.hh:50
std::map< std::string, std::shared_ptr< DataSet > > _dsets
Dataset to write test data to are stored in a map of dataset pointers.
Definition HdfBench.hh:88
void write_data()
Write the result times of each benchmark.
Definition HdfBench.hh:258
double time_between(const Time start, const Time end)
Returns the absolute time (in seconds) between the given time points.
Definition HdfBench.hh:300
typename Base::Config Config
Data type that holds the configuration.
Definition HdfBench.hh:45
std::chrono::duration< double > DurationType
Type of the duration measure, should be a floating-point type.
Definition HdfBench.hh:56
const std::chrono::duration< double > _sleep_bench
Sleep time in seconds before each benchmark.
Definition HdfBench.hh:99
BenchFunc write_const
Writes a constant value into the dataset.
Definition HdfBench.hh:350
const std::map< std::string, Config > _bench_cfgs
Configuration for the benchmarks.
Definition HdfBench.hh:77
BenchFunc setup_nd_with_chunks
Definition HdfBench.hh:329
std::map< std::string, BenchFunc > _write_funcs
A map of implemented write functions.
Definition HdfBench.hh:71
const bool _delete_afterwards
Whether to delete datasets after the last step.
Definition HdfBench.hh:93
std::chrono::high_resolution_clock::time_point Time
Type of a time point, retrieved from the clock.
Definition HdfBench.hh:53
void perform_step()
Iterate a single step.
Definition HdfBench.hh:229
std::map< std::string, BenchFunc > _setup_funcs
A map of implemented setup functions for datasets.
Definition HdfBench.hh:68
BenchFunc setup_nd
Definition HdfBench.hh:312
YAML::Node Config
Type of a variadic dictionary-like data structure used throughout Utopia.
Definition types.hh:71
ReturnType get_as(const std::string &key, const DataIO::Config &node)
This function is a wrapper around the yaml-cpp YAML::Node::as function.
Definition cfg_utils.hh:158
Container select_entities(const Manager &mngr, const DataIO::Config &sel_cfg)
Select entities according to parameters specified in a configuration.
Definition select.hh:213
Definition parallel.hh:235
Wrapper struct for defining model class data types.
Definition model.hh:92