Utopia  2
Framework for studying models of complex & adaptive systems.
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
Utopia::Models::HdfBench::HdfBenchModel Class Reference

The HdfBench Model. More...

#include <HdfBench.hh>

Inheritance diagram for Utopia::Models::HdfBench::HdfBenchModel:
Inheritance graph
[legend]
Collaboration diagram for Utopia::Models::HdfBench::HdfBenchModel:
Collaboration graph
[legend]

Public Types

using Base = Model< HdfBenchModel, HdfBenchModelTypes >
 The base model type. More...
 
using DataSet = typename Base::DataSet
 Data type for a dataset. More...
 
using Config = typename Base::Config
 Data type that holds the configuration. More...
 
using Clock = std::chrono::high_resolution_clock
 Type of clock. More...
 
using Time = std::chrono::high_resolution_clock::time_point
 Type of a time point, retrieved from the clock. More...
 
using DurationType = std::chrono::duration< double >
 Type of the duration measure, should be a floating-point type. More...
 
using BenchFunc = std::function< double(const std::string, Config)>
 Type of a benchmark function pointer. More...
 
- Public Types inherited from Utopia::Model< HdfBenchModel, HdfBenchModelTypes >
using Config = typename ModelTypes::Config
 Data type that holds the configuration. More...
 
using DataManager = DataIO::Default::DefaultDataManager< HdfBenchModel >
 The data manager to use, specialized with the derived model. More...
 
using DataGroup = typename ModelTypes::DataGroup
 Data type that is used for storing datasets. More...
 
using DataSet = typename ModelTypes::DataSet
 Data type that is used for storing data. More...
 
using RNG = typename ModelTypes::RNG
 Data type of the shared RNG. More...
 
using Space = typename ModelTypes::Space
 Data type of the space this model resides in. More...
 
using Time = typename ModelTypes::Time
 Data type for the model time. More...
 
using Monitor = typename ModelTypes::Monitor
 Data type for the monitor. More...
 
using MonitorManager = typename ModelTypes::MonitorManager
 Data type for the monitor manager. More...
 
using Level = typename ModelTypes::Level
 Data type for the hierarchical level. More...
 

Public Member Functions

template<class ParentModel >
 HdfBenchModel (const std::string &name, ParentModel &parent_model, const DataIO::Config &custom_cfg={})
 Construct the HdfBench model. More...
 
void perform_step ()
 Iterate a single step. More...
 
void monitor ()
 Monitor model information. More...
 
void write_data ()
 Write the result times of each benchmark. More...
 
- Public Member Functions inherited from Utopia::Model< HdfBenchModel, HdfBenchModelTypes >
 Model (const std::string &name, const ParentModel &parent_model, const Config &custom_cfg={}, std::tuple< WriterArgs... > w_args={}, const DataIO::Default::DefaultDecidermap< HdfBenchModel > &w_deciders=DataIO::Default::default_deciders< HdfBenchModel >, const DataIO::Default::DefaultTriggermap< HdfBenchModel > &w_triggers=DataIO::Default::default_triggers< HdfBenchModel >)
 Constructs a Model instance. More...
 
const std::shared_ptr< Space > & get_space () const
 Return the space this model resides in. More...
 
Time get_time () const
 Return the current time of this model. More...
 
Time get_time_max () const
 Return the maximum time possible for this model. More...
 
Config get_cfg () const
 Return the config node of this model. More...
 
std::string get_name () const
 Return the name of this model instance. More...
 
std::string get_full_name () const
 Return the full name of this model within the model hierarchy. More...
 
std::shared_ptr< DataGroupget_hdfgrp () const
 Return a pointer to the HDF group this model stores data in. More...
 
Time get_write_start () const
 Return the parameter that controls when write_data is called first. More...
 
Time get_write_every () const
 Return the parameter that controls how often write_data is called. More...
 
DataManager get_datamanager () const
 return the datamanager More...
 
hsize_t get_remaining_num_writes () const
 Return the number of remaining write_data calls this model will make. More...
 
