NASA - Jet Propulsion Laboratory
    + View the NASA Portal
Search JPL
Jet Propulsion Laboratory Home Earth Solar System Stars & Galaxies Technology
Introduction Background Software Links

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, 2006, 2007 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 bool openmp_enabled()
00040   {
00041 #ifdef _OPENMP
00042   return true;
00043 #else
00044   return false;
00045 #endif
00046   }
00047 
00048 inline int openmp_max_threads ()
00049   {
00050 #ifdef _OPENMP
00051   return omp_get_max_threads();
00052 #else
00053   return 1;
00054 #endif
00055   }
00056 
00057 inline int openmp_thread_num ()
00058   {
00059 #ifdef _OPENMP
00060   return omp_get_thread_num();
00061 #else
00062   return 0;
00063 #endif
00064   }
00065 
00066 /*! Calculates the range of indices between \a glo and \a ghi which
00067     must be processed by this thread and returns it in \a lo and \a hi.
00068 
00069     The indices \a ghi and \a hi are "one past the last real index",
00070     in analogy to the STL iterators. */
00071 inline void openmp_calc_share (int glo, int ghi, int &lo, int &hi)
00072   {
00073 #ifdef _OPENMP
00074   int nwork = ghi-glo;
00075   int nproc = omp_get_num_threads();
00076   int me = omp_get_thread_num();
00077   int nbase = nwork/nproc;
00078   int additional = nwork%nproc;
00079   lo = glo+me*nbase + ((me<additional) ? me : additional);
00080   hi = lo+nbase+(me<additional);
00081 #else
00082   lo=glo; hi=ghi;
00083 #endif
00084   }
00085 
00086 #endif

Generated on Fri Jun 18 16:12:29 2010 for LevelS C++ support library
Privacy / Copyright
FIRST GOV Contact: NASA Home Page Site Manager:
Webmaster:

CL 03-2650