#include <genesis/utils/core/options.hpp>
Simple Options class for application-wide configuration and settings.
Definition at line 57 of file options.hpp.
Public Member Functions | |
bool | allow_file_overwriting () const |
Get whether Genesis is allowed to overwrite files when outputting data. More... | |
void | allow_file_overwriting (bool value) |
Set whether Genesis is allowed to overwrite files when outputting data. More... | |
std::vector< std::string > const & | command_line () const |
Returns an array of strings containing the program's command line arguments. More... | |
void | command_line (int const argc, char const *const *argv) |
Set arguments to the program's command line options. More... | |
std::string | command_line_string () const |
Returns a string containing the program's command line arguments. More... | |
std::shared_ptr< ThreadPool > | global_thread_pool () const |
Return a global thread pool to be used for parallel computations. More... | |
size_t | global_thread_pool_size () const |
Get the number of threads allocatd in the pool, plus one for the main thread. More... | |
void | init_global_thread_pool () |
Initialize the global thread pool to be used for parallel computations. More... | |
void | init_global_thread_pool (size_t num_threads, size_t max_queue_size=0) |
Initialize the global thread pool to be used for parallel computations. More... | |
InputReadingThreadPolicy | input_reading_thread_policy () |
Get the policy for the threading of input source reading. More... | |
void | input_reading_thread_policy (InputReadingThreadPolicy policy) |
Set the policy for the threading of input source reading. More... | |
std::default_random_engine & | random_engine () |
Return a thread-local engine for random number generation. More... | |
unsigned long | random_seed () const |
Returns the random seed that was used to initialize the engine. More... | |
void | random_seed (unsigned long const seed) |
Set a specific global seed for the random engine initialization. More... | |
size_t | seed_counter () const |
Return the number of seeds used to initialize thread-local random engines. More... | |
Static Public Member Functions | |
static Options & | get () |
Returns a single instance of this class. More... | |
Public Types | |
enum | InputReadingThreadPolicy { kStrict, kTrivialAsync, kAllAsync } |
Decide how to use threads for input reading. More... | |
|
inline |
Get whether Genesis is allowed to overwrite files when outputting data.
See allow_file_overwriting( bool ) for details.
Definition at line 359 of file options.hpp.
|
inline |
Set whether Genesis is allowed to overwrite files when outputting data.
The option is false
by default, which causes Genesis to throw an execption when it attempts to write to a file that is already existing, as long as only the internal file writing functions are used, such as the to_file() function to get a target for the writer classes. We of course cannot control any independent file operations.
By setting this option to true
, files are silently overwritten in case they already exist. This has to be activated explicitly in order to avoid losing files by accident.
Definition at line 377 of file options.hpp.
|
inline |
Returns an array of strings containing the program's command line arguments.
Definition at line 82 of file options.hpp.
|
inline |
Set arguments to the program's command line options.
If the program is run from the command line, this method has to be used to properly propagate the command line options to this options class.
Definition at line 106 of file options.hpp.
|
inline |
Returns a string containing the program's command line arguments.
Definition at line 90 of file options.hpp.
|
inlinestatic |
Returns a single instance of this class.
Definition at line 68 of file options.hpp.
|
inline |
Return a global thread pool to be used for parallel computations.
The thread pool has to be initialized with init_global_thread_pool() first.
Note: In cases where we need to limit our number of spawned threads to some maximum amount, we might even want to use this pool for our readers, which often use AsynchronousReader, thus spawning threads to minimize i/o wait times; but this is not recommended, as the threads waiting for i/o might then be unnecessaryliy wait in the thread pool, just for them to then relatively quickly (compared to potential wait times in the thread queue) execute their disk operation. However, for more complex reading such as from compressed files, we might want to use the global thread pool after all. See BaseInputSource::is_trivial()
Definition at line 268 of file options.hpp.
|
inline |
Get the number of threads allocatd in the pool, plus one for the main thread.
This is because with our ProactiveFuture implementaiton, the main thread does work as well.
Definition at line 284 of file options.hpp.
|
inline |
Initialize the global thread pool to be used for parallel computations.
This overload uses the result of guess_number_of_threads() to get the overall number of threads to use, and initializes the pool to use one fewer than that, to account for the main thread also doing work. As our ThreadPool implementation uses what we call a ProactiveFuture, the main thread will start processing tasks from the pool queue while it is waiting for results to get ready.
After calling this function, global_thread_pool() can be used to obtain the global thread pool to enqueue work.
Definition at line 215 of file options.hpp.
|
inline |
Initialize the global thread pool to be used for parallel computations.
This initializes the pool to have exactly as many threads as provided by num_threads
here. Note that the main thread will also do work, so it is recommended to keep the num_threads
at at least one fewer than the hardware concurrency (or other upper limit of threads, such as OpenMP or Slum limits, that you might want to keep). Use the overload init_global_thread_pool() without any arguments to do this automatically.
If num_threads
is 0
, the thread pool is initialized with no threads at all, meaning that all enqueued work will instead be processed by the main thread once it wants to obtain the results of tasks. This essentially renders the thread pool into a lazy evaluating task queue.
After calling this function, global_thread_pool() can be used to obtain the global thread pool to enqueue work.
Definition at line 244 of file options.hpp.
|
inline |
Get the policy for the threading of input source reading.
Definition at line 345 of file options.hpp.
|
inline |
Set the policy for the threading of input source reading.
Definition at line 337 of file options.hpp.
|
inline |
Return a thread-local engine for random number generation.
Caveat: The engines are thread-local, and hence thread-safe. However, generally, in a multi-threaded setting, the order of execution in not deterministic, and hence results might not be reproducible, even when using a fixed seed.
Definition at line 168 of file options.hpp.
|
inline |
Returns the random seed that was used to initialize the engine.
This is the global seed that is used as a basis for all thread-local seeding.
Definition at line 124 of file options.hpp.
|
inline |
Set a specific global seed for the random engine initialization.
This (re)sets the global seed for the thread-local random engines. The engine of the thread where this function is called from, as well as any thread spawned after, is reseeded using this seed plus a counter based on the number of spawned threads.
On startup, the seed is initialized using the current system time, and that exact seed is used for the main thead. The seed can be reset using this function, but this will only affect the thread where the function is called from, as well as any threads spawned later. If a fixed seed is needed, this function hence needs to be called prior to spawning threads, and in particlar, before calling the init_global_thread_pool() functions. Otherwise, this function throws an exception, in order to avoid potential bugs that would be hard to track down.
In a single threaded environment, this behaves identical to the usual way of (re)seeding a random engine.
Definition at line 147 of file options.hpp.
|
inline |
Return the number of seeds used to initialize thread-local random engines.
This corresponds to the number of threads that have called random_engine().
Definition at line 178 of file options.hpp.
|
strong |
Decide how to use threads for input reading.
Definition at line 299 of file options.hpp.