casacore
Loading...
Searching...
No Matches
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: casa-feedback@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
34namespace casacore {
35namespace 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.
41inline uInt maxThreads() {
42#ifdef _OPENMP
43 return omp_get_max_threads();
44#else
45 return 1;
46#endif
47}
48// Backward
50
51// Set the number of threads to use. Note it can be overridden
52// for a parallel section by 'omp parallel num_threads(n)'.
53// Nothing is done if OpenMP is not used.
54#ifdef _OPENMP
55inline void setNumThreads(uInt n) { omp_set_num_threads(n); }
56#else
57inline void setNumThreads(uInt) {}
58#endif
59
60// Get the number of threads used in a parallel piece of code.
61// If OpenMP is not used, 1 is returned.
62inline uInt numThreads() {
63#ifdef _OPENMP
64 return omp_get_num_threads();
65#else
66 return 1;
67#endif
68}
69
70// Get the thread number (0 till numThreads).
71// If OpenMP is not used, 0 is returned.
72inline uInt threadNum() {
73#ifdef _OPENMP
74 return omp_get_thread_num();
75#else
76 return 0;
77#endif
78}
79
80// Set if nested parallel sections are possible or not.
81// Nothing is done if OpenMP is not used.
82#ifdef _OPENMP
83inline void setNested(Bool nest) { omp_set_nested(nest); }
84#else
85inline void setNested(Bool) {}
86#endif
87
88// Test if nested parallel sections are possible.
89// If OpenMP is not used, false is returned.
90inline bool nested() {
91#ifdef _OPENMP
92 return omp_get_nested();
93#else
94 return false;
95#endif
96}
97
98} // namespace OMP
99} // namespace casacore
100
101#endif
bool nested()
Test if nested parallel sections are possible.
Definition OMP.h:90
uInt numThreads()
Get the number of threads used in a parallel piece of code.
Definition OMP.h:62
void setNumThreads(uInt)
Set the number of threads to use.
Definition OMP.h:57
uInt threadNum()
Get the thread number (0 till numThreads).
Definition OMP.h:72
uInt nMaxThreads()
Backward.
void setNested(Bool)
Set if nested parallel sections are possible or not.
Definition OMP.h:85
uInt maxThreads()
Get the maximum number of threads.
Definition OMP.h:41
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40