Skip to content

Commit 9e19e0d

Browse files
committed
Add Single implementation of compiled methods, made correction in C++ code, modified graph, removed unnecessary files.
1 parent a496e53 commit 9e19e0d

File tree

10 files changed

+72
-187
lines changed

10 files changed

+72
-187
lines changed

benchmarks/cpp/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ int main(int argc, char* argv[]) {
163163
E = cl.energies();
164164
}
165165
}
166+
t = 0;
166167
}
167168

168169
return 0;

benchmarks/python/acc_numba.py

Lines changed: 0 additions & 111 deletions
This file was deleted.

benchmarks/python/acc_pythran.py renamed to benchmarks/python/compiled_methods.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def compute_accelerations(accelerations, masses, positions):
4040
return accelerations
4141

4242
@jit
43-
def pythran_loop(
43+
def loop(
4444
time_step, nb_steps, masses, positions,
4545
velocities):
4646

@@ -72,7 +72,7 @@ def pythran_loop(
7272

7373
def compute_energies(masses, positions, velocities):
7474

75-
ke = 0.5 * np.sum(masses * np.sum(velocities**2, axis=1))
75+
ke = 0.5 * masses @ np.sum(velocities**2, axis=1)
7676

7777
nb_particles = masses.size
7878
pe = 0.0
@@ -103,4 +103,4 @@ def compute_energies(masses, positions, velocities):
103103
path_input = sys.argv[1]
104104
masses, positions, velocities = load_input_data(path_input)
105105

106-
print('time taken:', timeit.timeit('pythran_loop(time_step, nb_steps, masses, positions, velocities)', globals=globals(), number=50))
106+
print('time taken:', timeit.timeit('loop(time_step, nb_steps, masses, positions, velocities)', globals=globals(), number=50))

benchmarks/python/optimized-numpy.py renamed to benchmarks/python/numpy_python.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def compute_accelerations(accelerations, masses, positions):
2929
distances = (vectors**2).sum(axis=1)
3030
coefs = 1./distances**1.5
3131

32-
accelerations[index_p0] += np.sum((masses[index_p0 + 1: nb_particles] * -1 * vectors.T * coefs), axis=0)
32+
accelerations[index_p0] += np.sum((masses[index_p0 + 1: nb_particles] * -1 * vectors.T * coefs).T, axis=0)
3333
accelerations[index_p0 + 1: nb_particles] += (mass0 * vectors.T * coefs).T
3434

3535
return accelerations
@@ -71,7 +71,7 @@ def numpy_loop(
7171

7272
def compute_energies(masses, positions, velocities):
7373

74-
ke = 0.5 * np.sum(masses * np.sum(velocities**2, axis=1))
74+
ke = 0.5 * masses @ np.sum(velocities**2, axis=1)
7575

7676
nb_particles = masses.size
7777
pe = 0.0

benchmarks/python/plot.py

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,31 @@
22
import pandas as pd
33
import matplotlib.pyplot as plt
44

5-
65
def plot(x, labels, list_df, names):
76

8-
plt.figure(figsize=(350, 220), dpi=50)
7+
plt.figure(figsize=(350, 220), dpi=30)
98
plt.subplot(2, 1, 1)
10-
9+
1110
width = 0.25
1211
rect = [0, 0, 0]
13-
12+
1413
list1 = []
1514
for ind, list in enumerate(list_df):
1615
if ind < 2:
1716
list1.append(list)
18-
17+
1918
for ind, time_taken in enumerate(list1):
20-
rect[ind] = plt.bar(x + width * ind, time_taken, width, align = 'center', label = labels[ind])
21-
plt.bar_label(rect[ind], padding = 3, fontsize = 250)
22-
23-
plt.xticks(x + width / 2, names, fontsize = 300)
24-
plt.yticks(fontsize = 300)
25-
plt.legend(fontsize = 250)
19+
rect[ind] = plt.bar(x + width*ind, time_taken, width, align='center', label=labels[ind])
20+
plt.bar_label(rect[ind], padding=3, fontsize=250)
21+
22+
plt.xticks(x + width/2, names, fontsize=300)
23+
plt.tick_params(axis='x', which='major', pad=50)
24+
plt.yticks(fontsize=300)
25+
plt.legend(fontsize=250)
2626

27-
plt.ylabel(r'$\frac{Time}{nParticles^2}$', fontsize = 300)
28-
plt.xlabel(r"$Number\ of\ Particles\ Simulated(nParticles)$", fontsize = 250)
29-
plt.title(r"$Library\ used\ for\ Implementation$", fontsize = 300)
27+
plt.ylabel(r'$\frac{Time}{nParticles^2}$', fontsize=350)
28+
plt.xlabel(r"$Number\ of\ Particles\ Simulated(nParticles)$", fontsize=270)
29+
plt.title(r"$Library\ based\ Implementation$", fontsize=300)
3030

3131
plt.subplot(2, 1, 2)
3232
rect = [0, 0, 0]
@@ -36,30 +36,32 @@ def plot(x, labels, list_df, names):
3636
for ind, list in enumerate(list_df):
3737
if ind >= 2:
3838
list2.append(list)
39-
39+
4040
j = 2
4141
for ind, time_taken in enumerate(list2):
42-
rect[ind] = plt.bar(x + width * ind, time_taken, width, align = 'center', color = colors[ind % len(colors)], label = labels[j])
42+
rect[ind] = plt.bar(x + width*ind, time_taken, width, align='center', color=colors[ind % len(colors)], label=labels[j])
4343
j += 1
44-
plt.bar_label(rect[ind], padding = 3, fontsize = 250)
45-
46-
plt.xticks(x + width, names, fontsize = 300)
47-
plt.yticks(fontsize = 300)
48-
plt.legend(fontsize = 250)
49-
50-
plt.ylabel(r'$\frac{Time}{nParticles^2}$', fontsize = 300)
51-
plt.xlabel(r"$Number\ of\ Particles\ Simulated(nParticles)$", fontsize = 250)
52-
plt.title(r"$Accelerator\ used\ for\ Implementation$", fontsize = 300)
44+
plt.bar_label(rect[ind], padding=3, fontsize=250)
45+
46+
plt.xticks(x + width, names, fontsize=300)
47+
plt.yticks(fontsize=300)
48+
plt.legend(fontsize=250)
49+
50+
plt.ylabel(r'$\frac{Time}{nParticles^2}$', fontsize=350)
51+
plt.tick_params(axis='x', which='major', pad=50)
52+
plt.xlabel(r"$Number\ of\ Particles\ Simulated(nParticles)$", fontsize=270)
53+
plt.title(r"$Compiler\ based\ Implementation$", fontsize=300)
5354

54-
plt.tight_layout(pad = 70.0)
55-
plt.savefig("benchmarking-numpy")
55+
plt.tight_layout(pad=70.0)
56+
plt.savefig("performance_benchmarking")
5657

5758
if __name__ == "__main__":
58-
data_path = "table.csv"
59+
60+
data_path = "data/table.csv"
5961
df = pd.read_csv(data_path)
60-
df = df.drop(['Unnamed: 0'], axis = 1)
62+
df = df.drop(['Unnamed: 0'], axis=1)
6163
df = df.T
62-
df.columns = ["NumPy", "Python", "C++", "Numba", "Pythran: Transonic"]
64+
df.columns = ["NumPy", "Python", "C++", "Numba", "Pythran"]
6365

6466
labels = df.columns
6567
names = ["16", "32", "64", "128"]
@@ -69,4 +71,3 @@ def plot(x, labels, list_df, names):
6971
list_df = df[0:].to_numpy().tolist()
7072

7173
plot(x, labels, list_df, names)
72-

benchmarks/python/pure-python.py renamed to benchmarks/python/pure_python.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,4 @@ def compute_energies(masses, positions, velocities):
151151
positions = positions.tolist()
152152
velocities = velocities.tolist()
153153

154-
print('time taken', timeit.timeit('loop(time_step, nb_steps, masses, positions, velocities'), globals=globals(), number=50)
154+
print('time taken', timeit.timeit('loop(time_step, nb_steps, masses, positions, velocities)', globals=globals(), number=50))

content/en/benchmark.md

Lines changed: 33 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: NumPy Benchmarks
33
sidebar: false
44
---
55

6-
<img src = "/images/content_images/benchmarking-numpy.png" alt = "Visualization" title = "Performance Benchmark; Number of Iterations: 5">
6+
<img src = "/images/content_images/performance_benchmarking.png" alt = "Visualization" title = "Performance Benchmark; Number of Iterations: 5">
77

88

99
## Overview
@@ -156,37 +156,37 @@ table, th, td {
156156
<tr>
157157
<tr>
158158
<td><b>NumPy</b></td>
159-
<td>0.0928</td>
160-
<td>0.1786</td>
161-
<td>0.2613</td>
162-
<td>0.1609</td>
159+
<td>12.61</td>
160+
<td>13.88</td>
161+
<td>15.59</td>
162+
<td>17.9</td>
163163
</tr>
164164
<tr>
165165
<td><b>Python</b></td>
166-
<td>0.8372</td>
167-
<td>0.8629</td>
168-
<td>0.8420</td>
169-
<td>0.7670</td>
166+
<td>12.85</td>
167+
<td>26.82</td>
168+
<td>50.13</td>
169+
<td>105.01</td>
170170
</tr>
171171
<tr>
172172
<td><b>C++</b></td>
173-
<td>0.0027</td>
174-
<td>0.0021</td>
175-
<td>0.0018</td>
176-
<td>0.0018</td>
173+
<td>1.646</td>
174+
<td>3.206</td>
175+
<td>5.725</td>
176+
<td>11.44</td>
177177
<tr>
178178
<td><b>Numba</b></td>
179-
<td>0.0569</td>
180-
<td>0.0355</td>
181-
<td>0.0290</td>
182-
<td>0.0207</td>
179+
<td>1.567</td>
180+
<td>3.223</td>
181+
<td>6.521</td>
182+
<td>13.64</td>
183183
</tr>
184184
<tr>
185-
<td><b>Pythran-Naive: Transonic</b></td>
186-
<td>0.0111</td>
187-
<td>0.0089</td>
188-
<td>0.0083</td>
189-
<td>0.0078</td>
185+
<td><b>Pythran</b></td>
186+
<td>0.3177</td>
187+
<td>0.6591</td>
188+
<td>1.2811</td>
189+
<td>2.5082</td>
190190
</tr>
191191
</table>
192192
</body>
@@ -219,34 +219,28 @@ table, th, td {
219219
</head>
220220
<table>
221221
<tr>
222-
<td><b>Algorithms</b></td>
223-
<td><b>Source Code</b></td>
222+
<td><b>Algorithm & Source Code</b></td>
224223
<td><b>Implementation Details</b></td>
225224
</tr>
226225
<tr>
227-
<td>NumPy</td>
228-
<td><a href = "/benchmarks/python/optimized-numpy.py">optimized-numpy.py</a></td>
229-
<td>NumPy Implementation</td>
226+
<td><a href = "/benchmarks/python/optimized_numpy.py">NumPy</a></td>
227+
<td>Vectorized Approach</td>
230228
</tr>
231229
<tr>
232-
<td>Python</td>
233-
<td><a href = "/benchmarks/python/pure-python.py">pure-python.py</a></td>
234-
<td>Python Implementation</td>
230+
<td><a href = "/benchmarks/python/pure_python.py">Python</a></td>
231+
<td>Standard Python Approach</td>
235232
</tr>
236233
<tr>
237-
<td>C++</td>
238-
<td><a href = "/benchmarks/cpp/main.cpp">main.cpp</a></td>
239-
<td>C++ Implementation</td>
234+
<td><a href = "/benchmarks/cpp/main.cpp">C++</a></td>
235+
<td>C++ Implementation, GNU C++ Compiler</td>
240236
</tr>
241237
<tr>
242-
<td>Numba</td>
243-
<td><a href = "/benchmarks/python/acc_numba.py">acc_numba.py</a></td>
244-
<td>Just-In-time Compilation</td>
238+
<td><a href = "/benchmarks/python/compiled_methods.py">Numba</a></td>
239+
<td>Just-In-time Compilation, Non-Vectorized Approach, Numba via Transonic Compiler</td>
245240
</tr>
246241
<tr>
247-
<td>Pythran: Transonic Jit</td>
248-
<td><a href = "/benchmarks/python/acc_pythran.py">acc_pythran.py</a></td>
249-
<td>Just-In-Time Compilation</td>
242+
<td><a href = "/benchmarks/python/compiled_methods.py">Pythran</a></td>
243+
<td>Just-In-Time Compilation, Non-Vectorized Approach, Pythran via Transonic Compiler</td>
250244
</tr>
251245
</table>
252246
</html>
Binary file not shown.
Loading

static/images/content_images/plot.png

-423 KB
Binary file not shown.

0 commit comments

Comments
 (0)