def parallel_root_only(func):
"""
This decorator blocks and calls the function on the root processor,
but does not broadcast results to the other processors.
"""
@wraps(func)
def root_only(*args, **kwargs):
if not parallel_capable:
return func(*args, **kwargs)
comm = _get_comm(args)
rv = None
if comm.rank == 0:
try:
rv = func(*args, **kwargs)
all_clear = 1
except Exception:
traceback.print_last()
all_clear = 0
else:
all_clear = None
all_clear = comm.mpi_bcast(all_clear)
if not all_clear: raise RuntimeError
return rv
return root_only
评论列表
文章目录