Skip to content

Commit

Permalink
#566: Ensure proper retention in correct phase of lb iterations in of…
Browse files Browse the repository at this point in the history
…fline mode
  • Loading branch information
ppebay committed Dec 16, 2024
1 parent 78c1273 commit 34454e8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
14 changes: 8 additions & 6 deletions src/lbaf/Execution/lbsAlgorithmBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/lbaf/Execution/lbsInformAndTransferAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 5 additions & 4 deletions src/lbaf/Execution/lbsRuntime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand All @@ -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

0 comments on commit 34454e8

Please sign in to comment.