From f06d22e02c43e076e66b19ddcc76506bbefcae2a Mon Sep 17 00:00:00 2001 From: Zhang Yunjun Date: Wed, 2 Sep 2020 12:33:13 -0700 Subject: [PATCH] topsStack/topo: use OMP_NUM_THREADS if available for the parallel processing with multiprocessing.Pool() --- contrib/stack/topsStack/topo.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/contrib/stack/topsStack/topo.py b/contrib/stack/topsStack/topo.py index 328b367..958e2b7 100755 --- a/contrib/stack/topsStack/topo.py +++ b/contrib/stack/topsStack/topo.py @@ -97,7 +97,12 @@ def main(iargs=None): for ind in range(reference.numberOfBursts): inputs.append((dirname, demImage, reference, ind)) - pool = mp.Pool(mp.cpu_count()) + # parallel processing + numThread = int(os.environ.get('OMP_NUM_THREADS', mp.cpu_count())) + numThread = min(numThread, mp.cpu_count()) + print('running in parallel with {} processes'.format(numThread)) + + pool = mp.Pool(numThread) results = pool.map(call_topo, inputs) pool.close() @@ -106,7 +111,7 @@ def main(iargs=None): boxes = np.array(boxes) bbox = [np.min(boxes[:,0]), np.max(boxes[:,1]), np.min(boxes[:,2]), np.max(boxes[:,3])] - print ('bbox : ',bbox) + print('bbox : ', bbox) if __name__ == '__main__':