-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_steps100.py
More file actions
75 lines (53 loc) · 2.65 KB
/
main_steps100.py
File metadata and controls
75 lines (53 loc) · 2.65 KB
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
73
74
import algos
import utils
import time
def main():
# Main function to run benchmarking and plotting for selected matrix multiplication algorithms
while True:
# Dictionary mapping method names to their corresponding functions
Methods = {
"Naive method": algos.normal_method,
"Strassen method": algos.strassen_method,
"Block method": algos.block_method,
"Numpy method": algos.numpy_method,
"Parallel CPU method": algos.parallel_method,
"GPU CuPy method": algos.gpu_cupy_method
}
# Selecting the algos to plot benchmark
for num , method in enumerate(Methods.keys()):
print(f"{num}: {method}")
method = input("Select method (Give the corresponding numbers): ").split()
# Validation for method selection
if (
len(method) == 0
or not all(m.isdigit() for m in method)
or not all(0 <= int(m) < len(Methods) for m in method)
):
print("-->!!! Invalid selection. Please enter valid method numbers.")
continue
N = 1000 # Maximum matrix size
otuput_name ='_'.join([list(Methods.keys())[int(m)].replace(" " , "_") for m in method])
start = time.perf_counter()
# Benchmarking loop
for n in range(1,N+1,100):
A = utils.generate_mat(n , low = 0 , high = 100 , seed = 42 , dtype = float)
B = utils.generate_mat(n , low = 0 , high = 100 , seed = 24 , dtype = float)
# Iterating through selected methods
for m in method:
method_name = list(Methods.keys())[int(m)]
func = Methods[method_name]
result , elapsed_time = utils.benchmark(func , A , B)
utils.log_result(method_name , n , elapsed_time , output_dir = f"results/data/{otuput_name}" + f"_steps100_{N}.csv")
# Plotting the results
utils.plotter( csv_file= f"results/data/{otuput_name}" + f"_steps100_{N}.csv" , output_image = f"results/plots/{otuput_name }" + f"_steps100_{N}.png")
finish = time.perf_counter()
print(f"Total benchmarking time: {finish - start} seconds")
print("Benchmarking completed and results plotted. Timing log and performance graph saved.")
# Prompt to continue or exit
cont = input("Do you want to continue? (y/n): ")
if cont.lower() != 'y':
break
if __name__ == "__main__":
# Entry point of the program .
# During multiprocessing the spawned child processes will not execute main() .
main()