Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
adrn authored Aug 23, 2024
1 parent 4c2006c commit 7b9d8f5
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions schwimmbad/mpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def wait(self, callback=None):
if callback is not None:
callback()

def map(self, worker, tasks, callback=None, tasklistback=True):
def map(self, worker, tasks, callback=None, return_results=True):
"""Evaluate a function or callable on each task in parallel using MPI.
The callable, ``worker``, is called on each element of the ``tasks``
Expand All @@ -156,14 +156,14 @@ def map(self, worker, tasks, callback=None, tasklistback=True):
result from each worker run and is executed on the master process.
This is useful for, e.g., saving results to a file, since the
callback is only called on the master thread.
tasklistback : bool
An option to save memory in the parallel calculations.
return_results : bool, optional
An option to disable returning the full result list, which can save memory usage in the parallel calculations when large results are returned.
Returns
-------
results : list
A list of results from the output of each ``worker()`` call.
If tasklistback = False, return [None] * len(tasklist)
But if `return_results = False`, this function returns `None`.
"""

# If not the master just wait for instructions.
Expand Down Expand Up @@ -205,11 +205,14 @@ def map(self, worker, tasks, callback=None, tasklistback=True):
callback(result)

workerset.add(worker)
if tasklistback:
if return_results:
resultlist[taskid] = result
pending -= 1

return resultlist
if return_results:
return resultlist
else:
return None

def close(self):
""" Tell all the workers to quit."""
Expand Down

0 comments on commit 7b9d8f5

Please sign in to comment.