Skip to content

Commit 44d433e

Browse files
committed
make simulator work with python3
Signed-off-by: Reto Achermann <[email protected]>
1 parent 27df9c2 commit 44d433e

20 files changed

+137
-105
lines changed

adaptive.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
# If you do not find this file, copies can be found by writing to:
88
# ETH Zurich D-INFK, Universitaetstr. 6, CH-8092 Zurich. Attn: Systems Group.
99

10+
import sys
11+
12+
#sys.path.append('contrib/python-graph/core')
1013
from pygraph.classes.digraph import digraph
1114

1215
import sched_adaptive
@@ -61,8 +64,8 @@ def get_root_node(self):
6164
c_snd_cost = sorted(_c_snd_cost.items(), key=lambda x: x[1])
6265
(root, cost) = c_snd_cost[0]
6366

64-
print 'Choosing node %d as root with cost %d' % \
65-
(root, cost)
67+
print ('Choosing node %d as root with cost %d' % \
68+
(root, cost))
6669

6770
return root
6871

@@ -74,5 +77,8 @@ def _build_tree(self, g):
7477
7578
"""
7679
gout = digraph()
77-
map(gout.add_node, [ n for n in g.nodes() ])
80+
for n in g.nodes() :
81+
gout.add_node(n)
82+
83+
7884
return gout

algorithms.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def invert_weights(g):
108108
w = 0
109109
for (s,d) in g.edges():
110110
w = max(w, g.edge_weight((s,d)))
111-
print 'Maximum edge weight is %d' % w
111+
print ('Maximum edge weight is %d' % w)
112112
w += 1 # Make sure the most expensive edge will have a cost of 1 afterwards
113113
g_inv = digraph()
114114
for n in g.nodes():
@@ -121,14 +121,14 @@ def invert_weights(g):
121121
g_inv.add_edge((s,d), w_inv)
122122
except:
123123
assert g_inv.edge_weight((s,d)) == w_inv # This one fails
124-
print "Edge %d %d already in graph, ignoring .. " % (s,d)
124+
print ("Edge %d %d already in graph, ignoring .. " % (s,d))
125125
return g_inv
126126

127127

128128
def merge_graphs(g1, g2):
129129
"""
130-
Merge two graphs to a new graph (V, E) with V = g1.nodes \union g2.nodes
131-
and Edge e \in g1 or e \in g2 -> e \in E.
130+
Merge two graphs to a new graph (V, E) with V = g1.nodes union g2.nodes
131+
and Edge e in g1 or e in g2 -> e in E.
132132
"""
133133

134134
if g1.DIRECTED or g2.DIRECTED:

cluster.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ def _build_tree(self, g):
4141
4242
"""
4343

44-
print '--------------------------------------------------'
45-
print '-- BUILD CLUSTER TOPLOGY'
46-
print '--------------------------------------------------'
44+
print ('--------------------------------------------------')
45+
print ('-- BUILD CLUSTER TOPLOGY')
46+
print ('--------------------------------------------------')
4747

4848
coords = self.get_coordinators()
4949

@@ -69,7 +69,7 @@ def _build_tree(self, g):
6969
numa_node = [ n for n in self.mod.get_numa_node(c) if n in g.nodes() ]
7070
g_simple = sequential(self.mod.get_graph(), numa_node, c)
7171
g_outer = merge_graphs(g_outer, g_simple)
72-
print "%s" % str(numa_node)
72+
print ("%s" % str(numa_node))
7373

7474
helpers.output_graph(g_outer, 'cluster_outer_bin', 'neato')
7575
return g_outer

config.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@
3333
dir_path = os.path.dirname(os.path.realpath(__file__))
3434

3535
# Path to the machine database.
36-
MACHINE_DATABASE='%s/machinedb/' % dir_path
36+
MACHINE_DATABASE='%s/machinedb' % dir_path
37+
MACHINE_DATABASE_SCRIPTS='%s/machinedb/scripts' % dir_path
38+
MACHINE_DATABASE_DATA='%s/machinedb/machine-data' % dir_path
3739

3840
# Arguments as given when invoking the simulator
3941
args = None

draw.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def finalize(self, final_time):
158158

159159
# Individual core by core, no merging of neighboring cores in one box
160160
if not packed:
161-
print self.obj_per_core
161+
print (self.obj_per_core)
162162
for c in self.model.get_cores(True):
163163
cidx = self.model.get_numa_id(c) % int(len(self.color_map))
164164
color = self.color_map[cidx]
@@ -220,18 +220,18 @@ def generate_image(self):
220220
with open('test.tex', 'w') as f:
221221

222222
_out = self.name.replace('.tex', '.png')
223-
print 'Generating visualization .. '
223+
print ('Generating visualization .. ')
224224

