Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass kwargs to pool constructor in choose_pool #4949

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions pycbc/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ def _dummy_broadcast(self, f, args):
self.map(f, [args] * self.size)

class SinglePool(object):

def __init__(self, **_):
pass

def broadcast(self, fcn, args):
return self.map(fcn, [args])

Expand Down Expand Up @@ -174,15 +178,18 @@ def use_mpi(require_mpi=False, log=True):
return use_mpi, size, rank


def choose_pool(processes, mpi=False):
""" Get processing pool
def choose_pool(processes, mpi=False, **kwargs):
""" Get processing pool.

Keyword arguments are passed to the pool constructor.
"""
do_mpi, size, rank = use_mpi(require_mpi=mpi)
if do_mpi:
try:
import schwimmbad
pool = schwimmbad.choose_pool(mpi=do_mpi,
processes=(size - 1))
processes=(size - 1),
**kwargs)
pool.broadcast = types.MethodType(_dummy_broadcast, pool)
atexit.register(pool.close)

Expand All @@ -197,11 +204,11 @@ def choose_pool(processes, mpi=False):
raise ValueError("Failed to start up an MPI pool, "
"install mpi4py / schwimmbad")
elif processes == 1:
pool = SinglePool()
pool = SinglePool(**kwargs)
else:
if processes == -1:
processes = cpu_count()
pool = BroadcastPool(processes)
pool = BroadcastPool(processes, **kwargs)

pool.size = processes
if size:
Expand Down
Loading