GemaCoreLib
The GeMA Core library
gmOmp.h
Go to the documentation of this file.
1 /************************************************************************
2 **
3 ** Copyright (C) 2014 by Carlos Augusto Teixera Mendes
4 ** All rights reserved.
5 **
6 ** This file is part of the "GeMA" software. It's use should respect
7 ** the terms in the license agreement that can be found together
8 ** with this source code.
9 ** It is provided AS IS, with NO WARRANTY OF ANY KIND,
10 ** INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR
11 ** A PARTICULAR PURPOSE.
12 **
13 ************************************************************************/
14 
26 #ifndef _GEMA_OPENMP_H_
27 #define _GEMA_OPENMP_H_
28 
29 #ifdef _OPENMP
30 #include <omp.h>
31 #endif
32 
36 inline void GmOmpInit(int maxThreads)
37 {
38  assert(maxThreads > 0);
39 #ifdef _OPENMP
40  omp_set_num_threads(maxThreads);
41  omp_set_dynamic(0);
42 #endif
43 }
44 
51 inline int GmOmpAdjustNumThreads(int nt)
52 {
53 #ifdef _OPENMP
54  int mt = omp_get_max_threads();
55  assert(mt > 0);
56  return (nt > 0 && nt <= mt) ? nt : mt;
57 #else
58  return 1;
59 #endif
60 }
61 
66 inline int GmOmpThreadNum()
67 {
68 #ifdef _OPENMP
69  return omp_get_thread_num();
70 #else
71  return 0;
72 #endif
73 }
74 
75 #ifdef _OPENMP
76 #define GM_OMP_ASSERT_NO_DYNAMIC assert(omp_get_dynamic() == 0)
77 #else
78 #define GM_OMP_ASSERT_NO_DYNAMIC ((void)0)
79 #endif
80 
81 #endif
int GmOmpThreadNum()
Returns the current Open Mp thread number (omp_get_thread_num()).
Definition: gmOmp.h:66
int GmOmpAdjustNumThreads(int nt)
Adjusts the given number of threads. If nt <= 0 or if nt > maximum number of omp threads,...
Definition: gmOmp.h:51
void GmOmpInit(int maxThreads)
Initializes OpenMP to use the given maximum number of threads. It also disables dynamic scheduling.
Definition: gmOmp.h:36