Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. # Return a decorator that runs the function only if rank == 0,
  2. # otherwise waits for a broadcast from rank 0
  3. def broadcast_from_zero(rank, comm, root=0):
  4. def decorator(func):
  5. @functools.wraps(func)
  6. def wrapped(*args, **kwargs):
  7. if comm is None:
  8. return func(*args, **kwargs)
  9.  
  10. if rank == root:
  11. val = func(*args, **kwargs)
  12. else:
  13. val = None
  14. comm.bcast(val, root=root)
  15. return val
  16. return wrapped
  17. return decorator
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement