Utopia 2
Framework for studying models of complex & adaptive systems.
Loading...
Searching...
No Matches
Public Types | Static Public Member Functions | Static Private Member Functions | Static Private Attributes | List of all members
Utopia::ParallelExecution Class Reference

Static information on the status of parallel execution. More...

#include <parallel.hh>

Public Types

enum  Setting { enabled , disabled }
 Possible settings for parallel execution. More...
 

Static Public Member Functions

static void init (const DataIO::Config &cfg)
 Initialize parallel features based on configuration setting.
 
static void set (const Setting value)
 Choose a setting for parallel execution at runtime.
 
static bool is_enabled ()
 Query if parallel execution is currently enabled.
 
static bool is_applied ()
 Actually check if parallel features are applied at runtime.
 

Static Private Member Functions

static std::shared_ptr< spdlog::logger > get_logger ()
 Fetch the core logger.
 

Static Private Attributes

static bool _enabled = false
 Runtime setting for parallel execution.
 

Detailed Description

Static information on the status of parallel execution.

Note
Using this class requires the Utopia core logger to be set up, which can conveniently done by calling Utopia::setup_loggers().

Member Enumeration Documentation

◆ Setting

Possible settings for parallel execution.

Enumerator
enabled 

Enable parallel execution.

disabled 

Disable parallel execution.

102 {
103 enabled,
104 disabled
105 };
@ enabled
Enable parallel execution.
Definition parallel.hh:103
@ disabled
Disable parallel execution.
Definition parallel.hh:104

Member Function Documentation

◆ get_logger()

static std::shared_ptr< spdlog::logger > Utopia::ParallelExecution::get_logger ( )
inlinestaticprivate

Fetch the core logger.

Returns
Valid shared pointer to the logger
Exceptions
runtime_errorIf logger does not exist
89 {
90 const auto log = spdlog::get(Utopia::log_core);
91 if (not log)
92 {
93 throw std::runtime_error("Cannot fetch core logger!");
94 }
95
96 return log;
97 }
Container select_entities(const Manager &mngr, const DataIO::Config &sel_cfg)
Select entities according to parameters specified in a configuration.
Definition select.hh:213
const std::string log_core
Definition logging.hh:18

◆ init()

static void Utopia::ParallelExecution::init ( const DataIO::Config cfg)
inlinestatic

Initialize parallel features based on configuration setting.

Parameters
cfgParameter space config node
Note
If the required parameter is not found, parallel features are disabled by default.
114 {
115 bool setting = false;
116
117 // Try fetching settings on parallel execution
118 if (const YAML::Node& cfg_par = cfg["parallel_execution"])
119 {
120 setting = get_as<bool>("enabled", cfg_par);
121 }
122
123 if (setting)
125 else
127 }
static void set(const Setting value)
Choose a setting for parallel execution at runtime.
Definition parallel.hh:135

◆ is_applied()

static bool Utopia::ParallelExecution::is_applied ( )
inlinestatic

Actually check if parallel features are applied at runtime.

Note
This method is implemented for testing purposes only and should not be used to change model or algorithm behavior!
168 {
169#ifdef UTOPIA_PARALLEL
170 return _enabled;
171#else
172 return false;
173#endif
174 }
static bool _enabled
Runtime setting for parallel execution.
Definition parallel.hh:81

◆ is_enabled()

static bool Utopia::ParallelExecution::is_enabled ( )
inlinestatic

Query if parallel execution is currently enabled.

Note
This value does not imply if parallel execution actually applies. If prerequisites are not met, parallel algorithms will default to sequential execution.
160{ return _enabled; }

◆ set()

static void Utopia::ParallelExecution::set ( const Setting  value)
inlinestatic

Choose a setting for parallel execution at runtime.

This setting may be changed at any time during runtime. However, algorithms currently running will continue with the policy they have been started with.

136 {
137 _enabled = (value == Setting::enabled);
138
139 const auto log = get_logger();
140 std::string msg = fmt::format("Parallel execution {}",
141 _enabled ? "enabled" : "disabled");
142
143#ifdef UTOPIA_PARALLEL
144 log->info(msg);
145#else
146 msg += ", but settings do NOT apply";
147 if (_enabled)
148 log->warn(msg);
149 else
150 log->debug(msg);
151#endif
152 }
static std::shared_ptr< spdlog::logger > get_logger()
Fetch the core logger.
Definition parallel.hh:88

Member Data Documentation

◆ _enabled

bool Utopia::ParallelExecution::_enabled = false
inlinestaticprivate

Runtime setting for parallel execution.


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