openmp_support.h

Go to the documentation of this file.
00001 /*
00002  *  This file is part of libcxxsupport.
00003  *
00004  *  libcxxsupport is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  libcxxsupport is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with libcxxsupport; if not, write to the Free Software
00016  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00017  */
00018 
00019 /*
00020  *  libcxxsupport is being developed at the Max-Planck-Institut fuer Astrophysik
00021  *  and financially supported by the Deutsches Zentrum fuer Luft- und Raumfahrt
00022  *  (DLR).
00023  */
00024 
00025 /*! \file openmp_support.h
00026  *  Various OpenMP-related convenience functions
00027  *
00028  *  Copyright (C) 2005-2011 Max-Planck-Society
00029  *  \author Martin Reinecke
00030  */
00031 
00032 #ifndef PLANCK_OPENMP_SUPPORT_H
00033 #define PLANCK_OPENMP_SUPPORT_H
00034 
00035 #ifdef _OPENMP
00036 #include <omp.h>
00037 #endif
00038 
00039 #include "share_utils.h"
00040 
00041 inline bool openmp_enabled()
00042   {
00043 #ifdef _OPENMP
00044   return true;
00045 #else
00046   return false;
00047 #endif
00048   }
00049 
00050 inline int openmp_max_threads ()
00051   {
00052 #ifdef _OPENMP
00053   return omp_get_max_threads();
00054 #else
00055   return 1;
00056 #endif
00057   }
00058 
00059 inline int openmp_num_threads ()
00060   {
00061 #ifdef _OPENMP
00062   return omp_get_num_threads();
00063 #else
00064   return 1;
00065 #endif
00066   }
00067 
00068 inline int openmp_thread_num ()
00069   {
00070 #ifdef _OPENMP
00071   return omp_get_thread_num();
00072 #else
00073   return 0;
00074 #endif
00075   }
00076 
00077 /*! Calculates the range of indices between \a glo and \a ghi which
00078     must be processed by this thread and returns it in \a lo and \a hi.
00079 
00080     The indices \a ghi and \a hi are "one past the last real index",
00081     in analogy to the STL iterators. */
00082 inline void openmp_calc_share (int64 glo, int64 ghi, int64 &lo, int64 &hi)
00083   {
00084 #ifdef _OPENMP
00085   calcShareGeneral (glo,ghi,omp_get_num_threads(),omp_get_thread_num(),lo,hi);
00086 #else
00087   lo=glo; hi=ghi;
00088 #endif
00089   }
00090 
00091 #endif

Generated on Thu Oct 8 14:48:51 2015 for LevelS C++ support library