Skip to content

Commit

Permalink
Rename new compact and spread to e_compact and e_spread (execution li…
Browse files Browse the repository at this point in the history
…st aware) and re-add old compact and spread
  • Loading branch information
nikosT committed Sep 5, 2024
1 parent 0e5a763 commit 52931cc
Show file tree
Hide file tree
Showing 2 changed files with 144 additions and 3 deletions.
2 changes: 1 addition & 1 deletion etc/oar/admission_rules.d/15_check_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
r8 = "^allowed=\\w+$"
r9 = "^inner=\\w+$"
r10 = "^timesharing=(?:(?:\\*|user),(?:\\*|name)|(?:\\*|name),(?:\\*|user))$"
r11 = "^(?:compact|spread|f_spread|co_loc|f_co_loc|no_pref|exclusive|friendly|unfriendly)$"
r11 = "^(?:compact|spread|f_spread|co_loc|f_co_loc|no_pref|exclusive|e_compact|e_spread|friendly|unfriendly)$"
all_re = re.compile(
"(%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s)"
% (r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11)
Expand Down
145 changes: 143 additions & 2 deletions oar/kao/custom_scheduling.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def get_nodes_characterization(session: Session):
return results


def compact(session, itvs_slots, hy_res_rqts, hy, beginning_slotset, reverse=True, allocation=(1, 3, 2)):
def e_compact(session, itvs_slots, hy_res_rqts, hy, beginning_slotset, reverse=True, allocation=(1, 3, 2)):
"""
Given a job resource request and a set of resources this function tries to find a matching allocation.
Expand Down Expand Up @@ -156,7 +156,7 @@ def compact(session, itvs_slots, hy_res_rqts, hy, beginning_slotset, reverse=Tru
return result


def spread(session, itvs_slots, hy_res_rqts, hy, beginning_slotset, reverse=True, allocation=(1, 3, 2)):
def e_spread(session, itvs_slots, hy_res_rqts, hy, beginning_slotset, reverse=True, allocation=(1, 3, 2)):
"""
Given a job resource request and a set of resources this function tries to find a matching allocation.
Expand Down Expand Up @@ -257,6 +257,147 @@ def spread(session, itvs_slots, hy_res_rqts, hy, beginning_slotset, reverse=True
return result


def compact(session, itvs_slots, hy_res_rqts, hy, beginning_slotset, reverse=True):
"""
Given a job resource request and a set of resources this function tries to find a matching allocation.
.. note::
This` can be override with the oar `extension <../admin/extensions.html#functions-assign-and-find>`_ mechanism.
:param session: The DB session
:param itvs_slots: A procset of the resources available for the allocation
:type itvs_slots: :class:`procset.ProcSet`
:param hy_res_rqts: The job's request
:param hy: The definition of the resources hierarchy
:return [ProcSet]: \
The allocation if found, otherwise an empty :class:`procset.ProcSet`
"""
# logger.info(session)

# queryCollection = BaseQueryCollection(session)
# jobs=get_jobs_in_state(session,'Running')
# logger.info(jobs)
# res = queryCollection.get_assigned_jobs_resources(jobs)
# logger.info(res)

result = ProcSet()
for hy_res_rqt in hy_res_rqts:
(hy_level_nbs, constraints) = hy_res_rqt
hy_levels = []
hy_nbs = []
for hy_l_n in hy_level_nbs:
(l_name, n) = hy_l_n
hy_levels.append(hy[l_name])
hy_nbs.append(n)

itvs_cts_slots = constraints & itvs_slots

# create a nodes Procset list sorted by min/max free cores
hy_nodes = sorted(
hy["network_address"],
key=lambda i: len(i & itvs_cts_slots),
reverse=reverse,
)

hy_levels = []
for node in hy_nodes:
# collect cpu Procset for particular node
n_cpus = list(filter(lambda p: p.issubset(node), hy["cpu"]))
# sort cpu Procset list sorted by min/max free cores
n_cpus = sorted(
n_cpus, key=lambda i: len(i & itvs_cts_slots), reverse=reverse
)
# map cpu Procset to core procset
hy_levels += list(
map(ProcSet, itertools.chain.from_iterable(map(iter, n_cpus)))
)

# there is an Admission Rule that blocks other resources than core
# so only 1 resource type will be given
hy_levels = [hy_levels]

res = find_resource_hierarchies_scattered(
itvs_cts_slots, list(hy_levels), hy_nbs
)
if res:
result = result | res
else:
return ProcSet()

return result


def spread(session, itvs_slots, hy_res_rqts, hy, beginning_slotset, reverse=True):
"""
Given a job resource request and a set of resources this function tries to find a matching allocation.
.. note::
This` can be override with the oar `extension <../admin/extensions.html#functions-assign-and-find>`_ mechanism.
:param session: The DB session
:param itvs_slots: A procset of the resources available for the allocation
:type itvs_slots: :class:`procset.ProcSet`
:param hy_res_rqts: The job's request
:param hy: The definition of the resources hierarchy
:return [ProcSet]: \
The allocation if found, otherwise an empty :class:`procset.ProcSet`
"""
result = ProcSet()
for hy_res_rqt in hy_res_rqts:
(hy_level_nbs, constraints) = hy_res_rqt
hy_levels = []
hy_nbs = []
for hy_l_n in hy_level_nbs:
(l_name, n) = hy_l_n
hy_levels.append(hy[l_name])
hy_nbs.append(n)

itvs_cts_slots = constraints & itvs_slots

itvs_cts_slots2 = itvs_cts_slots.copy()

for soc in hy["cpu"]:
avail_cores = soc & itvs_cts_slots
itvs_cts_slots -= ProcSet(*avail_cores[int(len(soc) / 2) : len(soc)])

# Select unused resources first (top-down).
try:
# create a nodes Procset list sorted by min/max free cores
hy_nodes = sorted(
hy["network_address"],
key=lambda i: len(i & itvs_cts_slots2),
reverse=reverse,
)

hy_levels = []
for node in hy_nodes:
# collect cpu Procset for particular node
n_cpus = list(filter(lambda p: p.issubset(node), hy["cpu"]))
# sort cpu Procset list sorted by min/max free cores
n_cpus = sorted(
n_cpus, key=lambda i: len(i & itvs_cts_slots2), reverse=reverse
)
# map cpu Procset to core procset
hy_levels += list(
map(ProcSet, itertools.chain.from_iterable(map(iter, n_cpus)))
)

# there is an Admission Rule that blocks other resources than core
# so only 1 resource type will be given
hy_levels = [hy_levels]

except Exception as e:
logger.info(e)

res = find_resource_hierarchies_scattered(itvs_cts_slots, hy_levels, hy_nbs)

if res:
result = result | res
else:
return ProcSet()

return result

def co_loc(session, itvs_slots, hy_res_rqts, hy, beginning_slotset):
"""
Given a job resource request and a set of resources this function tries to find a matching allocation.
Expand Down

0 comments on commit 52931cc

Please sign in to comment.