Peano 4
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 (int i = 0; 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 (int i = 0; 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
52
54
56 static Core instance;
57 return instance;
58}
59
60void tarch::multicore::Core::configure(int numberOfThreads) { internal::configureInternalTaskQueues(numberOfThreads); }
61
63
64bool tarch::multicore::Core::isInitialised() const { return true; }
65
67
69#ifdef CompilerHasSysinfo
70 return sched_getcpu();
71#else
72 // https://stackoverflow.com/questions/33745364/sched-getcpu-equivalent-for-os-x
73 return 0;
74#endif
75}
76
78
80
81#endif
bool isInitialised() const
Definition Core.cpp:64
~Core()
Destructor.
Definition Core.cpp:53
int getCoreNumber() const
Definition Core.cpp:68
static Core & getInstance()
Definition Core.cpp:55
int getNumberOfThreads() const
Returns the number of threads that is used.
Definition Core.cpp:66
void configure(int numberOfThreads=UseDefaultNumberOfThreads)
Configure the whole node, i.e.
Definition Core.cpp:60
void shutdown()
Shutdown parallel environment.
Definition Core.cpp:62
int getThreadNumber() const
Definition Core.cpp:77
void yield()
Wrapper around backend-specific yield.
Definition Core.cpp:79
void configureInternalTaskQueues(int numberOfTasks)
Set up internal queues.
Definition Tasks.cpp:363
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