3
0
mirror of https://github.com/triqs/dft_tools synced 2024-12-25 13:53:40 +01:00
dft_tools/test/speed/array_view.cpp
Olivier Parcollet fc2a620eae arrays: new ref counting and weak views
- improve the mem_block and shared_block.
- the reference counting is now done in the mem_block and shared_block, removing the need of shared_ptr.

- speed tests shows that shared_ptr is very slow (due to thread safety?)
the new version is much better, though not perfect.

- Hence introducing weak views.

- also :
-- clean the guard mechanism for python (to allow returning from python without any python ref left).
-- clean code, add documentation for mem_block
-- remove nan init, which was not working, and corresponding test
-- serialisation of view still unchanged (need to forbid serialization of view ??).

- tests ok, incl. valgrind tests.
2013-07-23 08:13:44 +02:00

78 lines
1.4 KiB
C++

//#define TRIQS_ARRAYS_ENFORCE_BOUNDCHECK
#include <triqs/arrays.hpp>
#include <triqs/arrays/matrix_view_proxy.hpp>
using namespace triqs::arrays;
#define TEST(X) std::cout << BOOST_PP_STRINGIZE((X)) << " ---> "<< (X) <<std::endl<<std::endl;
const int nl_interne = 100000;
const int N = 1000;
typedef double VALUE_TYPE;
//typedef int VALUE_TYPE;
inline VALUE_TYPE fnt(size_t i) { return i*(i+2.0)*(i-8.0);}
//inline VALUE_TYPE fnt(size_t i) { return i;} //*(i+2.0)*(i-8);}
//inline VALUE_TYPE fnt(size_t i) { return i*(i+2.0)*(i-8);}
struct with_view {
void operator()() {
array<double,3> A(N,2,2);
A() =0;
for (int u =0; u<nl_interne; ++u)
for (int i =0; i<N-1; ++i) A(i,range(), range()) (0,0) = fnt(i);
}
};
struct with_proxy {
void operator()() {
array<double,3> A(N,2,2);
A() =0;
for (int u =0; u<nl_interne; ++u)
for (int i =0; i<N-1; ++i) matrix_view_proxy<array<double,3>, 0>(A,i) (0,0) = fnt(i);
}
};
struct direct {
void operator()() {
array<double,3> A(N,2,2);
A() =0;
for (int u =0; u<nl_interne; ++u)
for (int i =0; i<N-1; ++i) A(i,0,0) = fnt(i);
}
};
struct direct2 {
void operator()() {
array<double,1> A(N);
A() =0;
for (int u =0; u<nl_interne; ++u)
for (int i =0; i<N-1; ++i) A(i) = fnt(i);
}
};
#include "./speed_tester.hpp"
int main() {
speed_tester<direct> (50);
speed_tester<with_proxy> (50);
speed_tester<with_view> (50);
speed_tester<direct2> (50);
//speed_tester<with_slices> (5000);
return 0;
}