Skip to content

Commit

Permalink
Calculate parallel and master_node flags in RLparallelscript.py
Browse files Browse the repository at this point in the history
  • Loading branch information
avalluvan committed Dec 16, 2024
1 parent 7a2f65c commit 17aae47
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
9 changes: 8 additions & 1 deletion cosipy/image_deconvolution/RLparallelscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,15 @@ def main():
parameter_filepath = DATA_DIR / 'imagedeconvolution_parfile_gal_511keV.yml'
image_deconvolution.read_parameterfile(parameter_filepath)

parallel_computation = True
if comm.Get_rank() == MASTER:
master_node = True
else:
master_node = False

# Initialize model
image_deconvolution.initialize(comm=comm)
image_deconvolution.initialize(parallel_computation = parallel_computation,
master_node = master_node)

# Execute deconvolution
image_deconvolution.run_deconvolution()
Expand Down
6 changes: 3 additions & 3 deletions cosipy/image_deconvolution/RichardsonLucy.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,9 @@ def finalization(self):
for this_result in self.results:
iteration_count = this_result["iteration"]

this_result["model"].write(f"{self.save_results_directory}/model_itr{iteration_count}_2.hdf5", overwrite = True)
this_result["delta_model"].write(f"{self.save_results_directory}/delta_model_itr{iteration_count}_2.hdf5", overwrite = True)
this_result["processed_delta_model"].write(f"{self.save_results_directory}/processed_delta_model_itr{iteration_count}_2.hdf5", overwrite = True)
this_result["model"].write(f"{self.save_results_directory}/model_itr{iteration_count}.hdf5", overwrite = True)
this_result["delta_model"].write(f"{self.save_results_directory}/delta_model_itr{iteration_count}.hdf5", overwrite = True)
this_result["processed_delta_model"].write(f"{self.save_results_directory}/processed_delta_model_itr{iteration_count}.hdf5", overwrite = True)

#fits
primary_hdu = fits.PrimaryHDU()
Expand Down
16 changes: 3 additions & 13 deletions cosipy/image_deconvolution/image_deconvolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
from .RichardsonLucy import RichardsonLucy
from .RichardsonLucySimple import RichardsonLucySimple

# MPI Master node
MASTER = 0

class ImageDeconvolution:
"""
A class to reconstruct all-sky images from COSI data based on image deconvolution methods.
Expand Down Expand Up @@ -121,21 +118,14 @@ def results(self):
"""
return self._deconvolution.results

def initialize(self, comm = None): # comm is required if the user intends to use parallel features
def initialize(self, parallel_computation = False, master_node = True):
"""
Initialize an initial model and an image deconvolution algorithm.
It is mandatory to execute this method before running the image deconvolution.
"""

if comm is None:
self.parallel_computation = False
self.master_node = True
elif comm.Get_rank() == MASTER:
self.parallel_computation = True
self.master_node = True
else:
self.parallel_computation = True
self.master_node = False
self.parallel_computation = parallel_computation
self.master_node = master_node

logger.info("#### Initialization Starts ####")

Expand Down

0 comments on commit 17aae47

Please sign in to comment.