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
13 std::stringstream out;
14 out << "(";
15#ifdef CompilerHasSysinfo
16 cpu_set_t mask;
17 sched_getaffinity(0, sizeof(cpu_set_t), &mask);
18
19 for (auto i = 0u; i < std::thread::hardware_concurrency(); i++) {
20 if (CPU_ISSET(i, &mask) != 0) {
21 out << "x";
22 } else {
23 out << "o";
24 }
25 }
26#else
27 out << " -- not available -- ";
28#endif
29 out << ")";
30 return out.str();
31}
32
34#ifdef CompilerHasSysinfo
35 cpu_set_t mask;
36 sched_getaffinity(0, sizeof(cpu_set_t), &mask);
37
38 int result = 0;
39 for (auto i = 0u; i < std::thread::hardware_concurrency(); i++) {
40 if (CPU_ISSET(i, &mask) != 0) {
41 result++;
42 }
43 }
44
45 return result;
46#else
47 return std::thread::hardware_concurrency();
48#endif
49}
50
51#ifndef SharedMemoryParallelisation
52
54
56
58 static Core instance;
59 return instance;
60}
61
62void tarch::multicore::Core::configure(int /*numberOfThreads*/) {}
63
65
66bool tarch::multicore::Core::isInitialised() const { return true; }
67
69
71#ifdef CompilerHasSysinfo
72 return sched_getcpu();
73#else
74 // https://stackoverflow.com/questions/33745364/sched-getcpu-equivalent-for-os-x
75 return 0;
76#endif
77}
78
80
84
85#endif
float u
bool isInitialised() const
Definition Core.cpp:66
~Core()
Destructor.
Definition Core.cpp:55
int getCoreNumber() const
Definition Core.cpp:70
static Core & getInstance()
Definition Core.cpp:57
int getNumberOfThreads() const
Returns the number of threads that is used.
Definition Core.cpp:68
void configure(int numberOfThreads=UseDefaultNumberOfThreads)
Configure the whole node, i.e.
Definition Core.cpp:62
void shutdown()
Shutdown parallel environment.
Definition Core.cpp:64
int getThreadNumber() const
Definition Core.cpp:79
void yield()
Wrapper around backend-specific yield.
Definition Core.cpp:81
std::string printUnmaskedThreads()
Creates a string representation of those threads which are available to the processes.
Definition Core.cpp:12
int getNumberOfUnmaskedThreads()
This routine runs through the Unix thread mask and counts how many threads SLURM allows a code to use...
Definition Core.cpp:33