generated from bsamseth/cpp-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenGraphs.py
150 lines (144 loc) · 6.82 KB
/
genGraphs.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import os
experiments = [
f
for f in os.listdir("experiments")
if os.path.isdir(os.path.join("experiments", f))
]
def perf(experiment, files):
speedup_files = [f for f in files if "speedup" in f]
speedup_files.sort()
time_files = [f for f in files if "speedup" not in f]
time_files.sort()
plt.figure(figsize=(10, 10))
for i in range(len(speedup_files)):
df = pd.read_csv(speedup_files[i])
numElements = speedup_files[i].split("_")[-1].split(".")[0]
plt.plot(df["numThreads"], df["speedup"], label=numElements)
# Plot a unit line
plt.plot([1, 16], [1, 16], label="Ideal")
# plot grid
plt.grid()
plt.title(f"Speedup vs number of threads for different number of elements")
plt.xlabel("Number of threads")
plt.ylabel("Speedup")
plt.legend()
plt.savefig(f"experiments/{experiment}/speedup.png")
plt.figure(figsize=(10, 10))
for i in range(len(time_files)):
df = pd.read_csv(time_files[i])
numElements = speedup_files[i].split("_")[-1].split(".")[0]
plt.plot(df["numThreads"], df["time"], label=numElements)
plt.grid()
plt.title(f"Time vs number of threads for different number of elements")
plt.xlabel("Number of threads")
plt.ylabel("Time")
plt.legend()
plt.savefig(f"experiments/{experiment}/time.png")
for experiment in experiments:
files = [
os.path.join("experiments", experiment, f)
for f in os.listdir(os.path.join("experiments", experiment))
if f.endswith(".csv")
]
if experiment == "performance":
perf(experiment, files)
elif experiment == "phases":
for i in range(len(files)):
df = pd.read_csv(files[i])
numElements = files[i].split("_")[-1].split(".")[0]
# numThreads,phase1,phase2,phase3,phase4
plt.figure(figsize=(10, 10))
# using stackplot
plt.stackplot(
df["numThreads"],
df["phase1"],
df["phase2"],
df["phase3"],
df["phase4"],
labels=["phase1", "phase2", "phase3", "phase4"],
)
plt.grid()
plt.title(f"Time spent in each phase for {numElements} elements")
plt.xlabel("Number of threads")
plt.ylabel("Time")
plt.legend()
plt.savefig(f"experiments/{experiment}/phases_{numElements}.png")
elif experiment == "sampling":
random_time_files = [f for f in files if "random" in f and "speedup" not in f]
random_time_files.sort()
regular_time_files = [f for f in files if "regular" in f and "speedup" not in f]
regular_time_files.sort()
combined_time_files = list(zip(random_time_files, regular_time_files))
for i in range(len(combined_time_files)):
random_df = pd.read_csv(combined_time_files[i][0])
regular_df = pd.read_csv(combined_time_files[i][1])
numElements = combined_time_files[i][0].split("_")[-1].split(".")[0]
plt.figure(figsize=(10, 10))
plt.plot(random_df["numThreads"], random_df["time"], label="random")
plt.plot(regular_df["numThreads"], regular_df["time"], label="regular")
plt.grid()
plt.title(f"Time vs number of threads for {numElements} elements")
plt.xlabel("Number of threads")
plt.ylabel("Time")
plt.legend()
plt.savefig(f"experiments/{experiment}/sampling_{numElements}.png")
random_speedup_files = [f for f in files if "random" in f and "speedup" in f]
random_speedup_files.sort()
regular_speedup_files = [f for f in files if "regular" in f and "speedup" in f]
regular_speedup_files.sort()
combined_speedup_files = list(zip(random_speedup_files, regular_speedup_files))
for i in range(len(combined_speedup_files)):
random_df = pd.read_csv(combined_speedup_files[i][0])
regular_df = pd.read_csv(combined_speedup_files[i][1])
numElements = combined_speedup_files[i][0].split("_")[-2]
plt.figure(figsize=(10, 10))
plt.plot(random_df["numThreads"], random_df["speedup"], label="random")
plt.plot(regular_df["numThreads"], regular_df["speedup"], label="regular")
plt.grid()
plt.title(f"Speedup vs number of threads for {numElements} elements")
plt.xlabel("Number of threads")
plt.ylabel("Speedup")
plt.legend()
plt.savefig(f"experiments/{experiment}/speedup_sampling_{numElements}.png")
elif experiment == "distribution":
normal_time_files = [f for f in files if "normal" in f and "speedup" not in f]
normal_time_files.sort()
uniform_time_files = [f for f in files if "uniform" in f and "speedup" not in f]
uniform_time_files.sort()
combined_time_files = list(zip(normal_time_files, uniform_time_files))
for i in range(len(combined_time_files)):
normal_df = pd.read_csv(combined_time_files[i][0])
uniform_df = pd.read_csv(combined_time_files[i][1])
numElements = combined_time_files[i][0].split("_")[-1].split(".")[0]
plt.figure(figsize=(10, 10))
plt.plot(normal_df["numThreads"], normal_df["time"], label="normal")
plt.plot(uniform_df["numThreads"], uniform_df["time"], label="uniform")
plt.grid()
plt.title(f"Time vs number of threads for {numElements} elements")
plt.xlabel("Number of threads")
plt.ylabel("Time")
plt.legend()
plt.savefig(f"experiments/{experiment}/distribution_{numElements}.png")
normal_speedup_files = [f for f in files if "normal" in f and "speedup" in f]
normal_speedup_files.sort()
uniform_speedup_files = [f for f in files if "uniform" in f and "speedup" in f]
uniform_speedup_files.sort()
combined_speedup_files = list(zip(normal_speedup_files, uniform_speedup_files))
for i in range(len(combined_speedup_files)):
normal_df = pd.read_csv(combined_speedup_files[i][0])
uniform_df = pd.read_csv(combined_speedup_files[i][1])
numElements = combined_speedup_files[i][0].split("_")[-2]
plt.figure(figsize=(10, 10))
plt.plot(normal_df["numThreads"], normal_df["speedup"], label="normal")
plt.plot(uniform_df["numThreads"], uniform_df["speedup"], label="uniform")
plt.grid()
plt.title(f"Speedup vs number of threads for {numElements} elements")
plt.xlabel("Number of threads")
plt.ylabel("Speedup")
plt.legend()
plt.savefig(
f"experiments/{experiment}/distribution_{numElements}_speedup.png"
)