Cleanup of print messages for MPI.

这个提交包含在:
Craig Warren
2017-03-02 15:57:39 +00:00
父节点 6b0c978747
当前提交 a8223aea27

查看文件

@@ -258,38 +258,46 @@ def run_mpi_sim(args, numbermodelruns, inputfile, usernamespace, optparams=None)
currentmodelrun = 1 currentmodelrun = 1
numworkers = size - 1 numworkers = size - 1
closedworkers = 0 closedworkers = 0
print('Master: PID {} on {} using {} workers.'.format(os.getpid(), name, numworkers)) print('MPI master rank {} (PID {}) on {} using {} workers'.format(rank, os.getpid(), name, numworkers))
while closedworkers < numworkers: while closedworkers < numworkers:
data = comm.recv(source=MPI.ANY_SOURCE, tag=MPI.ANY_TAG, status=status) data = comm.recv(source=MPI.ANY_SOURCE, tag=MPI.ANY_TAG, status=status)
source = status.Get_source() source = status.Get_source()
tag = status.Get_tag() tag = status.Get_tag()
if tag == tags.READY.value: # Worker is ready, so send it a task # Worker is ready, so send it a task
if tag == tags.READY.value:
if currentmodelrun < numbermodelruns + 1: if currentmodelrun < numbermodelruns + 1:
comm.send(currentmodelrun, dest=source, tag=tags.START.value) comm.send(currentmodelrun, dest=source, tag=tags.START.value)
print('Master: sending model {} to worker {}.'.format(currentmodelrun, source))
currentmodelrun += 1 currentmodelrun += 1
else: else:
comm.send(None, dest=source, tag=tags.EXIT.value) comm.send(None, dest=source, tag=tags.EXIT.value)
# Worker has completed a task
elif tag == tags.DONE.value: elif tag == tags.DONE.value:
print('Worker {}: completed.'.format(source)) pass
# Worker has completed all tasks
elif tag == tags.EXIT.value: elif tag == tags.EXIT.value:
print('Worker {}: exited.'.format(source)) print('MPI worker rank {} completed all tasks'.format(source))
closedworkers += 1 closedworkers += 1
# Worker process # Worker process
else: else:
print('Worker {}: PID {} on {}.'.format(rank, os.getpid(), name)) while True: # Break out of loop when work receives exit message
while True:
comm.send(None, dest=0, tag=tags.READY.value) comm.send(None, dest=0, tag=tags.READY.value)
currentmodelrun = comm.recv(source=0, tag=MPI.ANY_TAG, status=status) #  Receive a model number to run from the master currentmodelrun = comm.recv(source=0, tag=MPI.ANY_TAG, status=status) #  Receive a model number to run from the master
tag = status.Get_tag() tag = status.Get_tag()
# Run a model # Run a model
if tag == tags.START.value: if tag == tags.START.value:
if optparams: # If Taguchi optimistaion, add specific value for each parameter to optimise for each experiment to user accessible namespace
# Get info and setup device ID for GPU(s)
gpuinfo = ''
print('MPI worker rank {} (PID {}) starting model {}/{}{} on {}'.format(rank, os.getpid(), currentmodelrun, numbermodelruns, gpuinfo, name))
# If Taguchi optimistaion, add specific value for each parameter to optimise for each experiment to user accessible namespace
if optparams:
tmp = {} tmp = {}
tmp.update((key, value[currentmodelrun - 1]) for key, value in optparams.items()) tmp.update((key, value[currentmodelrun - 1]) for key, value in optparams.items())
modelusernamespace = usernamespace.copy() modelusernamespace = usernamespace.copy()
@@ -297,6 +305,7 @@ def run_mpi_sim(args, numbermodelruns, inputfile, usernamespace, optparams=None)
else: else:
modelusernamespace = usernamespace modelusernamespace = usernamespace
# Run the model
run_model(args, currentmodelrun, numbermodelruns, inputfile, modelusernamespace) run_model(args, currentmodelrun, numbermodelruns, inputfile, modelusernamespace)
comm.send(None, dest=0, tag=tags.DONE.value) comm.send(None, dest=0, tag=tags.DONE.value)