Skip to content

Commit

Permalink
🐛 Respect n_workers in max_chunks_per_worker (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
ddelange committed Sep 29, 2022
1 parent cd77bd8 commit b1af9c3
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/mapply/mapply.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ def _choose_n_chunks(
"""Choose final amount of chunks to be sent to the ProcessPool."""
# no sense running parallel if data is too small
n_chunks = int(shape[axis] / chunk_size)
if n_workers < 1:
n_workers = N_CORES

if max_chunks_per_worker:
# no sense making too many chunks
n_chunks = min(n_chunks, max_chunks_per_worker * N_CORES)
n_chunks = min(n_chunks, max_chunks_per_worker * n_workers)
if n_chunks < 1 or n_workers == 1 or N_CORES == 1:
# no sense running parallel
n_chunks = 1
Expand Down

0 comments on commit b1af9c3

Please sign in to comment.