openmp_support.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
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
00067
00068
00069
00070
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