Added parallelization to _project.pyx code

This commit is contained in:
Guilhem Lavaux 2014-06-11 11:14:33 +02:00
parent 5b133a9ac8
commit 401ddc8a8b
9 changed files with 173 additions and 122 deletions

View file

@ -1,8 +1,7 @@
from _cosmotool import *
from _project import *
from grafic import writeGrafic, writeWhitePhase, readGrafic
from grafic import writeGrafic, writeWhitePhase, readGrafic, readWhitePhase
from borg import read_borg_vol
from cic import cicParticles
from simu import loadRamsesAll, simpleWriteGadget, SimulationBare
from timing import timeit

View file

@ -42,9 +42,9 @@ def writeGrafic(filename, field, BoxSize, scalefac, **cosmo):
bad, bad, bad,
scalefac,
cosmo['omega_M_0'], cosmo['omega_lambda_0'], 100*cosmo['h'], checkPoint))
checkPoint = 4*Ny*Nx
checkPoint = 4*Ny*Nz
field = field.reshape(field.shape, order='F')
for i in xrange(Nz):
for i in xrange(Nx):
f.write(struct.pack("I", checkPoint))
f.write(field[i].astype(np.float32).tostring())
f.write(struct.pack("I", checkPoint))
@ -58,9 +58,29 @@ def writeWhitePhase(filename, field):
checkPoint = 4*4
f.write(struct.pack("IIIIII", checkPoint, Nx, Ny, Nz, 0, checkPoint))
checkPoint = struct.pack("I", 4*Ny*Nz)
field = field.reshape(field.shape, order='F')
checkPoint = struct.pack("I", 4*Nx*Ny)
for i in xrange(Nx):
f.write(checkPoint)
f.write(field[i].astype(np.float32).tostring())
f.write(checkPoint)
def readWhitePhase(filename):
with file(filename, mode="rb") as f:
_, Nx, Ny, Nz, _, _ = struct.unpack("IIIIII", f.read(4*4+2*4))
a = np.empty((Nx,Ny,Nz), dtype=np.float32)
checkPoint_ref = 4*Ny*Nz
for i in xrange(Nx):
if struct.unpack("I", f.read(4))[0] != checkPoint_ref:
raise ValueError("Invalid unformatted access")
a[i, :, :] = np.fromfile(f, dtype=np.float32, count=Ny*Nz).reshape((Ny, Nz), order='F')
if struct.unpack("I", f.read(4))[0] != checkPoint_ref:
raise ValueError("Invalid unformatted access")
return a

View file

@ -0,0 +1,15 @@
import time
def timeit(method):
def timed(*args, **kw):
ts = time.time()
result = method(*args, **kw)
te = time.time()
print '%r (%r, %r) %2.2f sec' % \
(method.__name__, args, kw, te-ts)
return result
return timed