Skip to content

Commit a7a10ad

Browse files
committed
#605: include all changes made during information stage study
1 parent 657ef68 commit a7a10ad

File tree

3 files changed

+42
-18
lines changed

3 files changed

+42
-18
lines changed

src/lbaf/Execution/lbsClusteringTransferStrategy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ def __init__(self, criterion, parameters: dict, lgr: Logger):
7676
self._logger.info(
7777
f"Percentage of maximum load required for subclustering: {self.__subclustering_threshold}")
7878

79-
# Initialize fraction of local imbalance that must be resolved by subcluster
79+
# Initialize fraction of local imbalance to be resolved by subcluster
8080
self.__subclustering_minimum_improvement = parameters.get("subclustering_minimum_improvement", 0.0)
8181
self._logger.info(
82-
"Fraction of local imbalance that must be resolved by subcluster: "
82+
"Local imbalance fraction to be resolved by subcluster: "
8383
f"{self.__subclustering_minimum_improvement}")
8484

8585
# Initialize cluster swap relative threshold

src/lbaf/Execution/lbsInformAndTransferAlgorithm.py

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
from ..Model.lbsRank import Rank
5151
from ..Model.lbsMessage import Message
5252
from ..Model.lbsPhase import Phase
53-
from ..IO.lbsStatistics import min_Hamming_distance, print_function_statistics
53+
from ..IO.lbsStatistics import min_Hamming_distance, compute_function_statistics
5454

5555

5656
class InformAndTransferAlgorithm(AlgorithmBase):
@@ -210,20 +210,25 @@ def __execute_information_stage(self):
210210
self._logger.debug(
211211
f"Peers known to rank {rank.get_id()}: {[r_k.get_id() for r_k in k_p]}")
212212

213-
# Report on final known information ratio
214-
n_k = sum(len(k_p) for k_p in self.__known_peers.values() if k_p) / n_r
213+
# Compute and report on final known information ratio
214+
if n_r > 1:
215+
# Knowledge ratios can be computed
216+
sum_kappa = 0.0
217+
known_fac = 1.0 / (n_r - 1.0)
218+
for rank, peers in self.__known_peers.items():
219+
kappa = known_fac * (len(peers) - 1)
220+
rank.set_kappa(kappa)
221+
sum_kappa += kappa
222+
else:
223+
self._logger.warning(
224+
f"Cannot compute knowledge ratio with only {n_r} ranks")
215225
self._logger.info(
216-
f"Average number of peers known to ranks: {n_k} ({100 * n_k / n_r:.2f}% of {n_r})")
226+
f"Average rank knowledge ratio: {sum_kappa / n_r:.4g}")
217227

218228
def execute(self, p_id: int, phases: list, statistics: dict):
219229
""" Execute 2-phase information+transfer algorithm on Phase with index p_id."""
220230
# Perform pre-execution checks and initializations
221231
self._initialize(p_id, phases, statistics)
222-
print_function_statistics(
223-
self._rebalanced_phase.get_ranks(),
224-
self._work_model.compute,
225-
"initial rank work",
226-
self._logger)
227232

228233
# Set phase to be used by transfer criterion
229234
self.__transfer_criterion.set_phase(self._rebalanced_phase)
@@ -256,12 +261,15 @@ def execute(self, p_id: int, phases: list, statistics: dict):
256261
self._logger.info(
257262
f"Iteration {i + 1} completed ({n_ignored} skipped ranks) in {time.time() - start_time:.3f} seconds")
258263

259-
# Compute and report iteration work statistics
260-
stats = print_function_statistics(
264+
# Compute and report iteration load imbalance and maximum work
265+
load_imb = compute_function_statistics(
261266
self._rebalanced_phase.get_ranks(),
262-
self._work_model.compute,
263-
f"iteration {i + 1} rank work",
264-
self._logger)
267+
lambda x: x.get_load()).get_imbalance()
268+
self._logger.info(f"\trank load imbalance: {load_imb:.6g}")
269+
max_work = compute_function_statistics(
270+
self._rebalanced_phase.get_ranks(),
271+
self._work_model.compute).get_maximum()
272+
self._logger.info(f"\tmaximum rank work: {max_work:.6g}")
265273

266274
# Update run statistics
267275
self._update_statistics(statistics)
@@ -273,9 +281,9 @@ def execute(self, p_id: int, phases: list, statistics: dict):
273281
self._initial_phase.get_lb_iterations().append(lb_iteration)
274282

275283
# Check if the current imbalance is within the target_imbalance range
276-
if stats.statistics["imbalance"] <= self.__target_imbalance:
284+
if load_imb <= self.__target_imbalance:
277285
self._logger.info(
278-
f"Reached target imbalance of {self.__target_imbalance} after {i + 1} iterations.")
286+
f"Reached target load imbalance of {self.__target_imbalance:.6g} after {i + 1} iterations.")
279287
break
280288

281289
# Report final mapping in debug mode

src/lbaf/Model/lbsRank.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ def __init__(
8282
# Start with empty metadata
8383
self.__metadata = {}
8484

85+
# Initialize knowledge ratio to complete ignorance
86+
self.__kappa = 0.0
87+
8588
# By default the rank is note connected to a node
8689
self.__node = None
8790

@@ -130,6 +133,19 @@ def set_size(self, size):
130133
f"size: incorrect type {type(size)} or value: {size}")
131134
self.__size = float(size)
132135

136+
@qoi
137+
def get_kappa(self) -> float:
138+
"""Return rank knowledge ratio."""
139+
return self.__kappa
140+
141+
def set_kappa(self, kappa):
142+
"""Set rank knowledge ratio, which is algorithm-specific."""
143+
# Value in [0;1] is required
144+
if not isinstance(kappa, float) or kappa < 0.0 or kappa > 1.0:
145+
raise TypeError(
146+
f"kappa: incorrect type {type(kappa)} or value: {kappa}")
147+
self.__kappa = kappa
148+
133149
def get_metadata(self) -> dict:
134150
"""Return original metadata."""
135151
return self.__metadata

0 commit comments

Comments
 (0)