Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add content on performance benchmarks. #460

Closed
wants to merge 89 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
375be0f
Create benchmark.md
khushi-411 Jul 30, 2021
8136aea
Create __init__.py
khushi-411 Aug 3, 2021
45107a7
Create __init__.py
khushi-411 Aug 3, 2021
55c27c7
Datasets here!
khushi-411 Aug 3, 2021
4cee21d
Delete __init__.py
khushi-411 Aug 3, 2021
c0ae310
Update benchmark.md
khushi-411 Aug 3, 2021
868095c
Update benchmark.md
khushi-411 Aug 3, 2021
09eddb9
Update benchmark.md
khushi-411 Aug 3, 2021
bb2091b
Update benchmark.md
khushi-411 Aug 3, 2021
cd7deba
Add files via upload
khushi-411 Aug 4, 2021
bb91dcb
Create __init__.py
khushi-411 Aug 4, 2021
777d242
Update benchmark.md
khushi-411 Aug 4, 2021
c86eb97
Update benchmark.md
khushi-411 Aug 4, 2021
4ca3a7b
Add files via upload
khushi-411 Aug 4, 2021
d1c4b27
Delete __init__.py
khushi-411 Aug 4, 2021
41f6ba8
Update benchmark.md
khushi-411 Aug 4, 2021
7c480fc
Update benchmark.md
khushi-411 Aug 4, 2021
e8ce3e7
Update benchmark.md
khushi-411 Aug 4, 2021
c62cdf7
Update benchmark.md
khushi-411 Aug 4, 2021
3d39ce5
Update benchmark.md
khushi-411 Aug 4, 2021
57d113d
Update benchmark.md
khushi-411 Aug 4, 2021
42de971
Update benchmark-2.py
khushi-411 Aug 4, 2021
39fc943
Update benchmark-2.py
khushi-411 Aug 4, 2021
76fde4b
Update bench.py
khushi-411 Aug 4, 2021
217a999
Update bench_numba.py
khushi-411 Aug 4, 2021
75863f4
Update bench_numpy_highlevel.py
khushi-411 Aug 4, 2021
c558adb
Update benchmark.md
khushi-411 Aug 4, 2021
60cc817
Update benchmark.md
khushi-411 Aug 4, 2021
919e489
Update benchmark.md
khushi-411 Aug 4, 2021
97c8021
Add files via upload
khushi-411 Aug 4, 2021
f5b725f
Update benchmark.md
khushi-411 Aug 4, 2021
a5b312a
Update benchmark.md
khushi-411 Aug 4, 2021
7274b56
Update benchmark.md
khushi-411 Aug 4, 2021
58fa41d
Add files via upload
khushi-411 Aug 4, 2021
47f868a
Update benchmark.md
khushi-411 Aug 4, 2021
47bf944
Update benchmark.md
khushi-411 Aug 4, 2021
7524a72
Delete benchmark-plot.jpg
khushi-411 Aug 4, 2021
a17669d
Add files via upload
khushi-411 Aug 4, 2021
36371cb
Update benchmark.md
khushi-411 Aug 5, 2021
2dcd3db
Update benchmark.md
khushi-411 Aug 5, 2021
e5ebf01
Update benchmark.md
khushi-411 Aug 5, 2021
670673f
Update benchmark.md
khushi-411 Aug 5, 2021
5a9261c
Update benchmark.md
khushi-411 Aug 5, 2021
baac17c
Update benchmark.md
khushi-411 Aug 5, 2021
04160d1
Update benchmark.md
khushi-411 Aug 5, 2021
58f1445
Update benchmark.md
khushi-411 Aug 5, 2021
a6607f7
Update benchmark.md
khushi-411 Aug 6, 2021
fbe17c0
Update benchmark.md
khushi-411 Aug 6, 2021
80a09af
Update benchmark.md
khushi-411 Aug 6, 2021
9df728e
Update config.yaml
khushi-411 Aug 6, 2021
9641ca0
Update config.yaml
khushi-411 Aug 6, 2021
5ae4e4c
Update benchmark.md
khushi-411 Aug 6, 2021
d451d6f
Update bench_numpy_highlevel.py
khushi-411 Aug 6, 2021
8b23628
Update bench_numpy_highlevel.py
khushi-411 Aug 6, 2021
224279b
Update bench_numba.py
khushi-411 Aug 6, 2021
5cabf45
Update bench.py
khushi-411 Aug 6, 2021
7c8a662
Update bench_numpy_highlevel_jit.py
khushi-411 Aug 6, 2021
570fb24
Update benchmark.md
khushi-411 Aug 6, 2021
6107349
Demo: Web page
khushi-411 Aug 7, 2021
bb1c7ec
Demo: testing
khushi-411 Aug 7, 2021
ca8e4be
demo
khushi-411 Aug 7, 2021
c917061
demo
khushi-411 Aug 7, 2021
b35bffb
demo
khushi-411 Aug 7, 2021
642ccbe
demo
khushi-411 Aug 7, 2021
c53cbe8
demo
khushi-411 Aug 7, 2021
268ec9c
demo
khushi-411 Aug 7, 2021
c9f5b66
demo
khushi-411 Aug 7, 2021
28597cc
Update benchmark.md
khushi-411 Aug 8, 2021
b99ce04
Added Overview
khushi-411 Aug 9, 2021
7316a94
Edited
khushi-411 Aug 9, 2021
86be3a4
Merge branch 'khushi-411/add-benchmarks' of https://github.com/khushi…
khushi-411 Aug 9, 2021
7c38ed1
Corrected Code
khushi-411 Aug 9, 2021
b5e1164
Edited
khushi-411 Aug 10, 2021
d853b0e
Edited
khushi-411 Aug 10, 2021
721f025
Edited
khushi-411 Aug 10, 2021
35bf1c2
Edited
khushi-411 Aug 10, 2021
c20c42d
Edited
khushi-411 Aug 10, 2021
9af3112
Edited
khushi-411 Aug 10, 2021
dd8763a
Edited
khushi-411 Aug 10, 2021
334dced
Edited
khushi-411 Aug 10, 2021
9268151
Edited
khushi-411 Aug 10, 2021
b4caeef
Edited
khushi-411 Aug 10, 2021
b182df9
Removed
khushi-411 Aug 11, 2021
b486de6
Edited
khushi-411 Aug 11, 2021
d7e6d91
Edited
khushi-411 Aug 11, 2021
7b662ff
Edited
khushi-411 Aug 11, 2021
c62a00e
Edited
khushi-411 Aug 11, 2021
43f97cf
Edited
khushi-411 Aug 11, 2021
c4a494b
Add files via upload
khushi-411 Aug 11, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
195 changes: 195 additions & 0 deletions benchmarks/cpp/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>

