Peano
Loading...
Searching...
No Matches
studies-load-balancing.py
Go to the documentation of this file.
1"""
2
3Compare the decompositions of the hardcoded load balancing
4
5Runs the executables that single-black-hole.py generated with different
6--decomposition and --split-mode settings. Each directory below the study
7directory holds one build. For each build, each thread count and each
8repetition, the script runs the code and reports
9
10- the number of local and virtual (remote) cells over all trees,
11- the largest number of local cells of any tree, i.e. the imbalance, and
12- the total time and the average time of the TimeStep sweeps.
13
14 python3 studies-load-balancing.py studies-quantised --threads 1 8 --repetitions 3
15
16"""
17
18import argparse
19import os
20import re
21import subprocess
22
23
24def run(directory, threads):
25 environment = dict(os.environ, OMP_NUM_THREADS=str(threads))
26 log = os.path.join(directory, f"run-{threads}.log")
27 with open(log, "w") as output:
28 subprocess.run(["./single-black-hole"], cwd=directory, env=environment, stdout=output, stderr=subprocess.STDOUT)
29 text = open(log).read()
30 statistics = re.findall(r"dumpStatistics\‍(\‍)\s+info\s+(\d+) tree\‍(s\‍): (.*) total=(\d+)/(\d+)", text)
31 trees, per_tree, local, virtual = statistics[-1]
32 local_per_tree = [int(x) for x in re.findall(r"#\d+:(\d+)/", per_tree)]
33 step = re.search(r"TimeStep: ([0-9.e+-]+)s\s+\‍(avg=([0-9.e+-]+),#measurements=(\d+)", text)
34 return dict(
35 trees=int(trees), local=int(local), virtual=int(virtual), max_local=max(local_per_tree),
36 total=float(step.group(1)) * int(step.group(3)), average=float(step.group(2)),
37 )
38
39
40if __name__ == "__main__":
41 parser = argparse.ArgumentParser()
42 parser.add_argument("study", help="Directory with one subdirectory per build")
43 parser.add_argument("--threads", type=int, nargs="+", default=[8])
44 parser.add_argument("--repetitions", type=int, default=3)
45 arguments = parser.parse_args()
46
47 print("build,threads,repetition,trees,local,virtual,virtual/local,max_local,step_total_s,step_average_s")
48 for name in sorted(os.listdir(arguments.study)):
49 directory = os.path.join(arguments.study, name)
50 if not os.path.exists(os.path.join(directory, "single-black-hole")):
51 continue
52 for threads in arguments.threads:
53 for repetition in range(arguments.repetitions):
54 r = run(directory, threads)
55 print(f"{name},{threads},{repetition},{r['trees']},{r['local']},{r['virtual']},"
56 f"{r['virtual'] / r['local']:.2f},{r['max_local']},{r['total']:.3f},{r['average']:.4f}", flush=True)