-
Notifications
You must be signed in to change notification settings - Fork 3
/
tri_part.py
executable file
·67 lines (52 loc) · 1.95 KB
/
tri_part.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
'''
Triangle partition utility
'''
import sys
import os
from subprocess import Popen
import configparser
from utils import sync_process, get_machine_list
if __name__ == "__main__":
pool = list()
if len(sys.argv) < 4:
print("Usage: python tri_part.py <graph_name> <in_prefix> <out_prefix>")
sys.exit(-1)
graph = sys.argv[1]
in_prefix = sys.argv[2]
out_prefix = sys.argv[3]
is_skew_res = "false"
config = configparser.ConfigParser()
config.read("conf/params.ini")
workdir = config['DEFAULT']['workdir']
num_machines = int(config['DEFAULT']['number_machines'])
num_workers = int(config['DEFAULT']['number_workers'])
print("Triangle Partition " + graph + " into " + out_prefix)
cur_dir = os.getcwd()
binPath = os.path.join(cur_dir, 'bin', 'tri_part')
hostPath = os.path.join(cur_dir, 'conf', 'hosts')
machines = get_machine_list(hostPath)
if num_machines > len(machines):
print("Specify too many <number_machines> in conf/params.ini."
" Should be <= " + str(len(machines)))
sys.exit(-1)
logPath = os.path.join(cur_dir, 'logs', 'partition', graph)
if not os.path.exists(logPath):
os.makedirs(logPath)
for i in range(num_machines):
run_params = "/usr/bin/time -v {} {} {} {} {} -n {} -w {} -p {} -h {}" \
.format(binPath, workdir, graph, in_prefix, out_prefix,
num_machines, num_workers, i, hostPath)
if is_skew_res == "true":
run_params += ' -R'
logfile_name = os.path.join(logPath, 'tri_part_r_%d.log' % i)
else:
logfile_name = os.path.join(logPath, 'tri_part_%d.log' % i)
with open(logfile_name, "w") as logfile:
command = ["ssh", machines[i], run_params]
print(command)
pool.append(Popen(
command,
stdout=logfile,
stderr=logfile
))
sync_process(pool)