5050from ..Model .lbsRank import Rank
5151from ..Model .lbsMessage import Message
5252from ..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
5656class 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"\t rank 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"\t maximum 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
0 commit comments