27#ifndef EWOMS_THREAD_MANAGER_HH
28#define EWOMS_THREAD_MANAGER_HH
38#include <dune/common/version.hh>
45template <
class TypeTag>
50#if defined(_OPENMP) || DOXYGEN
63 Parameters::Register<Parameters::ThreadsPerProcess>
64 (
"The maximum number of threads to be instantiated per process "
65 "('-1' means 'automatic')");
77 static void init(
bool queryCommandLineParameter =
true)
79 if (queryCommandLineParameter)
81 numThreads_ = Parameters::Get<Parameters::ThreadsPerProcess>();
85 if (numThreads_ != 1 && numThreads_ != -1)
86 throw std::invalid_argument(
"OpenMP is not available. The only valid values for "
87 "threads-per-process is 1 and -1 but it is "+std::to_string(numThreads_)+
"!");
89#elif !defined NDEBUG && defined DUNE_INTERFACECHECK
91 throw std::invalid_argument(
"You explicitly enabled Barton-Nackman interface checking in Dune. "
92 "The Dune implementation of this is currently incompatible with "
93 "thread parallelism!");
98 throw std::invalid_argument(
"Zero threads per process are not possible: It must be at least 1, "
99 "(or -1 for 'automatic')!");
105 omp_set_num_threads(numThreads_);
111 numThreads_ = omp_get_max_threads();
119 {
return static_cast<unsigned>(numThreads_); }
127 return static_cast<unsigned>(omp_get_thread_num());
134 static int numThreads_;
137template <
class TypeTag>
138int ThreadManager<TypeTag>::numThreads_ = 1;
Simplifies multi-threaded capabilities.
Definition: threadmanager.hh:47
@ isFake
Specify whether OpenMP is really available or not.
Definition: threadmanager.hh:52
static unsigned maxThreads()
Return the maximum number of threads of the current process.
Definition: threadmanager.hh:118
static void init(bool queryCommandLineParameter=true)
Initialize number of threads used thread manager.
Definition: threadmanager.hh:77
static unsigned threadId()
Return the index of the current OpenMP thread.
Definition: threadmanager.hh:124
static void registerParameters()
Register all run-time parameters of the thread manager.
Definition: threadmanager.hh:61
Declare the properties used by the infrastructure code of the finite volume discretizations.
Definition: blackoilboundaryratevector.hh:37
This file provides the infrastructure to retrieve run-time parameters.
The Opm property system, traits with inheritance.