Skip to content

Commit d538ee2

Browse files
committed
add support for mpi4py
1 parent 1debc15 commit d538ee2

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

adaptive/runner.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@
2626
except ModuleNotFoundError:
2727
with_distributed = False
2828

29+
try:
30+
import mpi4py.futures
31+
with_mpi4py = True
32+
except ModuleNotFoundError:
33+
with_mpi4py = False
34+
2935
with suppress(ModuleNotFoundError):
3036
import uvloop
3137
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
@@ -66,7 +72,7 @@ class BaseRunner(metaclass=abc.ABCMeta):
6672
the learner as its sole argument, and return True when we should
6773
stop requesting more points.
6874
executor : `concurrent.futures.Executor`, `distributed.Client`,\
69-
or `ipyparallel.Client`, optional
75+
`mpi4py.futures.MPIPoolExecutor`, or `ipyparallel.Client`, optional
7076
The executor in which to evaluate the function to be learned.
7177
If not provided, a new `~concurrent.futures.ProcessPoolExecutor`
7278
is used on Unix systems while on Windows a `distributed.Client`
@@ -281,7 +287,7 @@ class BlockingRunner(BaseRunner):
281287
the learner as its sole argument, and return True when we should
282288
stop requesting more points.
283289
executor : `concurrent.futures.Executor`, `distributed.Client`,\
284-
or `ipyparallel.Client`, optional
290+
`mpi4py.futures.MPIPoolExecutor`, or `ipyparallel.Client`, optional
285291
The executor in which to evaluate the function to be learned.
286292
If not provided, a new `~concurrent.futures.ProcessPoolExecutor`
287293
is used on Unix systems while on Windows a `distributed.Client`
@@ -386,7 +392,7 @@ class AsyncRunner(BaseRunner):
386392
stop requesting more points. If not provided, the runner will run
387393
forever, or until ``self.task.cancel()`` is called.
388394
executor : `concurrent.futures.Executor`, `distributed.Client`,\
389-
or `ipyparallel.Client`, optional
395+
`mpi4py.futures.MPIPoolExecutor`, or `ipyparallel.Client`, optional
390396
The executor in which to evaluate the function to be learned.
391397
If not provided, a new `~concurrent.futures.ProcessPoolExecutor`
392398
is used on Unix systems while on Windows a `distributed.Client`
@@ -693,6 +699,9 @@ def _get_ncores(ex):
693699
return 1
694700
elif with_distributed and isinstance(ex, distributed.cfexecutor.ClientExecutor):
695701
return sum(n for n in ex._client.ncores().values())
702+
elif with_mpi4py and isinstance(ex, mpi4py.futures.MPIPoolExecutor):
703+
ex.bootup() # wait until all workers are up and running
704+
return ex._pool.size # not public API!
696705
else:
697706
raise TypeError('Cannot get number of cores for {}'
698707
.format(ex.__class__))

0 commit comments

Comments
 (0)