Fix parallelization of the projector to make a proper reporting of the progress

This commit is contained in:
Guilhem Lavaux 2014-06-12 15:29:36 +02:00
parent 0aeb0d80c3
commit 6967a1f55c
2 changed files with 19 additions and 3 deletions

View File

@ -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()

View File

@ -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