Skip to content

Commit

Permalink
Incorporated review suggestions about placement of parallel_computati…
Browse files Browse the repository at this point in the history
…on and master_node flags
  • Loading branch information
avalluvan committed Dec 16, 2024
1 parent b99ff6a commit cddaa24
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 460 deletions.
6 changes: 3 additions & 3 deletions cosipy/image_deconvolution/RLparallelscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from histpy import Histogram

from cosipy.response import FullDetectorResponse
from cosipy.image_deconvolution import ImageDeconvolution, DataIFWithParallel, DataIF_COSI_DC2
from cosipy.image_deconvolution import ImageDeconvolution, DataIF_Parallel, DataIF_COSI_DC2

# Define MPI variables
MASTER = 0 # Indicates master process
Expand All @@ -17,14 +17,14 @@
def main():
'''
Main script to create a parallel execution-compatible
dataset using DataIFWithParallel and call ImageDeconvolution
dataset using DataIF_Parallel and call ImageDeconvolution
'''

# Set up MPI
comm = MPI.COMM_WORLD

# Create dataset
dataset = DataIFWithParallel(name = '511keV',
dataset = DataIF_Parallel(name = '511keV',
event_filename = '511keV_dc2_galactic_event.hdf5',
bkg_filename = '511keV_dc2_galactic_bkg.hdf5',
drm_filename = 'psr_gal_511_DC2.h5',
Expand Down
19 changes: 8 additions & 11 deletions cosipy/image_deconvolution/RichardsonLucy.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class RichardsonLucy(DeconvolutionAlgorithmBase):
"""

def __init__(self, initial_model:Histogram, dataset:list, mask, parameter, comm=None):
def __init__(self, initial_model:Histogram, dataset:list, mask, parameter,
parallel:bool=False, MASTER:bool=False):

DeconvolutionAlgorithmBase.__init__(self, initial_model, dataset, mask, parameter)

Expand Down Expand Up @@ -70,20 +71,16 @@ def __init__(self, initial_model:Histogram, dataset:list, mask, parameter, comm=
else:
os.makedirs(self.save_results_directory)

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

def initialization(self):
"""
initialization before performing image deconvolution
"""

# Master
if self.MASTER:
if (not self.parallel) or (self.MASTER):
# Clear results
self.results.clear()

Expand Down Expand Up @@ -199,7 +196,7 @@ def post_processing(self):
# update expectation_list
self.expectation_list = self.calc_expectation_list(self.model, dict_bkg_norm = self.dict_bkg_norm)
logger.debug("The expected count histograms were updated with the new model map.")

# update loglikelihood_list
self.loglikelihood_list = self.calc_loglikelihood_list(self.expectation_list)
logger.debug("The loglikelihood list was updated with the new expected count histograms.")
Expand All @@ -221,7 +218,7 @@ def register_result(self):
"""

# Master
if self.MASTER:
if (not self.parallel) or (self.MASTER):
this_result = {"iteration": self.iteration_count,
"model": copy.deepcopy(self.model),
"delta_model": copy.deepcopy(self.delta_model),
Expand Down Expand Up @@ -257,7 +254,7 @@ def finalization(self):
"""

# Master
if self.MASTER:
if (not self.parallel) or (self.MASTER):
if self.save_results == True:
logger.info('Saving results in {self.save_results_directory}')

Expand Down
2 changes: 1 addition & 1 deletion cosipy/image_deconvolution/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from .image_deconvolution_data_interface_base import ImageDeconvolutionDataInterfaceBase
from .dataIF_COSI_DC2 import DataIF_COSI_DC2
from .dataIFWithParallelSupport import DataIFWithParallel
from .dataIF_Parallel import DataIF_Parallel

from .model_base import ModelBase
from .allskyimage import AllSkyImageModel
Expand Down
Loading

0 comments on commit cddaa24

Please sign in to comment.