Main Page | Modules | Alphabetical List | Class List | File List | Class Members | File Members

openmp_support.h

00001 /*
00002  *  This file is part of Healpix_cxx.
00003  *
00004  *  Healpix_cxx 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  *  Healpix_cxx 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 Healpix_cxx; if not, write to the Free Software
00016  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00017  *
00018  *  For more information about HEALPix, see http://healpix.jpl.nasa.gov
00019  */
00020 
00021 /*
00022  *  Healpix_cxx is being developed at the Max-Planck-Institut fuer Astrophysik
00023  *  and financially supported by the Deutsches Zentrum fuer Luft- und Raumfahrt
00024  *  (DLR).
00025  */
00026 
00027 /*
00028  *  Copyright (C) 2005 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 inline int openmp_max_threads ()
00040   {
00041 #ifdef _OPENMP
00042   return omp_get_max_threads();
00043 #else
00044   return 1;
00045 #endif
00046   }
00047 
00048 inline int openmp_thread_num ()
00049   {
00050 #ifdef _OPENMP
00051   return omp_get_thread_num();
00052 #else
00053   return 0;
00054 #endif
00055   }
00056 
00057 /*! Calculates the range of indices between \a glo and \a ghi which
00058     must be processed by this thread and returns it in \a lo and \a hi.
00059 
00060     The indices \a ghi and \a hi are "one past the last real index",
00061     in analogy to the STL iterators. */
00062 inline void openmp_calc_share (int glo, int ghi, int &lo, int &hi)
00063   {
00064 #ifdef _OPENMP
00065   int nwork = ghi-glo;
00066   int nproc = omp_get_num_threads();
00067   int me = omp_get_thread_num();
00068   int nbase = nwork/nproc;
00069   int additional = nwork%nproc;
00070   lo = glo+me*nbase + ((me<additional) ? me : additional);
00071   hi = lo+nbase+(me<additional);
00072 #else
00073   lo=glo; hi=ghi;
00074 #endif
00075   }
00076 
00077 #endif

Generated on Fri Jul 8 09:37:14 2005 for LevelS C++ support library