Skip to content

Commit 4e2a475

Browse files
Fix nb of threads
1 parent 97102de commit 4e2a475

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

postprocess.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ def postproc():
4040
print(f"Mean result image written to [{mean_path}]")
4141

4242
print(f"Computing all correlations between [{size}] results...")
43-
correlations = postproc_srv.get_all_correlations(basedir, ids)
43+
nb_cores = len(os.sched_getaffinity(0))
44+
print(f"[{nb_cores}] cores available")
45+
correlations = postproc_srv.get_all_correlations(basedir, ids, nb_cores)
4446
correlations.to_csv(corr_path, index=False, sep=';')
4547
print(f"Correlations written to [{corr_path}]")
4648

@@ -53,7 +55,6 @@ def postproc():
5355
if __name__ == '__main__':
5456
now = datetime.now().strftime("%d-%m-%Y %H:%M:%S.%f")[:-3]
5557
print(f"Start [{now}]")
56-
print(f"[{len(os.sched_getaffinity(0))}] cores available")
5758
postproc()
5859
now = datetime.now().strftime("%d-%m-%Y %H:%M:%S.%f")[:-3]
5960
print(f"End [{now}]")

postprocess/postprocess_service.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,15 @@ def get_pairwise_correlation(self, src, tgt, path):
4444
jacc = self.corr_srv.get_correlation_coefficient(src_nii, tgt_nii, 'jaccard')
4545
return src, tgt, spear, pear, dice, jacc
4646

47-
def get_all_correlations(self, path, ids: List[str]) -> pd.DataFrame:
47+
def get_all_correlations(self, path, ids: List[str], nb_cores: int) -> pd.DataFrame:
4848
ids.append('mean')
49-
n = len(ids)
5049

5150
args = []
5251
for i in range(n):
5352
for j in range(i, n):
5453
args.append((ids[i], ids[j], path))
5554

56-
with Pool(processes=n) as pool:
55+
with Pool(processes=nb_cores) as pool:
5756
results = pool.starmap(self.get_pairwise_correlation, args)
5857

5958
data = []

0 commit comments

Comments
 (0)