From 6967a1f55cbd44d697312d4b7dcd0dbd585676eb Mon Sep 17 00:00:00 2001 From: Guilhem Lavaux Date: Thu, 12 Jun 2014 15:29:36 +0200 Subject: [PATCH] Fix parallelization of the projector to make a proper reporting of the progress --- python/_project.pyx | 20 ++++++++++++++++++-- python_sample/icgen/gen_ic_from_borg.py | 2 +- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/python/_project.pyx b/python/_project.pyx index 138eaa2..de3f952 100644 --- a/python/_project.pyx +++ b/python/_project.pyx @@ -731,6 +731,18 @@ cdef double _spherical_projloop(double theta, double phi, DTYPE_t[:,:,:] density return C_line_of_sight_projection(density, u0, min_distance, max_distance, shifter, integrator_id) +@cython.boundscheck(False) +cdef npx.uint64_t _mysum(int[:] jobs) nogil: + cdef npx.uint64_t s + cdef npx.uint64_t N + cdef int i + + s = 0 + N = jobs.shape[0] + for i in xrange(N): + s += jobs[i] + return s + @cython.boundscheck(False) def spherical_projection(int Nside, @@ -744,6 +756,7 @@ def spherical_projection(int Nside, cdef DTYPE_t[:] theta,phi cdef DTYPE_t[:,:,:] density_view cdef DTYPE_t[:] outm + cdef int[:] job_done cdef npx.ndarray[DTYPE_t, ndim=1] outm_array cdef long N cdef double stheta @@ -760,14 +773,17 @@ def spherical_projection(int Nside, p = pb.ProgressBar(maxval=outm.size,widgets=[pb.BouncingBar(), pb.ETA()]).start() N = outm.size + job_done = view.array(shape=(1,), format="i", itemsize=sizeof(int)) + job_done[:] = 0 theta,phi = hp.pix2ang(Nside, np.arange(N)) with nogil, parallel(): for i in prange(N): if progress != 0 and (i%booster) == 0: with gil: - p.update(i) + p.update(_mysum(job_done)) outm[i] = _spherical_projloop(theta[i], phi[i], density_view, min_distance, max_distance, shifter, integrator_id) - + job_done[i] = 1 + if progress: p.finish() diff --git a/python_sample/icgen/gen_ic_from_borg.py b/python_sample/icgen/gen_ic_from_borg.py index aced412..bae7b12 100644 --- a/python_sample/icgen/gen_ic_from_borg.py +++ b/python_sample/icgen/gen_ic_from_borg.py @@ -9,7 +9,7 @@ cosmo['omega_B_0']=0.049 cosmo['SIGMA8']=0.8344 cosmo['ns']=0.9624 -supergen=4 +supergen=8 zstart=50 astart=1/(1.+zstart) halfPixelShift=False