Skip to content

Commit 8876b2b

Browse files
committed
Adding core selections to benchmarking
Making it easy for that and whatnot
1 parent 776c0e4 commit 8876b2b

File tree

1 file changed

+50
-23
lines changed

1 file changed

+50
-23
lines changed

benchmark.py

Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,34 @@ def main(stdscr):
6565
# Select Dataset
6666
datasets = get_datasets()
6767
if not datasets:
68-
return None, "No CSV files found in data-generation/"
68+
return None, "No CSV files found in data-generation/", None
6969

7070
datasets.append("Exit")
7171
dataset = select_option(stdscr, "Select Dataset (Use Arrow Keys + Enter)", datasets)
7272

7373
if dataset == "Exit":
74-
return "Exit", None
74+
return "Exit", None, None
7575

7676
# Select Benchmark Version
7777
benchmarks = ["Serial", "OMP", "MPI", "ALL", "Exit"]
7878
benchmark = select_option(stdscr, "Select Benchmark to Run", benchmarks)
7979

80-
return benchmark, dataset
80+
if benchmark == "Exit":
81+
return "Exit", None, None
82+
83+
# Select Cores
84+
cores = None
85+
if benchmark in ["OMP", "MPI", "ALL"]:
86+
try:
87+
num_cpus = os.cpu_count()
88+
if num_cpus is None: num_cpus = 4
89+
except:
90+
num_cpus = 4
91+
92+
core_options = ["ALL"] + [str(i) for i in range(1, num_cpus + 1)]
93+
cores = select_option(stdscr, "Select Number of Cores", core_options)
94+
95+
return benchmark, dataset, cores
8196

8297
def run_benchmark():
8398
# Run make silently
@@ -86,55 +101,67 @@ def run_benchmark():
86101

87102
# Show Menu
88103
try:
89-
selection, dataset = curses.wrapper(main)
104+
result = curses.wrapper(main)
105+
if not result: return
106+
selection, dataset, cores = result
90107
except Exception as e:
91108
print(f"Error in UI: {e}")
92-
# run_command("make clean", silent=True)
93109
return
94110

95-
if selection == "Exit" or selection is None:
96-
if dataset and dataset != "Exit":
97-
print(dataset) # Print error message if any
111+
if selection is None:
112+
if dataset:
113+
print(dataset) # Print error message
114+
return
115+
116+
if selection == "Exit":
98117
print("Exiting...")
99-
# run_command("make clean", silent=True)
100118
return
101119

102-
print(f"\nRunning {selection} Benchmark with dataset: {dataset}\n" + "="*60 + "\n")
120+
print(f"\nRunning {selection} Benchmark with dataset: {dataset}")
121+
if cores:
122+
print(f"Cores: {cores}")
123+
print("="*60 + "\n")
124+
125+
# Determine core count
126+
omp_prefix = ""
127+
mpi_prefix = ""
128+
129+
if cores:
130+
count = 0
131+
# Divide cores by 2 to account for threading stuff - quick fix
132+
if cores == "ALL":
133+
count = os.cpu_count()/2 or 4
134+
else:
135+
count = int(cores)/2
136+
137+
omp_prefix = f"OMP_NUM_THREADS={count} "
138+
mpi_prefix = f"mpirun -np {count} "
103139

104140
# Run Selected
105141
start_time = time.time()
106142

107-
# Pass dataset as ARGS
108-
# args = f'ARGS="{dataset}"'
109-
110-
# Run the executable of the select benchmark, avoid make rules for overhead concerns
111143
if selection == "Serial":
112144
run_command(f"./QPESeq {dataset}")
113145

114146
elif selection == "OMP":
115-
run_command(f"./QPEOMP {dataset}")
147+
run_command(f"{omp_prefix}./QPEOMP {dataset}")
116148

117149
elif selection == "MPI":
118-
run_command(f"./QPEMPI {dataset}")
150+
run_command(f"{mpi_prefix}./QPEMPI {dataset}")
119151

120152
elif selection == "ALL":
121153
print("--- Running Serial ---")
122154
run_command(f"./QPESeq {dataset}")
123155

124156
print("\n--- Running OMP ---")
125-
run_command(f"./QPEOMP {dataset}")
157+
run_command(f"{omp_prefix}./QPEOMP {dataset}")
126158

127159
print("\n--- Running MPI ---")
128-
run_command(f"./QPEMPI {dataset}")
160+
run_command(f"{mpi_prefix}./QPEMPI {dataset}")
129161

130162
end_time = time.time()
131163
print("\n" + "="*60)
132164
print(f"Total Benchmark Time: {end_time - start_time:.4f} seconds")
133165

134-
# # Run make clean silently
135-
# print("Cleaning up build artifacts...")
136-
# run_command("make clean", silent=True)
137-
# print("Done.")
138-
139166
if __name__ == "__main__":
140167
run_benchmark()

0 commit comments

Comments
 (0)