Runtime Configuration
Configuration values can be read and changed at runtime using dash::util::Config
. It is capable of parsing configuration values from various human-readable formats to standardized representations.
Some Examples:
export FOO_ENABLED=on
export ANOTHER_FLAG=false
export HAS_WOMBATS=yes
export USE_CHAINSAW=0
export OVERKILL_BUFF_SIZE=4mb
export STARS_IN_SKY_SIZE=2K
Environment variables are loaded automatically during dash::init
.
bool foo_enabled = dash::util::Config::get("FOO_ENABLED");
bool another_flag = dash::util::Config::get("ANOTHER_FLAG");
// Configuration values can be set using any data type that supports
// operator<<(std::ostream, T):
dash::util::Config::set("HAS_WOMBATS", true);
// Configuration entries can be overwritten by values of different
// type ...
dash::util::Config::set("HAS_WOMBATS", 12.34);
// ... and converted to any specified type when read:
double has_wombats = dash::util::Config::get<double>("HAS_WOMBATS");
// --> 12.34
size_t has_wombats = dash::util::Config::get<size_t>("HAS_WOMBATS");
// --> 12
// If a configuration key has suffix "_SIZE" and its value
// containins an SI unit, an additional configuration entry
// with suffix "_SIZE_BYTES" is defined automatically:
std::string dash::util::Config::get("OVERKILL_BUFF_SIZE");
// --> "4mb"
size_t dash::util::Config::get("OVERKILL_BUFF_SIZE_BYTES");
// --> 4194304
size_t dash::util::Config::get("STARS_IN_SKY_SIZE_BYTES");
// --> 2048
As changes to the DASH configuration have local effect, defining unit-specific configurations is straightforward:
// Enable logging for units 0, 2, 4, ...
if (dash::myid() % 2) {
dash::util::Config::set("DASH_ENABLE_LOGGING", true);
} else {
dash::util::Config::set("DASH_ENABLE_LOGGING", false);
}