aGrUM  0.16.0
OMPThreads_inl.h
Go to the documentation of this file.
1 
29 // to ease automatic parsers
30 #include <agrum/agrum.h>
31 #include <agrum/core/OMPThreads.h>
32 
33 namespace gum {
34 
35  INLINE bool isOMP() {
36 #ifdef _OPENMP
37  return true;
38 #else
39  return false;
40 #endif
41  }
42 
43  INLINE void setNumberOfThreads(unsigned int number) {
44 #ifdef _OPENMP
45  omp_set_num_threads(number);
46 #else
48  "openMP was not enabled at compilation (or "
49  "you asked for 0 threads !)");
50 #endif
51  }
52 
53  INLINE unsigned int getMaxNumberOfThreads() {
54 #ifdef _OPENMP
55  return omp_get_max_threads();
56 #else
57  return 1;
58 #endif
59  }
60 
61  INLINE unsigned int getThreadNumber() {
62 #ifdef _OPENMP
63  return omp_get_thread_num();
64 #else
65  return 0;
66 #endif
67  }
68 
69  INLINE unsigned int getNumberOfRunningThreads() {
70 #ifdef _OPENMP
71  return omp_get_num_threads();
72 #else
73  return 1;
74 #endif
75  }
76 
77  INLINE unsigned int getNumberOfLogicalProcessors() {
78 #ifdef _OPENMP
79  return omp_get_num_procs();
80 #else
81  return 1;
82 #endif
83  }
84 
85  INLINE void setNestedParallelism(bool value) {
86 #ifdef _OPENMP
87  omp_set_nested(((value == true) ? 1 : 0));
88 #else
90  "openMP was not enabled at compilation (and you "
91  "asked for nested parallelism !)");
92 #endif
93  }
94 
95  INLINE bool getNestedParallelism() {
96 #ifdef _OPENMP
97  return ((omp_get_nested() == 0) ? false : true);
98 #else
99  return false;
100 #endif
101  }
102 
103  INLINE void setDynamicThreadsNumber(bool value) {
104 #ifdef _OPENMP
105  omp_set_dynamic(((value == true) ? 1 : 0));
106 #else
108  "openMP was not enabled at compilation (and you "
109  "asked for dynamic adjustment of the number of "
110  "threads !)");
111 #endif
112  }
113 
114  INLINE bool getDynamicThreadsNumber() {
115 #ifdef _OPENMP
116  return ((omp_get_dynamic() == 0) ? false : true);
117 #else
118  return false;
119 #endif
120  }
121 
122 } // namespace gum
bool isOMP()
Is OMP active ?
unsigned int getNumberOfLogicalProcessors()
Get the number of logical processors.
unsigned int getNumberOfRunningThreads()
Get the current number of running threads.
unsigned int getThreadNumber()
Get the calling thread id.
bool getDynamicThreadsNumber()
Get the dynamic thread number adjustment status.
void setNestedParallelism(bool value)
Set nested parallelism (false bu default).
unsigned int getMaxNumberOfThreads()
Returns the maximum number of threads at any time.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
bool getNestedParallelism()
Get nested parallelism status.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
void setDynamicThreadsNumber(bool value)
Set the dynamic threads number (false by default).
void setNumberOfThreads(unsigned int number)
Set the number of threads to be used.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55