std::shared_ptr< RNGget_rng () const
 Return a pointer to the shared RNG. More...
 
std::shared_ptr< spdlog::logger > get_logger () const
 Return a pointer to the logger of this model. More...
 
Monitor get_monitor () const
 Return the monitor of this model. More...
 
std::shared_ptr< MonitorManagerget_monitor_manager () const
 Get the monitor manager of the root model. More...
 
Level get_level () const
 Return the hierarchical level within the model hierarchy. More...
 
virtual void prolog ()
 A function that is called before starting model iteration. More...
 
virtual void epilog ()
 A function that is called after the last iteration of a model. More...
 
void iterate ()
 Iterate one (time) step of this model. More...
 
void run ()
 Run the model from the current time to the maximum time. More...
 
std::shared_ptr< DataSetcreate_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. More...
 
std::shared_ptr< DataSetcreate_dset (const std::string name, const 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 model's base data group. More...
 
std::shared_ptr< DataSetcreate_cm_dset (const std::string name, const CellManager &cm, const std::size_t compression_level=1, const std::vector< hsize_t > chunksize={})
 Create a dataset storing data from a CellManager. More...
 
std::shared_ptr< DataSetcreate_am_dset (const std::string name, const AgentManager &am, const std::size_t compression_level=1, const std::vector< hsize_t > chunksize={})
 Create a dataset storing data from a AgentManager. More...
 

Protected Member Functions

template<bool setup = false>
double benchmark (const std::string &bname)
 Carries out the benchmark associated with the given name. More...
 
double time_since (const Time start)
 Returns the time (in seconds) since the given time point. More...
 
double time_between (const Time start, const Time end)
 Returns the absolute time (in seconds) between the given time points. More...
 
- Protected Member Functions inherited from Utopia::Model< HdfBenchModel, HdfBenchModelTypes >
void __perform_step ()
 Perform the computation of a step. More...
 
void __monitor ()
 Monitor information in the terminal. More...
 
void __write_data ()
 Write data; calls the implementation's write_data method. More...
 
void __write_initial_state ()
 Write the initial state. More...
 
void increment_time (const Time dt=1)
 Increment time. More...
 
void __prolog ()
 The default prolog of a model. More...
 
void __epilog ()
 The default epilog of a model. More...
 
HdfBenchModel & impl ()
 cast to the derived class More...
 
const HdfBenchModel & impl () const
 const cast to the derived interface More...
 

Protected Attributes

BenchFunc setup_nd
 
BenchFunc setup_nd_with_chunks
 
BenchFunc write_const
 Writes a constant value into the dataset. More...
 
- Protected Attributes inherited from Utopia::Model< HdfBenchModel, HdfBenchModelTypes >
const std::string _name
 Name of the model instance. More...
 
const std::string _full_name
 The full name within the model hierarchy. More...
 
const Level _level
 The level within the model hierarchy. More...
 
const Config _cfg
 Config node belonging to this model instance. More...
 
const std::shared_ptr< RNG_rng
 The RNG shared between models. More...
 
const std::shared_ptr< spdlog::logger > _log
 The (model) logger. More...
 
std::shared_ptr< Space_space
 The space this model resides in. More...
 
Time _time
 Model-internal current time stamp. More...
 
const Time _time_max
 Model-internal maximum time stamp. More...
 
const std::shared_ptr< DataGroup_hdfgrp
 The HDF group this model instance should write its data to. More...
 
const Time _write_start
 First time at which write_data is called. More...
 
const Time _write_every
 How often to call write_data from iterate. More...
 
Monitor _monitor
 The monitor. More...
 
DataManager _datamanager
 Manager object for handling data output; see DataManager. More...
 

Private Member Functions

std::map< std::string, Configload_benchmarks ()
 Load the benchmark configurations into a map. More...
 

Private Attributes

std::map< std::string, BenchFunc_setup_funcs
 A map of implemented setup functions for datasets. More...
 
std::map< std::string, BenchFunc_write_funcs
 A map of implemented write functions. More...
 
const std::vector< std::string > _benchmarks
 Names of benchmarks. More...
 
const std::map< std::string, Config_bench_cfgs
 Configuration for the benchmarks. More...
 
std::map< std::string, double > _times
 The results of the measurements, stored under the benchmark name. More...
 
std::shared_ptr< DataSet_dset_times
 Dataset to store the write times in. More...
 
std::map< std::string, std::shared_ptr< DataSet > > _dsets
 Dataset to write test data to are stored in a map of dataset pointers. More...
 
const bool _delete_afterwards
 Whether to delete datasets after the last step. More...
 
const std::chrono::duration< double > _sleep_step
 Sleep time in seconds at the beginning of each step. More...
 
const std::chrono::duration< double > _sleep_bench
 Sleep time in seconds before each benchmark. More...
 

Additional Inherited Members

- Static Protected Attributes inherited from Utopia::Model< HdfBenchModel, HdfBenchModelTypes >
static constexpr WriteMode _write_mode
 Which data-writing mode the base model should use. More...
 

Detailed Description

The HdfBench Model.

This model implements a benchmark of Utopia's Hdf5 writing capabilities.

It does not implement a manager or a grid but focusses on benchmarking the write times, given iterable data.

Member Typedef Documentation

◆ Base

The base model type.

◆ BenchFunc

using Utopia::Models::HdfBench::HdfBenchModel::BenchFunc = std::function<double(const std::string, Config)>

Type of a benchmark function pointer.

◆ Clock

using Utopia::Models::HdfBench::HdfBenchModel::Clock = std::chrono::high_resolution_clock

Type of clock.

◆ Config

Data type that holds the configuration.

◆ DataSet

Data type for a dataset.

◆ DurationType

using Utopia::Models::HdfBench::HdfBenchModel::DurationType = std::chrono::duration<double>

Type of the duration measure, should be a floating-point type.

◆ Time

using Utopia::Models::HdfBench::HdfBenchModel::Time = std::chrono::high_resolution_clock::time_point

Type of a time point, retrieved from the clock.

Constructor & Destructor Documentation

◆ HdfBenchModel()

template<class ParentModel >
Utopia::Models::HdfBench::HdfBenchModel::HdfBenchModel ( const std::string &  name,
ParentModel &  parent_model,
const DataIO::Config custom_cfg = {} 
)
inline

Construct the HdfBench model.

This model aims to allow benchmarking of the Utopia Hdf5 library in a setting that is close to the actual use case, i.e.: as means for storing model output.

Parameters
nameName of this model instance
parent_modelThe parent model this model instance resides in
custom_cfgA custom configuration to use instead of the one extracted from the parent model using the instance name

Member Function Documentation

◆ benchmark()

template<bool setup = false>
double Utopia::Models::HdfBench::HdfBenchModel::benchmark ( const std::string &  bname)
inlineprotected

Carries out the benchmark associated with the given name.

◆ load_benchmarks()

std::map<std::string, Config> Utopia::Models::HdfBench::HdfBenchModel::load_benchmarks ( )
inlineprivate

Load the benchmark configurations into a map.

◆ monitor()

void Utopia::Models::HdfBench::HdfBenchModel::monitor ( )
inline

Monitor model information.

Here, functions and values can be supplied to the monitor that are then available to the frontend. The monitor() function is only called if a certain emit interval has passed; thus, the performance hit is small.

◆ perform_step()

void Utopia::Models::HdfBench::HdfBenchModel::perform_step ( )
inline

Iterate a single step.

The "iteration" in this model is the step that creates the data that is written in the write_data method, i.e.: it carries out the benchmarks and stores the corresponding times in the _times member, to be written out in write_data

◆ time_between()

double Utopia::Models::HdfBench::HdfBenchModel::time_between ( const Time  start,
const Time  end 
)
inlineprotected

Returns the absolute time (in seconds) between the given time points.

◆ time_since()

double Utopia::Models::HdfBench::HdfBenchModel::time_since ( const Time  start)
inlineprotected

Returns the time (in seconds) since the given time point.

◆ write_data()

void Utopia::Models::HdfBench::HdfBenchModel::write_data ( )
inline

Write the result times of each benchmark.

Member Data Documentation

◆ _bench_cfgs

const std::map<std::string, Config> Utopia::Models::HdfBench::HdfBenchModel::_bench_cfgs
private

Configuration for the benchmarks.

◆ _benchmarks

const std::vector<std::string> Utopia::Models::HdfBench::HdfBenchModel::_benchmarks
private

Names of benchmarks.

◆ _delete_afterwards

const bool Utopia::Models::HdfBench::HdfBenchModel::_delete_afterwards
private

Whether to delete datasets after the last step.

◆ _dset_times

std::shared_ptr<DataSet> Utopia::Models::HdfBench::HdfBenchModel::_dset_times
private

Dataset to store the write times in.

◆ _dsets

std::map<std::string, std::shared_ptr<DataSet> > Utopia::Models::HdfBench::HdfBenchModel::_dsets
private

Dataset to write test data to are stored in a map of dataset pointers.

◆ _setup_funcs

std::map<std::string, BenchFunc> Utopia::Models::HdfBench::HdfBenchModel::_setup_funcs
private

A map of implemented setup functions for datasets.

◆ _sleep_bench

const std::chrono::duration<double> Utopia::Models::HdfBench::HdfBenchModel::_sleep_bench
private

Sleep time in seconds before each benchmark.

◆ _sleep_step

const std::chrono::duration<double> Utopia::Models::HdfBench::HdfBenchModel::_sleep_step
private

Sleep time in seconds at the beginning of each step.

◆ _times

std::map<std::string, double> Utopia::Models::HdfBench::HdfBenchModel::_times
private

The results of the measurements, stored under the benchmark name.

◆ _write_funcs

std::map<std::string, BenchFunc> Utopia::Models::HdfBench::HdfBenchModel::_write_funcs
private

A map of implemented write functions.

◆ setup_nd

BenchFunc Utopia::Models::HdfBench::HdfBenchModel::setup_nd
protected
Initial value:
= [this](const auto& bname, auto cfg){
auto shape = get_as<std::vector<hsize_t>>("write_shape", cfg);
shape.insert(shape.begin(), this->get_time_max() + 1);
const auto start = Clock::now();
_dsets[bname] = this->_hdfgrp->open_dataset(bname);
_dsets[bname]->set_capacity(shape);
return time_since(start);
}
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
double time_since(const Time start)
Returns the time (in seconds) since the given time point.
Definition: HdfBench.hh:295
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

◆ setup_nd_with_chunks

BenchFunc Utopia::Models::HdfBench::HdfBenchModel::setup_nd_with_chunks
protected
Initial value:
= [this](const auto& bname, auto cfg){
const auto time_setup = this->setup_nd(bname, cfg);
const auto chunks = get_as<std::vector<hsize_t>>("chunks", cfg);
const auto start = Clock::now();
_dsets[bname]->set_chunksize(chunks);
return time_setup + time_since(start);
}
BenchFunc setup_nd
Definition: HdfBench.hh:312

◆ write_const

BenchFunc Utopia::Models::HdfBench::HdfBenchModel::write_const
protected
Initial value:
= [this](const auto& bname, auto cfg){
const auto val = get_as<double>("const_val", cfg);
const auto shape = get_as<std::vector<std::size_t>>("write_shape", cfg);
const auto it_len = std::accumulate(shape.begin(), shape.end(),
1, std::multiplies<std::size_t>());
const auto start = Clock::now();
_dsets[bname]->write(boost::counting_iterator<std::size_t>(0),
boost::counting_iterator<std::size_t>(it_len),
[&val]([[maybe_unused]] auto &count){
return val;
});
return time_since(start);
}

Writes a constant value into the dataset.


The documentation for this class was generated from the following file: