Skip to content

Commit

Permalink
#324: memory: fix code style issues
Browse files Browse the repository at this point in the history
  • Loading branch information
lifflander committed Dec 12, 2022
1 parent 91f7ea9 commit b9d97fd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/lbaf/Applications/LBAF_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def main(self):

# Perform central prefix optimizer when requested
if self.params.algorithm["name"] != "CentralizedPrefixOptimizer":
self.logger.info(f"Starting centralized prefix optimizer")
self.logger.info("Starting centralized prefix optimizer")

# Instantiate and execute runtime
qoi_name = self.params.__dict__.get("visualize_qoi")
Expand Down
42 changes: 12 additions & 30 deletions src/lbaf/Execution/lbsCentralizedPrefixOptimizerAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@


class CentralizedPrefixOptimizerAlgorithm(AlgorithmBase):
""" A concrete class for the centralized prefix memory-constrained optimizer
"""
""" A concrete class for the centralized prefix memory-constrained optimizer"""

def __init__(self, work_model, parameters: dict, lgr: Logger, qoi_name: str):
""" Class constructor
Expand All @@ -25,8 +24,8 @@ def __init__(self, work_model, parameters: dict, lgr: Logger, qoi_name: str):
work_model, parameters, lgr, qoi_name)

def execute(self, phases: list, distributions: dict, statistics: dict, _):
""" Execute centralized prefix memory-constrained optimizer
"""
""" Execute centralized prefix memory-constrained optimizer"""

# Ensure that a list with at least one phase was provided
if not phases or not isinstance(phases, list) or not isinstance(
(phase := phases[0]), Phase):
Expand Down Expand Up @@ -60,9 +59,7 @@ def execute(self, phases: list, distributions: dict, statistics: dict, _):
# objects.sort(key=lambda x: x.get("id"))

self._max_shared_ids = max_shared_ids + 1

made_no_assignments = 0

do_second_stage = False

while made_no_assignments < 2:
Expand All @@ -71,19 +68,14 @@ def execute(self, phases: list, distributions: dict, statistics: dict, _):
for rank in phase_ranks:
rank_max_heap.append(rank);

for i in range(len(rank_max_heap)):
self._logger.info("{} load {}".format(i, rank_max_heap[i].get_load()))

heapq._heapify_max(rank_max_heap)
max_rank = heapq._heappop_max(rank_max_heap)

diff = max_rank.get_load() - statistics["average load"]
self._logger.info("diff={}".format(diff))
self._logger.info(f"diff={diff}")

shared_map = {}
obj_shared_map = {}
groupings = []
groupings_sum = []
shared_map, obj_shared_map = {}, {}
groupings, groupings_sum = [], []

for o in max_rank.get_migratable_objects():
if not o.get_shared_block_id() in obj_shared_map:
Expand All @@ -99,35 +91,27 @@ def execute(self, phases: list, distributions: dict, statistics: dict, _):
for sid in shared_map:
groupings.append((shared_map[sid],sid))

for x in groupings:
self._logger.info("grouping {}".format(x))

groupings.sort()

for x in groupings:
self._logger.info("sorted grouping {}".format(x))

for i in range(len(groupings)):
groupings_sum.append(0)
groupings_sum[0] = groupings[0][0]
for i in range(1,len(groupings)):
groupings_sum[i] = groupings_sum[i-1] + groupings[i][0]

for i in range(len(groupings)):
self._logger.info("i={} sum={}".format(i,groupings_sum[i]))
self._logger.info(f"i={i} sum={groupings_sum[i]}")

pick_upper = 0
while (groupings_sum[pick_upper] < diff):
self._logger.info("add pick_upper")
pick_upper += 1
if pick_upper-1 >= 0 and groupings_sum[pick_upper-1] >= diff * 1.05:
pick_upper -= 1
self._logger.info("subtract pick_upper")
pick_lower = pick_upper-1
while (pick_lower-1 >= -1 and groupings_sum[pick_upper] - groupings_sum[pick_lower] < diff):
pick_lower -= 1

self._logger.info("pick=({},{})".format(pick_lower,pick_upper))
self._logger.info(f"pick=({pick_lower},{pick_upper}]")

made_assignment = False

Expand Down Expand Up @@ -161,28 +145,26 @@ def execute(self, phases: list, distributions: dict, statistics: dict, _):
self.report_final_mapping(self._logger)

def tryBin(self, ranks, max_rank, tbin, size, sid, objs):
self._logger.info("tryBin size={}, max={}".format(size, self._max_shared_ids))
self._logger.info(f"tryBin size={size}, max={self._max_shared_ids}")

min_ranks = []

for rank in ranks:
self._logger.info("adding rank {}: len={} max={}".format(rank.get_id(),len(rank.get_shared_blocks()),self._max_shared_ids))
if sid in rank.get_shared_blocks() or len(rank.get_shared_blocks()) < self._max_shared_ids:
min_ranks.append(rank)

heapq.heapify(min_ranks)
min_rank = None

tally_assigned = 0
tally_rejected = 0
tally_assigned, tally_rejected = 0, 0

for o in objs[sid]:
if len(min_ranks) == 0:
self._logger.error("reached condition where no ranks count take the element")
sys.excepthook = exc_handler
raise SystemExit(1)

if min_rank == None:
if min_rank is None:
min_rank = heapq.heappop(min_ranks)

if len(min_rank.get_shared_blocks()) >= self._max_shared_ids and not sid in min_rank.get_shared_blocks():
Expand All @@ -200,6 +182,6 @@ def tryBin(self, ranks, max_rank, tbin, size, sid, objs):

tally_rejected += 1

self._logger.info("try bin: {}, size={}, id={}; assigned={}, rejected={}\n".format(tbin, size, sid, tally_assigned, tally_rejected))
self._logger.info(f"try bin: {tbin}, size={size}, id={sid}; assigned={tally_assigned}, rejected={tally_rejected}")

return tally_assigned > 0

0 comments on commit b9d97fd

Please sign in to comment.