Fixed openmp usage

This commit is contained in:
Guilhem Lavaux 2015-02-10 14:20:09 +01:00
parent ab36a5b24a
commit 8198cef3c5
3 changed files with 10 additions and 7 deletions

View File

@ -6,7 +6,6 @@ import numpy as np
cimport numpy as npx cimport numpy as npx
cimport cython cimport cython
from copy cimport * from copy cimport *
from openmp cimport omp_get_max_threads, omp_get_thread_num
ctypedef npx.float64_t DTYPE_t ctypedef npx.float64_t DTYPE_t
DTYPE=np.float64 DTYPE=np.float64
@ -18,6 +17,10 @@ cdef extern from "project_tool.hpp" namespace "":
DTYPE_t compute_projection(DTYPE_t *vertex_value, DTYPE_t *u, DTYPE_t *u0, DTYPE_t rho) nogil DTYPE_t compute_projection(DTYPE_t *vertex_value, DTYPE_t *u, DTYPE_t *u0, DTYPE_t rho) nogil
cdef extern from "openmp.hpp" namespace "CosmoTool":
int smp_get_max_threads() nogil
int smp_get_thread_id() nogil
@cython.boundscheck(False) @cython.boundscheck(False)
@cython.cdivision(True) @cython.cdivision(True)
@ -850,7 +853,7 @@ def spherical_projection(int Nside,
if progress != 0: if progress != 0:
p = pb.ProgressBar(maxval=outm.size,widgets=[pb.Bar(), pb.ETA()]).start() p = pb.ProgressBar(maxval=outm.size,widgets=[pb.Bar(), pb.ETA()]).start()
N = omp_get_max_threads() N = smp_get_max_threads()
N0 = outm.size N0 = outm.size
if booster < 0: if booster < 0:
@ -860,7 +863,7 @@ def spherical_projection(int Nside,
job_done[:] = 0 job_done[:] = 0
theta,phi = hp.pix2ang(Nside, np.arange(N0)) theta,phi = hp.pix2ang(Nside, np.arange(N0))
with nogil, parallel(): with nogil, parallel():
tid = omp_get_thread_num() tid = smp_get_thread_id()
for i in prange(N0): for i in prange(N0):
if progress != 0 and (i%booster) == 0: if progress != 0 and (i%booster) == 0:
with gil: with gil:

View File

@ -9,10 +9,10 @@ SET(CosmoTool_SRCS
miniargs.cpp miniargs.cpp
growthFactor.cpp growthFactor.cpp
cosmopower.cpp cosmopower.cpp
cic.cpp
) )
IF (ENABLE_OPENMP) IF (ENABLE_OPENMP)
set(CosmoTool_SRCS ${CosmoTool_SRCS} cic.cpp)
ENDIF (ENABLE_OPENMP) ENDIF (ENABLE_OPENMP)
IF(FOUND_NETCDF3) IF(FOUND_NETCDF3)

View File

@ -32,7 +32,7 @@ same conditions as regards security.
The fact that you are presently reading this means that you have had The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms. knowledge of the CeCILL license and that you accept its terms.
+*/ +*/
#include <omp.h> #include "openmp.hpp"
#include <assert.h> #include <assert.h>
#include <math.h> #include <math.h>
#include <inttypes.h> #include <inttypes.h>
@ -62,7 +62,7 @@ void CICFilter::resetMesh()
void CICFilter::putParticles(CICParticles *particles, uint32_t N) void CICFilter::putParticles(CICParticles *particles, uint32_t N)
{ {
int threadUsed = omp_get_max_threads(); int threadUsed = smp_get_max_threads();
double *threadedDensity[threadUsed]; double *threadedDensity[threadUsed];
bool threadActivated[threadUsed]; bool threadActivated[threadUsed];
uint32_t tUsedMin[threadUsed], tUsedMax[threadUsed]; uint32_t tUsedMin[threadUsed], tUsedMax[threadUsed];
@ -79,7 +79,7 @@ void CICFilter::putParticles(CICParticles *particles, uint32_t N)
#pragma omp parallel #pragma omp parallel
{ {
int thisThread = omp_get_thread_num(); int thisThread = smp_get_thread_id();
double *dg = threadedDensity[thisThread]; double *dg = threadedDensity[thisThread];
threadActivated[thisThread] = true; threadActivated[thisThread] = true;