Skip to content

Commit

Permalink
automatic default Nfile.
Browse files Browse the repository at this point in the history
  • Loading branch information
rainwoodman committed Jul 28, 2016
1 parent 8984220 commit 0132f46
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions nbodykit/plugins/algorithms/PaintGrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class PaintGridAlgorithm(Algorithm):
"""
plugin_name = "PaintGrid"

def __init__(self, Nmesh, DataSource, Painter=None, paintbrush='cic', dataset='PaintGrid', Nfile=1):
def __init__(self, Nmesh, DataSource, Painter=None, paintbrush='cic', dataset='PaintGrid', Nfile=0):
# combine the two fields
self.datasource = DataSource
if Painter is None:
Expand Down Expand Up @@ -91,11 +91,17 @@ def save(self, output, result):
x3d = x3d.ravel()
ind = ind.ravel()
mpsort.sort(x3d, orderby=ind, comm=self.comm)
if self.Nfile == 0:
chunksize = 1024 * 1024 * 512
Nfile = (self.Nmesh * self.Nmesh * self.Nmesh + chunksize - 1)// chunksize
else:
Nfile = self.Nfile

if self.comm.rank == 0:
self.logger.info("writing to %s/%s in %d parts" % (output, self.dataset, self.Nfile))
self.logger.info("writing to %s/%s in %d parts" % (output, self.dataset, Nfile))

f = bigfile.BigFileMPI(self.comm, output, create=True)
b = f.create_from_array(self.dataset, x3d, Nfile=self.Nfile)
b = f.create_from_array(self.dataset, x3d, Nfile=Nfile)
b.attrs['ndarray.shape'] = numpy.array([self.Nmesh, self.Nmesh, self.Nmesh], dtype='i8')
b.attrs['BoxSize'] = numpy.array(self.datasource.BoxSize, dtype='f8')
b.attrs['Nmesh'] = self.Nmesh
Expand Down

0 comments on commit 0132f46

Please sign in to comment.