casacore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OMP.h
Go to the documentation of this file.
1 //# Copyright (C) 1993,1994,1995,1996,2000,2003
2 //# Associated Universities, Inc. Washington DC, USA.
3 //#
4 //# This library is free software; you can redistribute it and/or modify it
5 //# under the terms of the GNU Library General Public License as published by
6 //# the Free Software Foundation; either version 2 of the License, or (at your
7 //# option) any later version.
8 //#
9 //# This library is distributed in the hope that it will be useful, but WITHOUT
10 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 //# License for more details.
13 //#
14 //# You should have received a copy of the GNU Library General Public License
15 //# along with this library; if not, write to the Free Software Foundation,
16 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
17 //#
18 //# Correspondence concerning AIPS++ should be addressed as follows:
19 //# Internet email: aips2-request@nrao.edu.
20 //# Postal address: AIPS++ Project Office
21 //# National Radio Astronomy Observatory
22 //# 520 Edgemont Road
23 //# Charlottesville, VA 22903-2475 USA
24 //#
25 
26 #ifndef CASA_OS_OMP_H
27 #define CASA_OS_OMP_H
28 
29 #include <casacore/casa/aips.h>
30 #ifdef _OPENMP
31 #include <omp.h>
32 #endif
33 
34 namespace casacore {
35  namespace OMP {
36 
37  // Get the maximum number of threads.
38  // OpenMP sets it to the env.var. OMP_NUM_THREADS. If undefined, it is
39  // the number of cores.
40  // If OpenMP is not used, 1 is returned.
41  inline uInt maxThreads()
42  {
43 #ifdef _OPENMP
44  return omp_get_max_threads();
45 #else
46  return 1;
47 #endif
48  }
49  // Backward
50  uInt nMaxThreads();
51 
52  // Set the number of threads to use. Note it can be overridden
53  // for a parallel section by 'omp parallel num_threads(n)'.
54  // Nothing is done if OpenMP is not used.
55 #ifdef _OPENMP
56  inline void setNumThreads (uInt n)
57  { omp_set_num_threads (n); }
58 #else
59  inline void setNumThreads (uInt)
60  {}
61 #endif
62 
63  // Get the number of threads used in a parallel piece of code.
64  // If OpenMP is not used, 1 is returned.
65  inline uInt numThreads()
66  {
67 #ifdef _OPENMP
68  return omp_get_num_threads();
69 #else
70  return 1;
71 #endif
72  }
73 
74  // Get the thread number (0 till numThreads).
75  // If OpenMP is not used, 0 is returned.
76  inline uInt threadNum()
77  {
78 #ifdef _OPENMP
79  return omp_get_thread_num();
80 #else
81  return 0;
82 #endif
83  }
84 
85  // Set if nested parallel sections are possible or not.
86  // Nothing is done if OpenMP is not used.
87 #ifdef _OPENMP
88  inline void setNested (Bool nest)
89  { omp_set_nested (nest); }
90 #else
91  inline void setNested (Bool)
92  {}
93 #endif
94 
95  // Test if nested parallel sections are possible.
96  // If OpenMP is not used, false is returned.
97  inline bool nested()
98  {
99 #ifdef _OPENMP
100  return omp_get_nested();
101 #else
102  return false;
103 #endif
104  }
105 
106  } // end namespace
107 } // end namespace
108 
109 #endif
uInt numThreads()
Get the number of threads used in a parallel piece of code.
Definition: OMP.h:65
bool nested()
Test if nested parallel sections are possible.
Definition: OMP.h:97
void setNumThreads(uInt)
Set the number of threads to use.
Definition: OMP.h:59
uInt threadNum()
Get the thread number (0 till numThreads).
Definition: OMP.h:76
void setNested(Bool)
Set if nested parallel sections are possible or not.
Definition: OMP.h:91
uInt nMaxThreads()
Backward.
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
uInt maxThreads()
Get the maximum number of threads.
Definition: OMP.h:41
unsigned int uInt
Definition: aipstype.h:51