From 5093212ec0a40fc6c4763fd8960bb7f4ae7a8230 Mon Sep 17 00:00:00 2001 From: Guilhem Lavaux Date: Tue, 3 Apr 2018 11:28:29 +0200 Subject: [PATCH] Release the GIL --- python/_project.pyx | 49 ++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/python/_project.pyx b/python/_project.pyx index 1f8f234..4b1d1dd 100644 --- a/python/_project.pyx +++ b/python/_project.pyx @@ -385,8 +385,8 @@ def interp2d(x not None, y not None, @cython.boundscheck(False) @cython.cdivision(True) -cdef void INTERNAL_project_cic_no_mass(npx.ndarray[DTYPE_t, ndim=3] g, - npx.ndarray[DTYPE_t, ndim=2] x, int Ngrid, double Lbox, double shifter): +cdef void INTERNAL_project_cic_no_mass(DTYPE_t[:,:,:] g, + DTYPE_t[:,:] x, int Ngrid, double Lbox, double shifter) nogil: cdef double delta_Box = Ngrid/Lbox cdef int i cdef double a[3] @@ -418,8 +418,8 @@ cdef void INTERNAL_project_cic_no_mass(npx.ndarray[DTYPE_t, ndim=3] g, @cython.boundscheck(False) @cython.cdivision(True) -cdef void INTERNAL_project_cic_no_mass_periodic(npx.ndarray[DTYPE_t, ndim=3] g, - npx.ndarray[DTYPE_t, ndim=2] x, int Ngrid, double Lbox, double shifter): +cdef void INTERNAL_project_cic_no_mass_periodic(DTYPE_t[:,:,:] g, + DTYPE_t[:,:] x, int Ngrid, double Lbox, double shifter) nogil: cdef double delta_Box = Ngrid/Lbox cdef int i cdef double a[3] @@ -459,10 +459,10 @@ cdef void INTERNAL_project_cic_no_mass_periodic(npx.ndarray[DTYPE_t, ndim=3] g, @cython.boundscheck(False) @cython.cdivision(True) -cdef void INTERNAL_project_cic_with_mass(npx.ndarray[DTYPE_t, ndim=3] g, - npx.ndarray[DTYPE_t, ndim=2] x, - npx.ndarray[DTYPE_t, ndim=1] mass, - int Ngrid, double Lbox, double shifter): +cdef void INTERNAL_project_cic_with_mass(DTYPE_t[:,:,:] g, + DTYPE_t[:,:] x, + DTYPE_t[:] mass, + int Ngrid, double Lbox, double shifter) nogil: cdef double delta_Box = Ngrid/Lbox cdef int i cdef double a[3] @@ -496,10 +496,10 @@ cdef void INTERNAL_project_cic_with_mass(npx.ndarray[DTYPE_t, ndim=3] g, @cython.boundscheck(False) @cython.cdivision(True) -cdef void INTERNAL_project_cic_with_mass_periodic(npx.ndarray[DTYPE_t, ndim=3] g, - npx.ndarray[DTYPE_t, ndim=2] x, - npx.ndarray[DTYPE_t, ndim=1] mass, - int Ngrid, double Lbox, double shifter): +cdef void INTERNAL_project_cic_with_mass_periodic(DTYPE_t[:,:,:] g, + DTYPE_t[:,:] x, + DTYPE_t[:] mass, + int Ngrid, double Lbox, double shifter) nogil: cdef double half_Box = 0.5*Lbox, m0 cdef double delta_Box = Ngrid/Lbox cdef int i @@ -544,6 +544,9 @@ def project_cic(npx.ndarray[DTYPE_t, ndim=2] x not None, npx.ndarray[DTYPE_t, nd """ cdef npx.ndarray[DTYPE_t, ndim=3] g cdef double shifter + cdef bool local_periodic + + local_periodic = periodic if centered: shifter = 0.5*Lbox @@ -558,16 +561,20 @@ def project_cic(npx.ndarray[DTYPE_t, ndim=2] x not None, npx.ndarray[DTYPE_t, nd g = np.zeros((Ngrid,Ngrid,Ngrid),dtype=DTYPE) - if not periodic: - if mass is None: - INTERNAL_project_cic_no_mass(g, x, Ngrid, Lbox, shifter) - else: - INTERNAL_project_cic_with_mass(g, x, mass, Ngrid, Lbox, shifter) + if not local_periodic: + if mass is None: + with nogil: + INTERNAL_project_cic_no_mass(g, x, Ngrid, Lbox, shifter) + else: + with nogil: + INTERNAL_project_cic_with_mass(g, x, mass, Ngrid, Lbox, shifter) else: - if mass is None: - INTERNAL_project_cic_no_mass_periodic(g, x, Ngrid, Lbox, shifter) - else: - INTERNAL_project_cic_with_mass_periodic(g, x, mass, Ngrid, Lbox, shifter) + if mass is None: + with nogil: + INTERNAL_project_cic_no_mass_periodic(g, x, Ngrid, Lbox, shifter) + else: + with nogil: + INTERNAL_project_cic_with_mass_periodic(g, x, mass, Ngrid, Lbox, shifter) return g