This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Returning the transpose: speed question

Tags: None
(comma "," separated)
n2k
Registered Member
Posts
41
Karma
0
Hi,

I have a code where I need to return the symmetric part of a Matrix3d. Say that this matrix is called Sum. I noticed that returning (Sum+Sum.transpose())/2.0 is much slower that returning just Sum+Sum.transpose().

For example the following code takes 1.24 sec without the 2.0 factor and 1.77 sec with the 2.0 factor (gcc 4.2 -O3 -sse3, Eigen 2.0.12).

Can anybody please explain to me why this is happening?
Thank you for your help.

Code: Select all
#include <iostream>
#include <Eigen/Core>
#include <Eigen/Array>


Eigen::Matrix3d term(){
   Eigen::Vector3d A, B;
   A.setRandom();
   B.setRandom();
   
   return A*B.transpose();
}

Eigen::Matrix3d loop(){
   Eigen::Matrix3d Sum;
   Sum.setZero();
   
   for (int k=0;k<10000000;++k){
      Sum+=term();
   }

   return (Sum+Sum.transpose())/2.0;
//   return Sum+Sum.transpose();
}


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

   double t0=clock();
   std::cout<<loop()<<std::endl;
   std::cout << "Simulation Time =" << (clock()-t0)/CLOCKS_PER_SEC << " sec"<< std::endl;
   
   return 0;
}
n2k
Registered Member
Posts
41
Karma
0
.. never mind. This just happens on one of my two computers. I found out that if I generate my project with a MacOs 10.5 machine I find the problem. If I use a MacOs 10.6 machine I have no problem. I'm trying to find out the differences...


Bookmarks



Who is online

Registered users: abc72656, Bing [Bot], daret, Google [Bot], Sogou [Bot], Yahoo [Bot]