diff --git a/src/lbaf/Execution/lbsAlgorithmBase.py b/src/lbaf/Execution/lbsAlgorithmBase.py index ac5e0097..69e4e3bb 100644 --- a/src/lbaf/Execution/lbsAlgorithmBase.py +++ b/src/lbaf/Execution/lbsAlgorithmBase.py @@ -87,10 +87,11 @@ def __init__(self, work_model: WorkModelBase, parameters: dict, logger: Logger): self._logger.error("Could not create an algorithm without a dictionary of parameters") raise SystemExit(1) - # Initially no phase is assigned for processing + # Initially no phases are assigned for rebalancing + self._initial_phase = None self._rebalanced_phase = None - # Save the initial communications data + # Keep track of phase communications self._initial_communications = {} # Map rank statistics to their respective computation methods @@ -104,12 +105,12 @@ def get_initial_communications(self): """Return the initial phase communications.""" return self._initial_communications - def get_lb_iterations(self): - """Return possibly empty list of load balancing iterations.""" - return self._lb_iterations + def get_initial_phase(self): + """Return initial phase.""" + return self._initial_phase def get_rebalanced_phase(self): - """Return phased assigned for processing by algoritm.""" + """Return rebalanced phased.""" return self._rebalanced_phase @staticmethod @@ -178,6 +179,7 @@ def _initialize(self, p_id, phases, statistics): raise SystemExit(1) # Set initial communications for given phase index + self._initial_phase = phases[p_id] self._initial_communications[p_id] = phases[p_id].get_communications() # Create a new phase to preserve phase to be rebalanced diff --git a/src/lbaf/Execution/lbsInformAndTransferAlgorithm.py b/src/lbaf/Execution/lbsInformAndTransferAlgorithm.py index 87e8b2d5..da2b1e40 100644 --- a/src/lbaf/Execution/lbsInformAndTransferAlgorithm.py +++ b/src/lbaf/Execution/lbsInformAndTransferAlgorithm.py @@ -276,7 +276,7 @@ def execute(self, p_id: int, phases: list, statistics: dict, a_min_max): new_ranks.add(new_r) lb_iteration.set_ranks(new_ranks) lb_iteration.set_communications(self._initial_communications) - self._lb_iterations.append(lb_iteration) + self._initial_phase.get_lb_iterations().append(lb_iteration) # Report minimum Hamming distance when minimax optimum is available if a_min_max: diff --git a/src/lbaf/Execution/lbsRuntime.py b/src/lbaf/Execution/lbsRuntime.py index b1696a05..617a330d 100644 --- a/src/lbaf/Execution/lbsRuntime.py +++ b/src/lbaf/Execution/lbsRuntime.py @@ -135,6 +135,11 @@ def execute(self, p_id: int, phase_increment: int=0, lb_iterations=False): # Retrieve possibly null rebalanced phase and return it if (lbp := self.__algorithm.get_rebalanced_phase()): + # Retain lb iterations with initial phase when it is replaced + if not phase_increment: + self.__algorithm.get_rebalanced_phase().set_lb_iterations( + self.__algorithm.get_initial_phase().get_lb_iterations()) + # Increment rebalanced phase ID as requested lbp.set_id((lbp_id := lbp.get_id() + phase_increment)) @@ -143,9 +148,5 @@ def execute(self, p_id: int, phase_increment: int=0, lb_iterations=False): lbp.set_communications(initial_communications[p_id]) self.__logger.info(f"Created rebalanced phase {lbp_id}") - # Attach iterations to new phase when requested - lbp.set_lb_iterations( - self.__algorithm.get_lb_iterations() if lb_iterations else []) - # Return rebalanced phase return lbp