typedef double real;
using namespace std;

// Class Star, contains the properties:
// mass (m)
// position (r)
// velocity (v)
// accelerations (a and a0)

class Star {
public:
real m;
vector<real> r;
vector<real> v;
vector<real> a, a0;
// Default constructor
Star() {
r.assign(3, 0);
v.assign(3, 0);
a.assign(3, 0);
a0.assign(3, 0);
}
// Detailed constructor
Star(real mass, vector<real> pos, vector<real> vel) {
m = mass;
r = pos;
v = vel;
}
// Print function (overloaded << operator)
friend ostream &operator<<(ostream &so, const Star &si) {
so << si.m << " " << si.r[0] << " " << si.r[1] << " " << si.r[2] << " "
<< si.v[0] << " " << si.v[1] << " " << si.v[2] << endl;
return so;
}
};
// Star cluster based on the Star class
// A star cluster contains a number of stars
// stored in the vector S
//
class Cluster : public Star {
protected:
public:
vector<Star> s;
Cluster() : Star() {}
// Computes the acceleration of each star in the cluster
void acceleration() {
for (vector<Star>::iterator si = s.begin(); si != s.end(); ++si)
si->a.assign(3, 0);
// For each star
for (vector<Star>::iterator si = s.begin(); si != s.end(); ++si) {
vector<real> rij(3);
real init = 0.0;
// For each remaining star
for (vector<Star>::iterator sj = s.begin(); sj != s.end(); ++sj) {
if (si != sj) {
// Distance difference between the two stars
for (int i = 0; i != 3; ++i)
rij[i] = si->r[i] - sj->r[i];
// Sum of the dot product
real RdotR = inner_product(rij.begin(), rij.end(), rij.begin(), init);
real apre = 1. / sqrt(RdotR * RdotR * RdotR);
// Update accelerations
for (int i = 0; i != 3; ++i) {
si->a[i] -= sj->m * apre * rij[i];
}
} // end for
} // si != sj
} // end for
} // end acceleration

// Update positions
void updatePositions(real dt) {
for (vector<Star>::iterator si = s.begin(); si != s.end(); ++si) {
// Update the positions, based on the calculated accelerations and
// velocities
si->a0 = si->a;
for (int i = 0; i != 3; ++i) // for each axis (x/y/z)
si->r[i] += dt * si->v[i] + 0.5 * dt * dt * si->a0[i];
}
}

// Update velocities based on previous and new accelerations
void updateVelocities(real dt) {
// Update the velocities based on the previous and old accelerations
for (vector<Star>::iterator si = s.begin(); si != s.end(); ++si) {
for (int i = 0; i != 3; ++i)
si->v[i] += 0.5 * dt * (si->a0[i] + si->a[i]);
si->a0 = si->a;
}
}

// Compute the energy of the system,
// contains an expensive O(N^2) part which can be moved to the acceleration
// part where this is already calculated
vector<real> energies() {
real init = 0;
vector<real> E(3), rij(3);
E.assign(3, 0);

// Kinetic energy
for (vector<Star>::iterator si = s.begin(); si != s.end(); ++si)
E[1] += 0.5 * si->m *
inner_product(si->v.begin(), si->v.end(), si->v.begin(), init);

// Potential energy
for (vector<Star>::iterator si = s.begin(); si != s.end(); ++si) {
for (vector<Star>::iterator sj = si + 1; sj != s.end(); ++sj) {
for (int i = 0; i != 3; ++i)
rij[i] = si->r[i] - sj->r[i];
E[2] -= si->m * sj->m /
sqrt(inner_product(rij.begin(), rij.end(), rij.begin(), init));
}
}
E[0] = E[1] + E[2];
return E;
}

// Print function
friend ostream &operator<<(ostream &so, Cluster &cl) {
for (vector<Star>::iterator si = cl.s.begin(); si != cl.s.end(); ++si)
so << *si;
return so;
}
};

