/*******************************************************************************
*
* TRIQS: a Toolbox for Research in Interacting Quantum Systems
*
* Copyright (C) 2011 by O. Parcollet
*
* TRIQS is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* TRIQS is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* TRIQS. If not, see .
*
******************************************************************************/
#include
#include
using namespace triqs::arrays;
using namespace triqs;
const int N1= 10, N2 = 10;
struct plain_for_no_ptr_const {
void operator()() {
triqs::arrays::array A (N1,N2,FORTRAN_LAYOUT);
for (int u =0; u<2500000; ++u)
for (int j=0; j A (N1,N2,FORTRAN_LAYOUT);
auto V = make_view(A);
for (int u =0; u<2500000; ++u)
//make_view(A) = 1867;
V= 1867;
}
};
struct plain_for_no_ptr {
void operator()() {
triqs::arrays::matrix A (N1,N2, FORTRAN_LAYOUT);
for (int u =0; u<2500000; ++u)
for (int i =0; i::indexmap_type::domain_type::index_value_type index_value_type;
struct F {
triqs::arrays::matrix & a;
F(triqs::arrays::matrix & a_): a(a_){}
//void operator()(value_type & p, index_value_type const & key) const { p=key[0]*10 + key[1] ;}
//void operator()(value_type & p, value_type const & x0, value_type const & x1) const { p=x0*10 + x1 ;}
template void operator()( X0 const & x0, X1 const & x1) const { a(x0,x1) =x0*10 + x1 ;}
};
struct with_foreach {
void operator()() {
triqs::arrays::matrix A (N1,N2,FORTRAN_LAYOUT);
// triqs::arrays::indexmaps::
for (int u =0; u<2500000; ++u) foreach(A,F(A));
// for (int u =0; u<5000; ++u) make_view(A) = 1867;
}
};
struct iterators {
void operator()() {
typedef triqs::arrays::matrix MM;
MM A (N1,N2,FORTRAN_LAYOUT);
for (int u =0; u<3000; ++u)
{
for (auto it = A.begin(); it; ++it) {
*it =10*it.indices()[0] + it.indices()[1] ;
}
}
}
};
template
struct pointer_generic_form {
void operator()() {
triqs::arrays::matrix A (N1,N2, FORTRAN_LAYOUT);
const int_type s0 = A.indexmap().strides()[0];
const int_type s1 = A.indexmap().strides()[1];
const int_type l0 = A.indexmap().lengths()[0];
const int_type l1 = A.indexmap().lengths()[1];
for (int u =0; u<1000; ++u) {
double * restrict p= &(A(0,0));
//typedef int int_type;
//assert(s0==1); assert(s1==N1);
//assert(l0==N1); assert(l1==N2);
for (int_type i0 =0; i0 MM;
MM A (N1,N2,FORTRAN_LAYOUT);
for (int u =0; u<5000; ++u)
{
for (MM::iterator it = A.begin(); it; ++it) {
*it = 1876;
}
}
}
};
struct foreach_manual_simple {
void operator()() {
triqs::arrays::array A (N1,N2,FORTRAN_LAYOUT);
mini_vector t;
const int u[2] = {1,0}; //=1, u1=0;
//int u[2]; for (int i=0; i<2; ++i) u[i] = 1-i;
for (int k =0; k<5000; ++k)
for (t[u[0]]=0; t[u[0]] (l);
speed_tester (l);
std::cout << "----------- Comparing manual loop and foreach for A(i,j) = 10 *i + j--------------------"<< std::endl ;
speed_tester (l);
speed_tester (l);
//speed_tester > (l);
//speed_tester > (l);
//speed_tester(l);
std::cout << "----------- Comparing manual loop and foreach for A(i,j) = 10 *i + j--------------------"<< std::endl ;
speed_tester (l);
speed_tester (l);
return 0;
}