Re: [eigen] copy constructor / assignment operator potential issue?

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


Gael,

Thanks for your reply. We actually found a bug in our timer (also it's weird that boost timer "V1" doesn't use
clock_gettime but gettimeofday - looking forward to get boost 1.48 more widespread with its "V2" timer library --
anyway...), and as you mentioned, the result do differ quite a bit based on what compiler we used. However, it seemed to
be a fluke on our side. Sorry for the noise :)

Cheers,
Radu.

On 01/04/2012 05:10 AM, Gael Guennebaud wrote:
> Hi,
> 
> I think that your loops are too naive, the compiler could be able to
> simply remove it and only does the last copy. It is usually preferable
> to wrap trivial code into a non inlined function, e.g.:
> 
> template<typename T1, typename T2>
> EIGEN_DONT_INLINE void foo(T1& vec, const T2& mat, int j)
> {
>   vec = mat.row(j);
> }
> 
> and then do, e.g.:
> 
>   int nr = mat.rows ();
>   BENCH(t1, tries, rep, for (int j = 0; j < nr; ++j) foo(vec1,mat,j););
>   std::cerr << t1.best() << "s\n";
> 
>   BENCH(t2, tries, rep, for (int j = 0; j < mat.rows(); ++j) foo(vec2,mat,j););
>   std::cerr << t2.best() << "s\n";
> 
> Doing so I obtained:
> 
> Gaels-MacBook-Pro:bugs gaelguennebaud$ CXX=g++-4.2 sh run.sh
> -e
> a) row major + EIGEN_NO_DEBUG
> 0.118974s
> 0.118443s
> -e
> c) column major + EIGEN_NO_DEBUG
> 0.135277s
> 0.135402s
> 
> Gaels-MacBook-Pro:bugs gaelguennebaud$ CXX=g++-mp-4.4 sh run.sh
> -e
> a) row major + EIGEN_NO_DEBUG
> 0.081015s
> 0.081603s
> -e
> c) column major + EIGEN_NO_DEBUG
> 0.100763s
> 0.100464s
> 
> Gaels-MacBook-Pro:bugs gaelguennebaud$ CXX=g++-mp-4.6 sh run.sh
> -e
> a) row major + EIGEN_NO_DEBUG
> 0.0641789s
> 0.0730638s
> -e
> c) column major + EIGEN_NO_DEBUG
> 0.0778357s
> 0.0827175s
> 
> The results of course depend a bit on the compiler, but I don't
> anything problematic here.
> 
> cheers,
> gael
> 
> On Wed, Jan 4, 2012 at 10:41 AM, Radu B. Rusu <rusu@xxxxxxxxxxxxxxxx> wrote:
>> int
>> main (int argc, char** argv)
>> {
>>  Vector4f vec1;
>>  MatrixXf mat;// (300, 4);
>>  mat = MatrixXf (300, 4);
>>  {
>>    int nr = mat.rows ();
>>    ScopeTime t1 ("w/out rows");
>>    for (long i = 0; i < 1000000; ++i)
>>    {
>>      for (int j = 0; j < nr; ++j)
>>        vec1 = mat.row (j);
>>    }
>>  }
>>  std::cout << vec1;
>>
>>  Vector4f vec2;
>>  {
>>    ScopeTime t2 ("w/ rows");
>>    for (long i = 0; i < 1000000; ++i)
>>    {
>>      for (int j = 0; j < mat.rows (); ++j)
>>        vec2 = mat.row (j);
>>    }
>>  }
>>
>>  std::cout << vec2;
>>  return (0);
>> }
> 
> 



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/