25 #ifndef EWOMS_THREAD_MANAGER_HH
26 #define EWOMS_THREAD_MANAGER_HH
37 #include <dune/common/version.hh>
40 namespace Properties {
47 template <
class TypeTag>
52 #if defined(_OPENMP) || DOXYGEN
66 "The maximum number of threads to be instantiated per process "
67 "('-1' means 'automatic')");
76 if (numThreads_ != 1 && numThreads_ != -1)
77 OPM_THROW(std::invalid_argument,
78 "OpenMP is not available. The only valid values for "
79 "threads-per-process is 1 and -1 but it is " << numThreads_ <<
"!");
81 #elif !DUNE_VERSION_NEWER(DUNE_COMMON, 2,4) && !defined NDEBUG
83 OPM_THROW(std::invalid_argument,
84 "You seem to be using Dune "
85 <<DUNE_COMMON_VERSION_MAJOR<<
"."<<DUNE_COMMON_VERSION_MINOR
86 <<
" in debug mode and with the number of OpenMP threads larger than 1. "
87 "This Dune version does not support thread parallelism in debug mode!");
90 #elif DUNE_VERSION_NEWER(DUNE_COMMON, 2,4) && !defined NDEBUG && defined DUNE_INTERFACECHECK
92 OPM_THROW(std::invalid_argument,
93 "You explicitly enabled Barton-Nackman interface checking in Dune. "
94 "The Dune implementation of this is currently incompatible with "
95 "thread parallelism!");
99 OPM_THROW(std::invalid_argument,
100 "Zero threads per process are not possible: It must be at least 1, "
101 "(or -1 for 'automatic')!");
108 omp_set_num_threads(numThreads_);
110 numThreads_ = omp_get_max_threads();
118 {
return numThreads_; }
126 return omp_get_thread_num();
133 static int numThreads_;
136 template <
class TypeTag>
137 int ThreadManager<TypeTag>::numThreads_ = 1;
This file implements various objects which provide mutual exclusion capabilities for multi-threaded a...
static void registerParameters()
Register all run-time parameters of the thread manager.
Definition: threadmanager.hh:63
static void init()
Definition: threadmanager.hh:70
Simplifies multi-threaded capabilities.
Definition: threadmanager.hh:48
Specify whether OpenMP is really available or not.
Definition: threadmanager.hh:54
NEW_PROP_TAG(Grid)
The type of the DUNE grid.
This file provides the infrastructure to retrieve run-time parameters.
Definition: baseauxiliarymodule.hh:35
static int maxThreads()
Return the maximum number of threads of the current process.
Definition: threadmanager.hh:117
#define EWOMS_REGISTER_PARAM(TypeTag, ParamType, ParamName, Description)
Register a run-time parameter.
Definition: parametersystem.hh:64
static int threadId()
Return the index of the current OpenMP thread.
Definition: threadmanager.hh:123
Provides the magic behind the eWoms property system.
#define EWOMS_GET_PARAM(TypeTag, ParamType, ParamName)
Retrieve a runtime parameter.
Definition: parametersystem.hh:95