-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepare-multimessage.py
87 lines (58 loc) · 2.2 KB
/
prepare-multimessage.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env python
#
# Copyright (c) 2013-2016, ETH Zurich.
# All rights reserved.
#
# This file is distributed under the terms in the attached LICENSE file.
# If you do not find this file, copies can be found by writing to:
# ETH Zurich D-INFK, Universitaetstr. 6, CH-8092 Zurich. Attn: Systems Group.
import sys
from config import MACHINE_DATABASE
MDB= '%s/' % MACHINE_DATABASE
sys.path.append(MDB)
import machineinfo
def prepare_multimessage(machine):
root = 0
assert root in machine.get_cores()
num_nodes = machine.get_num_numa_nodes()
local = [ str(l) for l in machine.get_numa_node(root) if l != root ]
cores = [ (c, machine.get_send_cost(root, c)) for c in machine.get_cores()]
cores = sorted(cores, key=lambda x: x[1], reverse=True)
node_avg = []
for idx, node in enumerate(machine.get_numa_information()):
if machine.get_numa_id(root) == idx:
continue
node_avg += [(idx, sum([ machine.get_send_cost(root, c) for c in node ])/len(node))]
node_avg = sorted(node_avg, key=lambda x: x[1], reverse=True)[:2]
n1 = machine.get_numa_node_by_id(node_avg[0][0])
if num_nodes>2:
n2 = machine.get_numa_node_by_id(node_avg[1][0])
# http://stackoverflow.com/questions/3471999/how-do-i-merge-two-lists-into-a-single-list
remote = [str(j) for i in zip(n1,n2) for j in i]
else:
remote = [str(j) for j in n1]
s = ('%s)\n'
' ARGS=\"%d %s %s\"\n'
' ;;') % (machine.get_name(), root, ','.join(local), ','.join(remote))
print >> sys.stderr, s
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--machines')
global arg
arg = parser.parse_args()
all_machines = [ s for (s, _, _) in machineinfo.machines ]
machines = all_machines if not arg.machines else arg.machines.split()
for m in machines:
try:
# Initialize machine to get pairwise send costs
import config
from netos_machine import NetosMachine
from server import SimArgs
# Set machine name
config.args = SimArgs()
config.args.machine = m
m_class = NetosMachine()
prepare_multimessage(m_class)
except IOError as e:
print str(e)
exit(0)