-
Notifications
You must be signed in to change notification settings - Fork 0
/
regress.py
executable file
·53 lines (43 loc) · 2.08 KB
/
regress.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
#!/usr/bin/env python2
import difflib
import subprocess
import time
import argparse
import sys
parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('-n', type=int, metavar="NUMAGENTS", nargs='?', default=100, help='Number of agents (0 < n <= 1000)')
parser.add_argument('-t', type=int, metavar="MAXTIME", nargs='?', default=20000, help='Maximum number of time steps')
args = parser.parse_args()
if args.n <= 0 or args.n > 1000:
print("[-] Invalid number of agents (0 < n <= 1000)")
sys.exit(0)
print("[.] making libraries")
subprocess.check_output(["make"], cwd="./libpedsim")
subprocess.check_output(["make"], cwd="./libpedsimpar")
print("[.] making test executables")
subprocess.check_output("g++ ./regress/regress.cpp -o regress/regress_seq -Ilibpedsim -lpedsim -Llibpedsim -g -std=c++0x", shell=True)
subprocess.check_output("g++ ./regress/regress.cpp -o regress/regress_par -Ilibpedsimpar -lpedsimpar -Llibpedsimpar -g -std=c++0x", shell=True)
print("[.] running sequential")
start = time.time()
subprocess.check_output("LD_LIBRARY_PATH=./libpedsim/:${{LD_LIBRARY_PATH}} ./regress/regress_seq -n {} -t {}".format(args.n, args.t), shell=True)
subprocess.check_output("mv ./pedsim_out.txt ./pedsim_out_seq.txt", shell=True)
end = time.time()
seqtime = end-start
print("Sequential: {} ms".format(seqtime*1000.0))
print("[.] running parallel")
start = time.time()
subprocess.check_output("LD_LIBRARY_PATH=./libpedsimpar/:${{LD_LIBRARY_PATH}} ./regress/regress_par -n {} -t {}".format(args.n, args.t), shell=True)
subprocess.check_output("mv ./pedsim_out.txt ./pedsim_out_par.txt", shell=True)
end = time.time()
partime = end-start
print("Parallel: {} ms".format(partime*1000.0))
print("Speedup: {}".format(seqtime/partime))
print("[.] checking output")
outputSeq = open("./pedsim_out_seq.txt").read().strip().splitlines()
outputPar = open("./pedsim_out_par.txt").read().strip().splitlines()
if outputSeq != outputPar:
print("[-] MISMATCH:")
for line in difflib.unified_diff(outputSeq, outputPar, lineterm=''):
print(line)
else:
print("[+] Passed.")