Peano
Loading...
Searching...
No Matches
Core.cpp
Go to the documentation of this file.
2
6
7#ifdef CompilerHasSysinfo
8#include <sched.h>
9#endif
10
12 std::stringstream out;
13 out << "(";
14#ifdef CompilerHasSysinfo
15 cpu_set_t mask;
16 sched_getaffinity(0, sizeof(cpu_set_t), &mask);
17
18 for (auto i = 0u; i < std::thread::hardware_concurrency(); i++) {
19 if (CPU_ISSET(i, &mask) != 0) {
20 out << "x";
21 } else {
22 out << "o";
23 }
24 }
25#else
26 out << " -- not available -- ";
27#endif
28 out << ")";
29 return out.str();
30}
31
33#ifdef CompilerHasSysinfo
34 cpu_set_t mask;
35 sched_getaffinity(0, sizeof(cpu_set_t), &mask);
36
37 int result = 0;
38 for (auto i = 0u; i < std::thread::hardware_concurrency(); i++) {
39 if (CPU_ISSET(i, &mask) != 0) {
40 result++;
41 }
42 }
43
44 return result;
45#else
46 return std::thread::hardware_concurrency();
47#endif
48}
49
50#ifndef SharedMemoryParallelisation
51
53
55
57 static Core instance;
58 return instance;
59}
60
61void tarch::multicore::Core::configure(int /*numberOfThreads*/) {}
62
64
65bool tarch::multicore::Core::isInitialised() const { return true; }
66
68
70#ifdef CompilerHasSysinfo
71 return sched_getcpu();
72#else
73 // https://stackoverflow.com/questions/33745364/sched-getcpu-equivalent-for-os-x
74 return 0;
75#endif
76}
77
79
81
82#endif
float u
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
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