int main(int argc, char* argv[]) {

Cluster cl;
real m;
int dummy;
vector<real> r(3), v(3);

// Read input data from the command line (makeplummer | dumbp)
do {
cin >> dummy;
cin >> m;
for (int i = 0; i != 3; ++i)
cin >> r[i];
for (int i = 0; i != 3; ++i)
cin >> v[i];
cl.s.push_back(Star(m, r, v));
} while (!cin.eof());

// Remove the last one
cl.s.pop_back();

// Compute initial energu of the system
vector<real> E(3), E0(3);
E0 = cl.energies();
cerr << "Energies: " << E0[0] << " " << E0[1] << " " << E0[2] << endl;

// Start time, end time and simulation step
real t = 0.0;
real tend;

if (argc > 1)
tend = strtod(argv[1], NULL);
else
tend = 10.0;

real dt = 1e-3;
int k = 0;

// Initialize the accelerations
cl.acceleration();

// Start the main loop
while (t < tend) {
// Update positions based on velocities and accelerations
cl.updatePositions(dt);

// Get new accelerations
cl.acceleration();

// Update velocities
cl.updateVelocities(dt);

t += dt;
k += 1;
if (k % 100 == 0) {
E = cl.energies();
cout << "t= " << t << " E= " << E[0] << " " << E[1] << " " << E[2]
<< " dE/E = " << (E[0] - E0[0]) / E0[0] << endl;
}
} // end while

cout << "number time steps: " << k << endl;

return 0;
} // end program
Loading