Loading...
Searching...
No Matches
OMP.h
Go to the documentation of this file.
//# Copyright (C) 1993,1994,1995,1996,2000,2003
//# Associated Universities, Inc. Washington DC, USA.
//#
//# This library is free software; you can redistribute it and/or modify it
//# under the terms of the GNU Library General Public License as published by
//# the Free Software Foundation; either version 2 of the License, or (at your
//# option) any later version.
//#
//# This library is distributed in the hope that it will be useful, but WITHOUT
//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
//# License for more details.
//#
//# You should have received a copy of the GNU Library General Public License
//# along with this library; if not, write to the Free Software Foundation,
//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
//#
//# Correspondence concerning AIPS++ should be addressed as follows:
//# Internet email: casa-feedback@nrao.edu.
//# Postal address: AIPS++ Project Office
//# National Radio Astronomy Observatory
//# 520 Edgemont Road
//# Charlottesville, VA 22903-2475 USA
//#
#ifndef CASA_OS_OMP_H
#define CASA_OS_OMP_H
#include <casacore/casa/aips.h>
#ifdef _OPENMP
#include <omp.h>
#endif
namespace casacore {
namespace OMP {
// Get the maximum number of threads.
// OpenMP sets it to the env.var. OMP_NUM_THREADS. If undefined, it is
// the number of cores.
// If OpenMP is not used, 1 is returned.
inline uInt maxThreads()
{
#ifdef _OPENMP
return omp_get_max_threads();
#else
return 1;
#endif
}
// Backward
uInt nMaxThreads();
// Set the number of threads to use. Note it can be overridden
// for a parallel section by 'omp parallel num_threads(n)'.
// Nothing is done if OpenMP is not used.
#ifdef _OPENMP
inline void setNumThreads (uInt n)
{ omp_set_num_threads (n); }
#else
inline void setNumThreads (uInt)
{}
#endif
// Get the number of threads used in a parallel piece of code.
// If OpenMP is not used, 1 is returned.
inline uInt numThreads()
{
#ifdef _OPENMP
return omp_get_num_threads();
#else
return 1;
#endif
}
// Get the thread number (0 till numThreads).
// If OpenMP is not used, 0 is returned.
inline uInt threadNum()
{
#ifdef _OPENMP
return omp_get_thread_num();
#else
return 0;
#endif
}
// Set if nested parallel sections are possible or not.
// Nothing is done if OpenMP is not used.
#ifdef _OPENMP
inline void setNested (Bool nest)
{ omp_set_nested (nest); }
#else
inline void setNested (Bool)
{}
#endif
// Test if nested parallel sections are possible.
// If OpenMP is not used, false is returned.
inline bool nested()
{
#ifdef _OPENMP
return omp_get_nested();
#else
return false;
#endif
}
} // end namespace
} // end namespace
#endif
casacore::OMP
Definition OMP.h:35
casacore::OMP::nested
bool nested()
Test if nested parallel sections are possible.
Definition OMP.h:97
casacore::OMP::numThreads
uInt numThreads()
Get the number of threads used in a parallel piece of code.
Definition OMP.h:65
casacore::OMP::setNumThreads
void setNumThreads(uInt)
Set the number of threads to use.
Definition OMP.h:59
casacore::OMP::threadNum
uInt threadNum()
Get the thread number (0 till numThreads).
Definition OMP.h:76
casacore::OMP::nMaxThreads
uInt nMaxThreads()
Backward.
casacore::OMP::setNested
void setNested(Bool)
Set if nested parallel sections are possible or not.
Definition OMP.h:91
casacore::OMP::maxThreads
uInt maxThreads()
Get the maximum number of threads.
Definition OMP.h:41
casacore
this file contains all the compiler specific defines
Definition mainpage.dox:28
casacore::uInt
unsigned int uInt
Definition aipstype.h:49
casacore::Bool
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40