Commit 477310a2 authored by David Glesser's avatar David Glesser
Browse files

Add an EASY SJBF scheduler to pybatsim.

parent 968cf932
#/usr/bin/python3
from batsim.batsim import BatsimScheduler, Batsim
from batsim.batsim import BatsimScheduler
from schedulers.common_pyss_adaptator import CpuSnapshot
import sys
......@@ -69,7 +69,7 @@ class EasyBackfillNotopo(BatsimScheduler):
for job in scheduledJobs:
job.start_time = current_time
job.start_time = current_time#just to be sure
res = self.availableResources[:job.requested_resources]
self.jobs_res[job.id] = res
self.previousAllocations[job.id] = res
......@@ -87,6 +87,7 @@ class EasyBackfillNotopo(BatsimScheduler):
# Try to schedule the first job
if self.cpu_snapshot.free_processors_available_at(current_time) >= self.unscheduled_jobs[0].requested_resources:
job = self.unscheduled_jobs.pop(0)
job.start_time = current_time
self.cpu_snapshot.assignJob(job, current_time)
tosched.append(job)
......@@ -122,11 +123,13 @@ class EasyBackfillNotopo(BatsimScheduler):
if job.requested_time > shadow_len:
if job.requested_resources <= extra_cpu:
result.append(job)
job.start_time = current_time
self.cpu_snapshot.assignJob(job, current_time)
extra_cpu -= job.requested_resources
else:
if job.requested_resources <= extra_cpu+nonextra_cpu:
result.append(job)
job.start_time = current_time
self.cpu_snapshot.assignJob(job, current_time)
nonextra_cpu -= job.requested_resources
if nonextra_cpu < 0:
......
from schedulers.easy_backfill_notopo import EasyBackfillNotopo
def list_copy(my_list):
result = []
for i in my_list:
result.append(i)
return result
# shortest job first
sjf_sort_key = (
lambda job : job.requested_time
)
# this scheduler is similar to the standard easy scheduler. The only diffrence is that
# the tail of jobs is reordered by shortest job first before trying to backfill jobs in the tail.
class EasySjbfBackfillNotopo(EasyBackfillNotopo):
""" This algorithm implements the algorithm in the paper of Tsafrir, Etzion, Feitelson, june 2007?
"""
def _backfill_jobs(self, current_time):
"Overriding parent method"
if len(self.unscheduled_jobs) <= 1:
return []
result = []
first_job = self.unscheduled_jobs[0]
tail = list_copy(self.unscheduled_jobs[1:])
tail_of_jobs_by_sjf_order = sorted(tail, key=sjf_sort_key)
first_job.start_time = current_time
self.cpu_snapshot.assignJobEarliest(first_job, current_time)
for job in tail_of_jobs_by_sjf_order:
if self.cpu_snapshot.canJobStartNow(job, current_time):
job.is_backfilled = 1
job.start_time = current_time
self.unscheduled_jobs.remove(job)
self.cpu_snapshot.assignJob(job, current_time)
result.append(job)
self.cpu_snapshot.unAssignJob(first_job)
first_job.start_time = None
return result
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment