forked from alexispapabil/thesis
-
Notifications
You must be signed in to change notification settings - Fork 2
/
node.py
49 lines (41 loc) · 1.29 KB
/
node.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
#!/usr/bin/env python3
#-*- coding: utf-8 -*-
from slot import Socket
class Node:
def __init__(self, name, sockets, cores):
self.name = name
self.cores = cores
self.exclusive = 0
self.sockets = []
for i in range(sockets):
self.sockets.append(Socket(i, self.cores))
def occupied(self, policy):
for socket in self.sockets:
if socket.occupied(policy):
return 1
return 0
def free(self, jobs):
self.exclusive = 0
for socket in self.sockets:
socket.free(jobs)
def remaining(self):
window = map(lambda socket: socket.remaining(), self.sockets)
window = [interval for socket in window for interval in socket]
return min(window)
def myjobs(self):
jobs = set()
for socket in self.sockets:
jobs = jobs.union(set(socket.myjobs()))
return jobs
def precedence(self, heatmap, job):
jobs = self.myjobs()
if jobs:
(myjob,) = jobs
return heatmap[job.app.split('.')[0]][myjob.app.split('.')[0]]
else:
return 0
def __str__(self):
text = ''
for socket in self.sockets:
text += self.name + ' ' + str(socket) + '\n'
return text