Skip to content

Commit 473ad10

Browse files
committed
parallelize write
1 parent 9243642 commit 473ad10

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

lya_2pt/interface.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,23 @@ def run(self, healpix_ids=None):
235235

236236
def write_results(self):
237237
if self.config['compute'].getboolean('compute-correlation', False):
238-
for healpix_id, result in self.xi_output.items():
239-
self.output.write_cf_healpix(result, healpix_id, self.config, self.settings)
238+
if self.num_cpu > 1:
239+
with multiprocessing.Pool(processes=self.num_cpu) as pool:
240+
arguments = [(result, healpix_id, self.config, self.settings)
241+
for healpix_id, result in self.xi_output.items()]
242+
_ = pool.starmap(self.output.write_cf_healpix, arguments)
243+
else:
244+
for healpix_id, result in self.xi_output.items():
245+
self.output.write_cf_healpix(result, healpix_id, self.config, self.settings)
240246

241247
if self.config['compute'].getboolean('compute-distortion-matrix', False):
242-
for healpix_id, result in self.dmat_output.items():
243-
self.output.write_dmat_healpix(result, healpix_id, self.config, self.settings)
248+
if self.num_cpu > 1:
249+
with multiprocessing.Pool(processes=self.num_cpu) as pool:
250+
arguments = [(result, healpix_id, self.config, self.settings)
251+
for healpix_id, result in self.dmat_output.items()]
252+
_ = pool.starmap(self.output.write_dmat_healpix, arguments)
253+
else:
254+
for healpix_id, result in self.dmat_output.items():
255+
self.output.write_dmat_healpix(result, healpix_id, self.config, self.settings)
244256

245257
# TODO: add other modes

0 commit comments

Comments
 (0)