aGrUM  0.13.2
OMPThreads_inl.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Pierre-Henri WUILLEMIN and Christophe GONZALES *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
20 
27 // to ease automatic parsers
28 #include <agrum/agrum.h>
29 #include <agrum/core/OMPThreads.h>
30 
31 namespace gum {
32 
33  INLINE bool isOMP() {
34 #ifdef _OPENMP
35  return true;
36 #else
37  return false;
38 #endif
39  }
40 
41  INLINE void setNumberOfThreads(unsigned int number) {
42 #ifdef _OPENMP
43  omp_set_num_threads(number);
44 #else
46  "openMP was not enabled at compilation (or "
47  "you asked for 0 threads !)");
48 #endif
49  }
50 
51  INLINE unsigned int getMaxNumberOfThreads() {
52 #ifdef _OPENMP
53  return omp_get_max_threads();
54 #else
55  return 1;
56 #endif
57  }
58 
59  INLINE unsigned int getThreadNumber() {
60 #ifdef _OPENMP
61  return omp_get_thread_num();
62 #else
63  return 0;
64 #endif
65  }
66 
67  INLINE unsigned int getNumberOfRunningThreads() {
68 #ifdef _OPENMP
69  return omp_get_num_threads();
70 #else
71  return 1;
72 #endif
73  }
74 
75  INLINE unsigned int getNumberOfLogicalProcessors() {
76 #ifdef _OPENMP
77  return omp_get_num_procs();
78 #else
79  return 1;
80 #endif
81  }
82 
83  INLINE void setNestedParallelism(bool value) {
84 #ifdef _OPENMP
85  omp_set_nested(((value == true) ? 1 : 0));
86 #else
88  "openMP was not enabled at compilation (and you "
89  "asked for nested parallelism !)");
90 #endif
91  }
92 
93  INLINE bool getNestedParallelism() {
94 #ifdef _OPENMP
95  return ((omp_get_nested() == 0) ? false : true);
96 #else
97  return false;
98 #endif
99  }
100 
101  INLINE void setDynamicThreadsNumber(bool value) {
102 #ifdef _OPENMP
103  omp_set_dynamic(((value == true) ? 1 : 0));
104 #else
106  "openMP was not enabled at compilation (and you "
107  "asked for dynamic adjustment of the number of "
108  "threads !)");
109 #endif
110  }
111 
112  INLINE bool getDynamicThreadsNumber() {
113 #ifdef _OPENMP
114  return ((omp_get_dynamic() == 0) ? false : true);
115 #else
116  return false;
117 #endif
118  }
119 
120 } // 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.
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
bool getNestedParallelism()
Get nested parallelism status.
Wrappers for OpenMP.
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:66