-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
executable file
·72 lines (64 loc) · 2.03 KB
/
run.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
from subprocess import Popen, PIPE
import datetime
import sys
import os
from glob import glob
from tqdm import tqdm
def single_launch(name):
proc = Popen(name, shell=True, stdout=PIPE, stderr=PIPE)
proc.wait()
res = proc.communicate()
log = res[1].decode("utf-8")
try:
time = float(log.split('\n')[-2].split("Time: ")[-1])
return log, time
except ValueError as ve:
print(log)
with open(os.path.join(os.getcwd(), 'error_log.log'), 'w') as f:
f.write(log)
print("Runtime error. Exit")
exit(0)
def min_res(name, repeats=3):
min_time = 1e6
min_log = ""
for _ in tqdm(range(repeats)):
log, time = single_launch(name)
if time < min_time:
min_time = time
min_log = log
return min_log, min_time
def get_times(filename, algos, matrices, repeats):
run_name = datetime.datetime.now().strftime('%m_%d_%H_%M_%S')
os.makedirs("experiments", exist_ok=True)
os.makedirs(os.path.join("experiments", run_name), exist_ok=False)
global_log = ""
with open(os.path.join("experiments", run_name, "times.csv"), "w") as f:
f.write(";")
for a in algos:
f.write(a + ';')
f.write("\n")
for m in matrices:
print(m)
f.write(os.path.basename(m) + ";")
snodes = m[:-6] + "snodes"
for a in algos:
print(a)
string = os.path.join(os.getcwd(), filename + " " + a + " " + m + " " + snodes + " 1 1 check")
print(string)
log, time = min_res(string, repeats=repeats)
global_log += log
global_log += "-"*100+"\n"
f.write(str(time) + ";")
f.write("\n")
with open(os.path.join("experiments", run_name, "best_times_log.log"), "w") as f:
f.write(global_log)
def main():
filename = os.path.join("build", "app", "SPTRSV")
algos = ["base", "custom", "blas", "barrier", "syncfree", "write_first"]
matrices = glob(os.path.join(sys.argv[1], "*"))
assert len(matrices) % 2 == 0
matrices = list(filter(lambda x: not x.endswith('.snodes'), matrices))
repeats = 1
get_times(filename, algos, matrices, repeats)
if __name__ == "__main__":
main()