225225
for line in open('template.tex', 'r'):
226226
f.write(line.replace('{%file%}', self.name))
227227

228228
f.close()
229229

230230
try:
231-
print subprocess.check_output(shlex.split('rm -f test-figure0.pdf'))
232-
print subprocess.check_output(shlex.split('pdflatex -shell-escape -interaction nonstopmode test.tex'))
233-
print subprocess.check_output(shlex.split('convert -verbose -density 300 test-figure0.pdf %s' % _out))
231+
print (subprocess.check_output(shlex.split('rm -f test-figure0.pdf')))
232+
print (subprocess.check_output(shlex.split('pdflatex -shell-escape -interaction nonstopmode test.tex')))
233+
print (subprocess.check_output(shlex.split('convert -verbose -density 300 test-figure0.pdf %s' % _out)))
234234

235235
except Exception as e:
236-
print 'Generating visualization failed, aborting'
236+
print ('Generating visualization failed, aborting')
237237
raise e

evaluate.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -767,8 +767,8 @@ def evaluate_all(topo, root, m, sched):
767767

768768
# Dump tree
769769
for c in m.get_cores(True):
770-
print '%d -> %s' % \
771-
(c, ','.join([ str(x) for (_, x) in sched.find_schedule(c) ]))
770+
print( '%d -> %s' % \
771+
(c, ','.join([ str(x) for (_, x) in sched.find_schedule(c) ])))
772772

773773
return res
774774

@@ -853,9 +853,9 @@ def evaluate(self, topo, root, m, sched):
853853
else:
854854
send_feedback = 0
855855

856-
print "Terminating(%d,%s,%s) - cost %d for last_node -> root" % \
857-
(self.sim_round, str(self.last_node), str(root),
858-
send_feedback + self.model.get_receive_cost(self.last_node, root))
856+
print ("Terminating(%d,%s,%s) - cost %d for last_node -> root" % \
857+
(self.sim_round, str(self.last_node), str(root),
858+
send_feedback + self.model.get_receive_cost(self.last_node, root)))
859859
self.sim_round += send_feedback
860860
# * Propagation
861861
self.sim_round += T_PROPAGATE

events.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22
#
33
# Copyright (c) 2013-2016, ETH Zurich.
44
# All rights reserved.
@@ -11,6 +11,8 @@ class Event():
1111
def __init__(self, src, dest):
1212
self.src = src
1313
self.dest = dest
14+
def __lt__(self, other) :
15+
return False
1416

1517
class Send(Event):
1618
"""
@@ -20,6 +22,8 @@ class Send(Event):
2022

2123
def get_type(self):
2224
return 'Send'
25+
def __lt__(self, other) :
26+
return True
2327

2428
class Receive(Event):
2529
"""
@@ -29,6 +33,8 @@ class Receive(Event):
2933
"""
3034
def get_type(self):
3135
return 'Receive'
36+
def __lt__(self, other) :
37+
return True
3238

3339
class Propagate(Event):
3440
"""
@@ -38,6 +44,8 @@ class Propagate(Event):
3844
"""
3945
def get_type(self):
4046
return 'Propagate'
47+
def __lt__(self, other) :
48+
return False
4149

4250
class Receiving(Event):
4351
"""Indicates that a node is currently receiving a message and no other
@@ -53,3 +61,5 @@ class Receiving(Event):
5361
"""
5462
def get_type(self):
5563
return 'Receiving'
64+
def __lt__(self, other) :
65+
return False

fibonacci.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def _build_tree(self, g):
4444
while algorithms.F(fibno+2)-1<num_cores:
4545
fibno += 1
4646

47-
print 'Fibonacci number for this machine is %d' % fibno
47+
print ('Fibonacci number for this machine is %d' % fibno)
4848

4949
# Build tree
5050
nodes = []
@@ -54,7 +54,7 @@ def _build_tree(self, g):
5454
assert len(nodes)>=num_cores
5555

5656
# Sort nodes such that nodes further up in the tree come first
57-
nodes = sorted(nodes, cmp=lambda x, y: cmp(len(x),len(y)))
57+
nodes = sorted(nodes, key=lambda x: len(x))
5858

5959
# Shorten nodes so that we have just enough cores
6060
nodes = nodes[:num_cores]

helpers.py

+15-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22
#
33
# Copyright (c) 2013-2016, ETH Zurich.
44
# All rights reserved.
@@ -15,13 +15,17 @@
1515
sys.path.append('/usr/lib64/graphviz/python/')
1616
sys.path.append('/home/skaestle/bin/')
1717
sys.path.append(os.getenv('HOME') + '/bin/')
18+
1819
import gv
19-
import Queue
20+
import queue
2021
import logging
2122
import re
2223

2324
import config
2425

26+
import sys
27+
sys.path.append('./contrib/python-graph/core')
28+
sys.path.append('./contrib/python-graph/dot')
2529
from pygraph.classes.graph import graph
2630
from pygraph.classes.digraph import digraph
2731

@@ -51,7 +55,7 @@ def output_clustered_graph(graph, name, clustering):
5155
'#9467bd', '#c5b0d5', '#8c564b', '#c49c94',
5256
'#e377c2', '#f7b6d2', '#7f7f7f', '#c7c7c7',
5357
'#bcbd22', '#dbdb8d', '#17becf', '#9edae5' ]
54-
clist = [ tableau20[i*2] for i in range(0, len(tableau20)/2)]
58+
clist = [ tableau20[i*2] for i in range(0, len(tableau20)//2)]
5559

5660
i = 0
5761
for c in clustering:
@@ -104,7 +108,7 @@ def output_quorum_configuration(model, hierarchies, root, sched, topo, midx,
104108
d = core_index_dict(model.graph.nodes())
105109

106110
dim = model.get_num_cores()
107-
mat = [[0 for x in xrange(dim)] for x in xrange(dim)]
111+
mat = [[0 for x in range(dim)] for x in range(dim)]
108112

109113
import hybrid_model
110114

@@ -238,7 +242,7 @@ def walk_graph(g, root, func, mat, sched, core_dict):
238242
"""
239243
assert isinstance(g, graph) or isinstance(g, digraph)
240244

