| 1 |
/* |
| 2 |
* This file is part of libcxxsupport. |
| 3 |
* |
| 4 |
* libcxxsupport is free software; you can redistribute it and/or modify |
| 5 |
* it under the terms of the GNU General Public License as published by |
| 6 |
* the Free Software Foundation; either version 2 of the License, or |
| 7 |
* (at your option) any later version. |
| 8 |
* |
| 9 |
* libcxxsupport is distributed in the hope that it will be useful, |
| 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
* GNU General Public License for more details. |
| 13 |
* |
| 14 |
* You should have received a copy of the GNU General Public License |
| 15 |
* along with libcxxsupport; if not, write to the Free Software |
| 16 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 |
*/ |
| 18 |
|
| 19 |
/* |
| 20 |
* libcxxsupport is being developed at the Max-Planck-Institut fuer Astrophysik |
| 21 |
* and financially supported by the Deutsches Zentrum fuer Luft- und Raumfahrt |
| 22 |
* (DLR). |
| 23 |
*/ |
| 24 |
|
| 25 |
/*! \file openmp_support.h |
| 26 |
* Various OpenMP-related convenience functions |
| 27 |
* |
| 28 |
* Copyright (C) 2005-2011 Max-Planck-Society |
| 29 |
* \author Martin Reinecke |
| 30 |
*/ |
| 31 |
|
| 32 |
#ifndef PLANCK_OPENMP_SUPPORT_H |
| 33 |
#define PLANCK_OPENMP_SUPPORT_H |
| 34 |
|
| 35 |
#ifdef _OPENMP |
| 36 |
#include <omp.h> |
| 37 |
#endif |
| 38 |
|
| 39 |
#include "share_utils.h" |
| 40 |
|
| 41 |
inline bool openmp_enabled() |
| 42 |
{ |
| 43 |
#ifdef _OPENMP |
| 44 |
return true; |
| 45 |
#else |
| 46 |
return false; |
| 47 |
#endif |
| 48 |
} |
| 49 |
|
| 50 |
inline int openmp_max_threads () |
| 51 |
{ |
| 52 |
#ifdef _OPENMP |
| 53 |
return omp_get_max_threads(); |
| 54 |
#else |
| 55 |
return 1; |
| 56 |
#endif |
| 57 |
} |
| 58 |
|
| 59 |
inline int openmp_num_threads () |
| 60 |
{ |
| 61 |
#ifdef _OPENMP |
| 62 |
return omp_get_num_threads(); |
| 63 |
#else |
| 64 |
return 1; |
| 65 |
#endif |
| 66 |
} |
| 67 |
|
| 68 |
inline int openmp_thread_num () |
| 69 |
{ |
| 70 |
#ifdef _OPENMP |
| 71 |
return omp_get_thread_num(); |
| 72 |
#else |
| 73 |
return 0; |
| 74 |
#endif |
| 75 |
} |
| 76 |
|
| 77 |
/*! Calculates the range of indices between \a glo and \a ghi which |
| 78 |
must be processed by this thread and returns it in \a lo and \a hi. |
| 79 |
|
| 80 |
The indices \a ghi and \a hi are "one past the last real index", |
| 81 |
in analogy to the STL iterators. */ |
| 82 |
inline void openmp_calc_share (int64 glo, int64 ghi, int64 &lo, int64 &hi) |
| 83 |
{ |
| 84 |
#ifdef _OPENMP |
| 85 |
calcShareGeneral (glo,ghi,omp_get_num_threads(),omp_get_thread_num(),lo,hi); |
| 86 |
#else |
| 87 |
lo=glo; hi=ghi; |
| 88 |
#endif |
| 89 |
} |
| 90 |
|
| 91 |
#endif |