1 #ifndef DUNE_FEM_OMPMANAGER_HH 2 #define DUNE_FEM_OMPMANAGER_HH 7 #if USE_PTHREADS && HAVE_PTHREAD == 0 8 #warning "pthreads were not found!" 12 #if defined _OPENMP || USE_PTHREADS == 1 13 #ifndef USE_SMP_PARALLEL 14 #define USE_SMP_PARALLEL 41 return omp_get_max_threads();
47 return omp_get_num_threads();
53 return omp_get_thread_num();
65 omp_set_num_threads( numThreads );
75 #warning "ThreadManager: using pthreads" 82 static inline Manager& instance()
84 static thread_local Manager mg ;
88 inline void initThread(
const int maxThreads,
const int threadNum )
92 threadNum_ = threadNum ;
100 inline void multiThreadMode(
const int nThreads )
102 activeThreads_ = nThreads;
105 inline int maxThreads()
const {
return maxThreads_; }
109 assert( threadNum_ >= 0 );
119 : threadNum_( -1 ), maxThreads_( 1 ), activeThreads_( 1 )
123 static inline Manager& manager()
125 return Manager :: instance();
133 static inline void initSingleThreadMode()
135 manager().singleThreadMode();
139 static inline void initMultiThreadMode(
const int nThreads )
141 manager().multiThreadMode( nThreads );
145 static inline void initThread(
const int maxThreads,
const int threadNum )
147 manager().initThread( maxThreads, threadNum );
156 return manager().maxThreads();
162 return manager().currentThreads();
166 static inline int thread()
168 return manager().thread();
175 manager().initThread( numThreads, 0 );
225 #endif // #ifndef DUNE_FEM_OMPMANAGER_HH
static bool isMaster()
return true if the current thread is the master thread (i.e. thread 0)
Definition: threadmanager.hh:211
The ThreadManager wrapps basic shared memory functionality provided by OpenMP or pthreads such as thr...
Definition: threadmanager.hh:199
static void setMaxNumberThreads(const int numThreads)
set maximal number of threads available during run
Definition: threadmanager.hh:214
static int thread()
return thread number
Definition: threadmanager.hh:208
Definition: coordinate.hh:4
static int currentThreads()
return number of current threads
Definition: threadmanager.hh:205
static int maxThreads()
return maximal number of threads possbile in the current run
Definition: threadmanager.hh:202
static bool singleThreadMode()
returns true if program is operating on one thread currently
Definition: threadmanager.hh:217