aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
OMPThreads_inl.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright (c) 2005-2021 by Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4  * info_at_agrum_dot_org
5  *
6  * This library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 /**
23  * @file
24  * @brief OpenMP wrappers implementation.
25  * @author Matthieu HOURBRACQ and Pierre-Henri WUILLEMIN(@LIP6)
26  */
27 
28 // to ease automatic parsers
29 #include <agrum/agrum.h>
30 #include <agrum/tools/core/OMPThreads.h>
31 
32 namespace gum {
33 
34  INLINE bool isOMP() {
35 #ifdef _OPENMP
36  return true;
37 #else
38  return false;
39 #endif
40  }
41 
42  INLINE void setNumberOfThreads(unsigned int number) {
43 #ifdef _OPENMP
45 #else
47  "openMP was not enabled at compilation (or "
48  "you asked for 0 threads !)");
49 #endif
50  }
51 
52  INLINE unsigned int getMaxNumberOfThreads() {
53 #ifdef _OPENMP
54  return omp_get_max_threads();
55 #else
56  return 1;
57 #endif
58  }
59 
60  INLINE unsigned int getThreadNumber() {
61 #ifdef _OPENMP
62  return omp_get_thread_num();
63 #else
64  return 0;
65 #endif
66  }
67 
69 #ifdef _OPENMP
70  return omp_get_num_threads();
71 #else
72  return 1;
73 #endif
74  }
75 
77 #ifdef _OPENMP
78  return omp_get_num_procs();
79 #else
80  return 1;
81 #endif
82  }
83 
85 #ifdef _OPENMP
86  omp_set_nested(((value == true) ? 1 : 0));
87 #else
89  "openMP was not enabled at compilation (and you "
90  "asked for nested parallelism !)");
91 #endif
92  }
93 
95 #ifdef _OPENMP
96  return ((omp_get_nested() == 0) ? false : true);
97 #else
98  return false;
99 #endif
100  }
101 
103 #ifdef _OPENMP
104  omp_set_dynamic(((value == true) ? 1 : 0));
105 #else
107  "openMP was not enabled at compilation (and you "
108  "asked for dynamic adjustment of the number of "
109  "threads !)");
110 #endif
111  }
112 
114 #ifdef _OPENMP
115  return ((omp_get_dynamic() == 0) ? false : true);
116 #else
117  return false;
118 #endif
119  }
120 
121 } // namespace gum
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643