241-
active = Queue.Queue()
245+
active = queue.Queue()
242246
done = []
243247

244248
active.put((root, None))
@@ -274,8 +278,8 @@ def draw_final(mod, sched, topo):
274278
assert isinstance(sched, scheduling.Scheduling)
275279
assert isinstance(topo, Overlay)
276280

277-
print 'Name of machine is:', mod.get_name()
278-
print 'Name of topology is:', topo.get_name()
281+
print ('Name of machine is:', mod.get_name())
282+
print ('Name of topology is:', topo.get_name())
279283

280284
import pygraphviz as pgv
281285
A = pgv.AGraph()
@@ -302,7 +306,7 @@ def draw_final(mod, sched, topo):
302306
A.add_subgraph(c, name='cluster_%d' % i, color=clist[i % len(clist)])
303307
i += 1
304308
else:
305-
print 'Not drawing NUMA nodes'
309+
print ('Not drawing NUMA nodes')
306310

307311
desc = 'mc' if mc else 'full'
308312

@@ -314,8 +318,8 @@ def draw_final(mod, sched, topo):
314318
A.write(_name + '.dot')
315319

316320
except Exception as e:
317-
print 'Generating PNGs for graph topologies faield, continuing'
318-
print e
321+
print ('Generating PNGs for graph topologies faield, continuing')
322+
print (e)
319323

320324

321325
def fill_matrix(s, children, parent, mat, sched, core_dict):
@@ -444,7 +448,7 @@ class bcolors:
444448
UNDERLINE = '\033[4m'
445449

446450
def warn(msg):
447-
print bcolors.WARNING + 'WARNING: ' + msg + bcolors.ENDC
451+
print (bcolors.WARNING + 'WARNING: ' + msg + bcolors.ENDC)
448452

449453

450454
def git_version():

hybrid.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ def __init__(self, mod, mp_topology):
5454
g = digraph()
5555

5656
clusters = self.mod.machine_topology['Cache level 3']
57-
print str(clusters)
57+
print (str(clusters))
5858
coords = []
5959

6060
for cluster in clusters.get():
6161

6262
# First core in cluster acts as coordinator
6363
coords.append(cluster[0])
6464

65-
print str(coords)
65+
print (str(coords))
6666
coords = map(int, coords)
6767
g.add_nodes(coords)
6868

@@ -75,7 +75,7 @@ def __init__(self, mod, mp_topology):
7575

7676
self.mp_tree = self.mp_topology(simplemachine.SimpleMachine(g))
7777
tmp = self.mp_tree.get_broadcast_tree()
78-
print 'broadcast', str(tmp[0].graph)
78+
print ('broadcast', str(tmp[0].graph))
7979
self.mp_tree_topo = tmp[0].graph
8080

8181
for (cluster, coord) in zip(clusters.get(), coords):
@@ -116,7 +116,7 @@ def get_scheduler(self, graph):
116116
"""
117117
XXX Graph is ignored!!
118118
"""
119-
print "get_scheduler for hybrid tree using %s" % str(self.mp_tree)
119+
print ("get_scheduler for hybrid tree using %s" % str(self.mp_tree))
120120
return self.mp_tree.get_scheduler(self.mp_tree._get_broadcast_tree())
121121

122122
def get_name(self):

0 commit comments

Comments
 (0)