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

[clef] timing examples #514

Open
wants to merge 1 commit into
base: unstable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
179 changes: 179 additions & 0 deletions benchmark/clef_speed.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@

#include <triqs/clef.hpp>
#include <triqs/gfs.hpp>
#include <triqs/utility/timer.hpp>

using namespace triqs;
using namespace triqs::gfs;

// Index placeholders
clef::placeholder<0> i;
clef::placeholder<1> j;
clef::placeholder<2> k;
clef::placeholder<3> l;

// Frequency placeholders
clef::placeholder<4> w;
clef::placeholder<5> n1;
clef::placeholder<6> n2;
clef::placeholder<7> n3;

typedef gf<cartesian_product<imfreq, imfreq, imfreq>, tensor_valued<4>> g2_iw_t;

double test_clef_clef(int n=20, int m=20, double beta=1.0) {
utility::timer timer;
auto G2_iw_ph = g2_iw_t{
{{beta, Boson, n}, {beta, Fermion, m}, {beta, Fermion, m}}, {1, 1, 1, 1}};
timer.start();

G2_iw_ph(w,n1,n2)(i,j,k,l) << 0.0;

timer.stop();
return double(timer);
}

double test_loop_clef(int n=20, int m=20, double beta=1.0) {
utility::timer timer;
gf_mesh<imfreq> mesh_b{beta, Boson, n};
gf_mesh<imfreq> mesh_f{beta, Fermion, m};
auto G2_iw_ph = g2_iw_t{{mesh_b, mesh_f, mesh_f}, {1, 1, 1, 1}};
timer.start();

for(auto const& w : mesh_b)
for(auto const& n1 : mesh_f)
for(auto const& n2 : mesh_f)
G2_iw_ph[w,n1,n2](i,j,k,l) << 0.0;

timer.stop();
return double(timer);
}

double test_loop_loop(int n=20, int m=20, double beta=1.0) {
utility::timer timer;
gf_mesh<imfreq> mesh_b{beta, Boson, n};
gf_mesh<imfreq> mesh_f{beta, Fermion, m};
auto G2_iw_ph = g2_iw_t{{mesh_b, mesh_f, mesh_f}, {1, 1, 1, 1}};
timer.start();

int size_0 = G2_iw_ph.target_shape()[0];
int size_1 = G2_iw_ph.target_shape()[1];
int size_2 = G2_iw_ph.target_shape()[2];
int size_3 = G2_iw_ph.target_shape()[3];

for(auto const& w : mesh_b)
for(auto const& n1 : mesh_f)
for(auto const& n2 : mesh_f)
for(int i : range(size_0))
for(int j : range(size_1))
for(int k : range(size_2))
for(int l : range(size_3))
G2_iw_ph[w,n1,n2](i,j,k,l) = 0.0;

timer.stop();
return double(timer);
}

double test_loop_loop_bracket(int n=20, int m=20, double beta=1.0) {
utility::timer timer;
gf_mesh<imfreq> mesh_b{beta, Boson, n};
gf_mesh<imfreq> mesh_f{beta, Fermion, m};
auto G2_iw_ph = g2_iw_t{{mesh_b, mesh_f, mesh_f}, {1, 1, 1, 1}};
timer.start();

int size_0 = G2_iw_ph.target_shape()[0];
int size_1 = G2_iw_ph.target_shape()[1];
int size_2 = G2_iw_ph.target_shape()[2];
int size_3 = G2_iw_ph.target_shape()[3];

for(auto const& w : mesh_b)
for(auto const& n1 : mesh_f)
for(auto const& n2 : mesh_f)
for(int i : range(size_0))
for(int j : range(size_1))
for(int k : range(size_2))
for(int l : range(size_3))
G2_iw_ph[{w,n1,n2}](i,j,k,l) = 0.0;

timer.stop();
return double(timer);
}

double test_loop_loop_constexpr_target(int n=20, int m=20, double beta=1.0) {
utility::timer timer;
gf_mesh<imfreq> mesh_b{beta, Boson, n};
gf_mesh<imfreq> mesh_f{beta, Fermion, m};
auto G2_iw_ph = g2_iw_t{{mesh_b, mesh_f, mesh_f}, {1, 1, 1, 1}};
timer.start();

auto size_0 = 1;
auto size_1 = 1;
auto size_2 = 1;
auto size_3 = 1;

for(auto const& w : mesh_b)
for(auto const& n1 : mesh_f)
for(auto const& n2 : mesh_f)
for(int i : range(size_0))
for(int j : range(size_1))
for(int k : range(size_2))
for(int l : range(size_3))
G2_iw_ph[{w,n1,n2}](i,j,k,l) = 0.0;

timer.stop();
return double(timer);
}

double test_loop_fixed(int n=20, int m=20, double beta=1.0) {
utility::timer timer;
gf_mesh<imfreq> mesh_b{beta, Boson, n};
gf_mesh<imfreq> mesh_f{beta, Fermion, m};
auto G2_iw_ph = g2_iw_t{{mesh_b, mesh_f, mesh_f}, {1, 1, 1, 1}};
timer.start();

for(auto const& w : mesh_b)
for(auto const& n1 : mesh_f)
for(auto const& n2 : mesh_f)
G2_iw_ph[w,n1,n2](0,0,0,0) = 0.0;

timer.stop();
return double(timer);
}

double test_array(int n=20, int m=20, double beta=1.0) {
utility::timer timer;
gf_mesh<imfreq> mesh_b{beta, Boson, n};
gf_mesh<imfreq> mesh_f{beta, Fermion, m};
auto G2_iw_ph = g2_iw_t{{mesh_b, mesh_f, mesh_f}, {1, 1, 1, 1}};
timer.start();

G2_iw_ph.data() *= 0.0;

timer.stop();
return double(timer);
}

/*

//#include <Eigen/Core>
//#include <Eigen/Dense>
//#include <unsupported/Eigen/CXX11/Tensor>

double test_eigen_tensor(int n=20, int m=20, double beta=1.0) {
utility::timer timer;
gf_mesh<imfreq> mesh_b{beta, Boson, n};
gf_mesh<imfreq> mesh_f{beta, Fermion, m};
auto G2_iw_ph = g2_iw_t{{mesh_b, mesh_f, mesh_f}, {1, 1, 1, 1}};

// create eigen tensor view of the data ?!?!
template<int I> using Tensor = Eigen::Tensor<std::complex<double>, I, Eigen::RowMajor>;
Eigen::TensorMap<Tensor<7>> data(G2_iw_ph.data(), n, m, m, 1, 1, 1, 1);

timer.start();

data = 0.0;

timer.stop();
return double(timer);
}

*/
23 changes: 23 additions & 0 deletions benchmark/clef_speed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import numpy as np
from cpp2py.compiler import compile

filename = 'clef_speed.cpp'

code = ''.join(open(filename, 'r').readlines())

cxxflags = '-O3 -march=native -Ofast -mavx -mfma -mavx2 -g -ggdb -Wno-invalid-partial-specialization '

includes = ' -I /opt/local/include/ -I /opt/local/include/openmpi-clang40 '

M = compile(code, modules = "pytriqs", cxxflags=cxxflags + includes)

print '--> Running clef timing tests'
tests = np.array([
getattr(M, method) for method in M.__dict__.keys() if 'test_' in method])
times = np.array([test(n=80, m=80) for test in tests])

sidx = np.argsort(times)[::-1]
times, tests = times[sidx], tests[sidx]

for time, test in zip(times, tests):
print '%40s -- %10.2f ms' % (test.__name__, 1000.0 * time)