def __init__(self, comm=None, loadbalance=False, debug=False,
wait_on_start = True, exit_on_end = True,
cores_per_task = 1, **kwargs):
if MPI is None:
raise ImportError("Please install mpi4py")
self.comm = MPI.COMM_WORLD if comm is None else comm
self.rank = self.comm.Get_rank()
if cores_per_task > 1:
self.size = max(1, self.comm.Get_size() // cores_per_task)
else:
self.size = self.comm.Get_size() - 1
self.function = _error_function
self.loadbalance = loadbalance
self.debug = debug
if self.size == 0:
raise ValueError("Tried to create an MPI pool, but there "
"was only one MPI process available. "
"Need at least two.")
self.exit_on_end = exit_on_end
# Enter main loop for workers?
if wait_on_start:
if self.is_worker():
self.wait()
评论列表
文章目录