-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworkloadmanager.py
59 lines (51 loc) · 1.47 KB
/
workloadmanager.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import sys
import random
from job import Job
from simulator import Simulator
'''
Read workload from a file.
'''
class WorkloadManager:
def __init__(self, filename=None):
self.jobQueue = []
if filename != None:
self.read(filename)
#self.jobIdQueue = []
def read(self, inFile):
#lineno=0
with open(inFile, "r") as f:
for line in f:
line = line.replace('\n', '')
line = line.strip()
if not line.startswith('#') and len(line) > 0:
# Job(nmaps=64, lmap=140, lmapapprox=60, nreds=1, lred=15, submit=i*150, approx)
splits = line.split()
nmaps0 = int(splits[0])
lmap0 = int(splits[1])
lmapapprox0 = int(splits[2])
nreds0 = int(splits[3])
lred0 = int(splits[4])
#lredapprox0 = int(splits[4]) # TODO cheng
submit0 = int(splits[5])
approx0 = float(splits[6])
# Create job
job = Job(nmaps=nmaps0, lmap=lmap0, lmapapprox=lmapapprox0, nreds=nreds0, lred=lred0, submit=submit0)
job.approxAlgoMapVal = approx0
self.jobQueue.append(job)
#lineno+=1
#return lineno
return self.jobQueue
def getJobs(self):
return self.jobQueue
'''
def applySJFPriority(self, rate):
for job in self.jobQueue:
if random.random() < rate:
job.priority = Job.Priority.VERY_HIGH
def copyToSimulator(self, simulator):
for job in self.jobQueue:
jobId = simulator.addJob(job)
self.jobIdQueue.append(jobId)
'''
if __name__ == '__main__':
workload = WorkloadManager()