Skip to content

Commit

Permalink
Merge pull request #258 from nickhand/master
Browse files Browse the repository at this point in the history
read config files on root before bcast in nbkit-batch
  • Loading branch information
nickhand committed Oct 26, 2016
2 parents 36c282c + 2e6671a commit 65aa914
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions bin/nbkit-batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,14 +331,12 @@ def compute_one_task(self, itask, task):
a tuple of values representing this task value
"""
# if you are the pool's root, write out the temporary parameter file
this_config = None
config_stream = None
if self.workers.subcomm.rank == 0:

# initialize a temporary file
with tempfile.NamedTemporaryFile(delete=False) as ff:

this_config = ff.name
logger.debug("creating temporary file: %s" %this_config)
with tempfile.TemporaryFile() as ff:
logger.debug("creating temporary file: %s" %ff.name)

# key/values for this task
if len(self.task_dims) == 1:
Expand All @@ -360,12 +358,16 @@ def compute_one_task(self, itask, task):
# do the string formatting if the key is present in template
valid = {k:possible_kwargs[k] for k in possible_kwargs if k in kwargs}
ff.write(formatter.format(self.template, **valid).encode())

# read temp file as config stream
ff.seek(0)
config_stream = ff.read()

# bcast the file name to all in the worker pool
this_config = self.workers.subcomm.bcast(this_config, root=0)
# bcast the file stream to all in the worker pool
config_stream = self.workers.subcomm.bcast(config_stream, root=0)

# configuration file passed via -c
params, extra = ReadConfigFile(open(this_config, 'r').read(), self.algorithm_class.schema)
params, extra = ReadConfigFile(config_stream, self.algorithm_class.schema)

# output is required
output = getattr(extra, 'output', None)
Expand All @@ -379,9 +381,9 @@ def compute_one_task(self, itask, task):

# remove temporary files
if self.workers.subcomm.rank == 0:
if os.path.exists(this_config):
logger.debug("removing temporary file: %s" %this_config)
os.remove(this_config)
if os.path.exists(ff.name):
logger.debug("removing temporary file: %s" %ff.name)
os.remove(ff.name)

return 0

Expand Down

0 comments on commit 65aa914

Please sign in to comment.