From b662fcb763488121a95a2b73d2e83c1c0abb8d70 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Sat, 21 May 2022 12:11:34 +0300 Subject: Use multiprocessing to improve performance --- gn3/computations/partial_correlations.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'gn3') diff --git a/gn3/computations/partial_correlations.py b/gn3/computations/partial_correlations.py index c12b4ec..530dd71 100644 --- a/gn3/computations/partial_correlations.py +++ b/gn3/computations/partial_correlations.py @@ -7,6 +7,7 @@ GeneNetwork1. import math import warnings +from multiprocessing import Pool, cpu_count from functools import reduce, partial from typing import Any, Tuple, Union, Sequence, Generator @@ -325,11 +326,15 @@ def compute_partial( This implementation reworks the child function `compute_partial` which will then be used in the place of `determinPartialsByR`. """ - return ( - result for result in ( - compute_trait_info( - primary_vals, control_vals, (target[data_start_pos:], target[0]), method) - for target in targets) + with Pool(processes=(cpu_count() - 1)) as pool: + return ( + result for result in ( + pool.starmap( + compute_trait_info, + (( + primary_vals, control_vals, + (target[data_start_pos:], target[0]), method) + for target in targets))) if result is not None) def partial_correlations_normal(# pylint: disable=R0913 -- cgit v1.2.3