From 1a5efd87d8af1047cb25a2d5d031e1649597a287 Mon Sep 17 00:00:00 2001 From: mstorm <10544058+malte-storm@users.noreply.github.com> Date: Sat, 17 Aug 2019 00:58:15 +0100 Subject: [PATCH] BUG: Num processes exceeds number of slices (#444) This patch prevents extra python processes from being spawned when the amount of work to be done is less than the number of processes. --- source/tomopy/util/mproc.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/source/tomopy/util/mproc.py b/source/tomopy/util/mproc.py index 3b7147e76..4db12a948 100644 --- a/source/tomopy/util/mproc.py +++ b/source/tomopy/util/mproc.py @@ -141,8 +141,7 @@ def get_ncore_nchunk(axis_size, ncore=None, nchunk=None): def get_ncore_slices(axis_size, ncore=None, nchunk=None): # default ncore to max (also defaults ncore == 0) - if not ncore: - ncore = mp.cpu_count() + ncore = min(mp.cpu_count() if not ncore else ncore, axis_size) if nchunk is None: # calculate number of slices to send to each GPU chunk_size = axis_size // ncore