Peano
Loading...
Searching...
No Matches
Core.cpp
Go to the documentation of this file.
1#include "tarch/Assertions.h"
3
7
8#ifdef CompilerHasSysinfo
9#include <sched.h>
10#endif
11
12#include <map>
13
14#if defined(SharedTBB)
15#include <sstream>
16#include "config.h"
17#include <tbb/global_control.h>
18#include <tbb/info.h>
19#include <oneapi/tbb/task_arena.h>
20//#include <tbb/task_arena.h>
21
22#include <map>
23
24namespace {
25 ::tbb::global_control* globalControl = nullptr;
26}
27
28
29tarch::logging::Log tarch::multicore::Core::_log( "tarch::multicore::Core" );
30
31
33 _numberOfThreads( ::tbb::info::default_concurrency() ) {
34}
35
36
38
39
41 static Core instance;
42 return instance;
43}
44
45
46void tarch::multicore::Core::configure( int numberOfThreads ) {
47 if (globalControl!=nullptr) delete globalControl;
48 globalControl = nullptr;
49 if (numberOfThreads != UseDefaultNumberOfThreads) {
50 _numberOfThreads = numberOfThreads;
51 globalControl = new oneapi::tbb::global_control(oneapi::tbb::global_control::max_allowed_parallelism,numberOfThreads);
52 }
53 else {
54 _numberOfThreads = oneapi::tbb::info::default_concurrency();
55 }
56
57 if (_numberOfThreads>getNumberOfUnmaskedThreads()) {
58 logWarning( "configure(int)", "number of configured threads (" << numberOfThreads << ") is bigger than available unmasked threads (" << getNumberOfUnmaskedThreads() << ")" );
59 logWarning( "configure(int)", "unmasked threads: " << printUnmaskedThreads() );
60 }
61}
62
63
65 if (globalControl!=nullptr) delete globalControl;
66 globalControl = nullptr;
67}
68
69
71 return true;
72}
73
74
76 return _numberOfThreads;
77}
78
79
81 #ifdef CompilerHasSysinfo
82 return sched_getcpu();
83 #else
84 // https://stackoverflow.com/questions/33745364/sched-getcpu-equivalent-for-os-x
85 return 1;
86 #endif
87}
88
89
91 return tbb::this_task_arena::current_thread_index();
92}
93
94
96 // @todo This is not what I want. I want to interrupt the current task and
97 // tell TBB to continue with another task. This is technically not a
98 // yield, as I do not expect another thread to come in
99 std::this_thread::yield();
100}
101#endif
#define logWarning(methodName, logMacroMessageStream)
Wrapper macro around tarch::tarch::logging::Log to improve logging.
Definition Log.h:440
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
I've written an API to IIT, but I'm not currently using.