Replies: 3 comments 3 replies
-
I fixed the initializer problem. A minimum working example is given below. My main change is to let import time
from mpi4py.futures import MPIPoolExecutor
def simple_task(x):
time.sleep(0.2)
return x * x
def common_initializer():
# A basic initializer, doing almost nothing for now.
pass
def common_initializer2():
# A basic initializer, doing almost nothing for now.
pass
class MPIEvaluator:
def __init__(self, n_workers=None, initializer=common_initializer):
self._pool = None
self.n_workers = n_workers
self.initializer = initializer
def __enter__(self):
self._pool = MPIPoolExecutor(max_workers=self.n_workers, initializer=self.initializer)
print(f"MPI pool started with {self._pool._max_workers} workers")
return self
def map(self, fn, *iterables, timeout=None, chunksize=1, unordered=False):
return self._pool.map(fn, *iterables, timeout=timeout, chunksize=chunksize, unordered=unordered)
def __exit__(self, exc_type, exc_val, exc_tb):
if self._pool:
self._pool.shutdown(wait=True)
print("MPI pool has been shut down")
self._pool = None
def main():
# First use of the MPIEvaluator
with MPIEvaluator(n_workers=4) as pool:
results1 = list(pool.map(simple_task, range(10)))
print("First pool completed")
# Second use of the MPIEvaluator
with MPIEvaluator(n_workers=4, initializer=None) as pool:
results2 = list(pool.map(simple_task, range(20)))
print("Second pool completed")
if __name__ == "__main__":
main()
|
Beta Was this translation helpful? Give feedback.
-
I have started a new branch to do some testing with the initializer. A quick test on the lake model with 4 processes and 4000 experiments shows that the runtime goes from 14 seconds with the current version to just 4 seconds with the initializer. So, from a performance point of view, sending over the model only once and creating the experiment_runner only once really make a big difference. I am not yet sure about the drawbacks of being able to call an initializer only once. |
Beta Was this translation helpful? Give feedback.
-
Another twist in investigating this. We have been using This implies we need to update the tutorial. |
Beta Was this translation helpful? Give feedback.
-
A discussion to gather feedback on the MPIEvaluator and discuss future development.
This discussion will be linked in the official documentation as long as the MPIEvaluator is experimental.
Previous development and discussion
Includes most of the requirements and design discussions
Includes the prototyping and iteration of the first draft implementation
Includes the final implementation delivered, including extensive documentation
Includes a tutorial for using the MPIEvaluator, including an example for running on the DelftBlue SLURM-based system.
An extensive technical report on the MPIEvaluator is available: MPIEvaluatorTechnicalReport - 2023-11.pdf
Beta Was this translation helpful? Give feedback.
All reactions