Peano
Loading...
Searching...
No Matches
Core.cpp
Go to the documentation of this file.
2
7
8#ifdef CompilerHasSysinfo
9#include <sched.h>
10#endif
11
12#if defined(SharedOMP)
13
14#include <omp.h>
15
16#include "config.h"
17
18tarch::logging::Log tarch::multicore::Core::_log( "tarch::multicore::Core" );
19
20
22 _numberOfThreads( omp_get_max_threads() ) {
23}
24
25
27
28
30 static Core instance;
31 return instance;
32}
33
34
35void tarch::multicore::Core::configure( int numberOfThreads) {
36 if ( omp_get_num_procs() != omp_get_max_threads() ) {
37 logWarning( "configure(int)", "omp_get_num_procs reports " << omp_get_num_procs() << " while omp_get_max_threads reports " << omp_get_max_threads() << ". Take smaller value to avoid overbooking" );
38 }
39 int maxThreads = std::min(omp_get_num_procs(), omp_get_max_threads());
40
41 if (numberOfThreads!=UseDefaultNumberOfThreads) {
42 if ( maxThreads!=numberOfThreads ) {
43 logWarning( "configure(int)", "number of threads configured (" << numberOfThreads << ") does not match system thread level of " << maxThreads << ". OpenMP may ignore manual thread count reset");
44 }
45
46 omp_set_num_threads(numberOfThreads);
47 _numberOfThreads = omp_get_max_threads();
48 logInfo( "configure(int)", "manually reset number of threads used to " << numberOfThreads );
49 } else {
50 omp_set_num_threads(maxThreads);
51 _numberOfThreads = omp_get_max_threads();
52 }
53
54 if (_numberOfThreads>getNumberOfUnmaskedThreads()) {
55 logWarning( "configure(int)", "number of configured threads (" << _numberOfThreads << ") is bigger than available unmasked threads (" << getNumberOfUnmaskedThreads() << ")" );
56 logWarning( "configure(int)", "unmasked threads: " << printUnmaskedThreads() );
57 }
58}
59
60
62
63
65 return true;
66}
67
68
70 return _numberOfThreads;
71}
72
73
75 return omp_get_thread_num();
76}
77
78
80 #ifdef CompilerHasSysinfo
81 return sched_getcpu();
82 #else
83 // https://stackoverflow.com/questions/33745364/sched-getcpu-equivalent-for-os-x
84 return 0;
85 #endif
86}
87
88
91 #pragma omp taskyield
92}
93#endif
#define logWarning(methodName, logMacroMessageStream)
Wrapper macro around tarch::tarch::logging::Log to improve logging.
Definition Log.h:440
#define logInfo(methodName, logMacroMessageStream)
Wrapper macro around tarch::tarch::logging::Log to improve logging.
Definition Log.h:411
Log Device.
Definition Log.h:516
bool isInitialised() const
Definition Core.cpp:65
~Core()
Destructor.
Definition Core.cpp:54
int getCoreNumber() const
Definition Core.cpp:69
static Core & getInstance()
Definition Core.cpp:56
int getNumberOfThreads() const
Returns the number of threads that is used.
Definition Core.cpp:67
static tarch::logging::Log _log
Logging device.
Definition Core.h:55
void configure(int numberOfThreads=UseDefaultNumberOfThreads)
Configure the whole node, i.e.
Definition Core.cpp:61
void shutdown()
Shutdown parallel environment.
Definition Core.cpp:63
int getThreadNumber() const
Definition Core.cpp:78
void yield()
Wrapper around backend-specific yield.
Definition Core.cpp:80
std::string printUnmaskedThreads()
Creates a string representation of those threads which are available to the processes.
Definition Core.cpp:11
int getNumberOfUnmaskedThreads()
This routine runs through the Unix thread mask and counts how many threads SLURM allows a code to use...
Definition Core.cpp:32