Re: [eigen] [Fwd: eigen cwise] unexpected performance regression with eigen's cwise()

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


First, here's a fixed version, the code was doing illegal accesses due
to mixing up i and j.

Here with gcc-4.4.1 on x86 linux, I can't see a significant speed difference.

=== 14:20:44 ~$ g++ -DEIGEN_CWISEOP temp.cpp -o temp -O3 -msse2
-DNDEBUG -I eigen2 && ./temp
Time: 2.64
=== 14:21:12 ~$ g++ -DCUSTOM_CWISEOP temp.cpp -o temp -O3 -msse2
-DNDEBUG -I eigen2 && ./temp
Time: 2.62

maybe tell your friend to try with gcc 4.4 ?

Benoit

2009/8/19 Rohit Garg <rpg.314@xxxxxxxxx>:
> A freind of mine who is using eigen for his code, hit this unexpected
> speed bump. I have no idea why.
>
> gcc 4.3.3
> Opteron 144, 1.8 ghz
> OS: ubuntu, 9.04, 32 bit
> eigen: unstable
>
>
> ---------- Forwarded message ----------
> From:  <sriramkashyap@xxxxxxxxx>
> Date: Wed, Aug 19, 2009 at 10:16 AM
> Subject: eigen cwise
> To: Rohit Garg <rpg.314@xxxxxxxxx>
>
>
> Results for 3 runs of the attached code (50000 cwise muls, done 50000 times):
>
> compile flags; -msse -msse2 -msse3 -DEIGEN_NO_DEBUG -O3
>
> My cwise: 7.56, 7.84, 7.7
> Eigen cwise: 8.3, 8.17, 8.39
>
>
>
> --
> Rohit Garg
>
> http://rpg-314.blogspot.com/
>
> Senior Undergraduate
> Department of Physics
> Indian Institute of Technology
> Bombay
>
#include<iostream>
#include<Eigen/Core>
#include<ctime>

using namespace Eigen;
using namespace std;
#define SIZE 50000
#define ITER 50000
Vector3f blah[SIZE];

void initBlah(){
	for (int i=0;i<SIZE;i++){
		blah[i]=Vector3f((i%100)/2.0f,(i%100)/3.0f,(i%100)/4.0f);
	}
}

Vector3f cwiseop(const Vector3f& a, const Vector3f& b){
	return Vector3f(a.x()*b.x(),a.y()*b.y(),a.z()*b.z());
}

void doMul(){
	for (int i=0;i<SIZE-2;i++)
		for (int j=0;j<ITER;j++)
#ifdef CUSTOM_CWISEOP
      blah[i]=cwiseop(blah[i+1],blah[i+2]);
#endif
#ifdef EIGEN_CWISEOP
				blah[i]=blah[i+1].cwise()*blah[i+2];
#endif        
}

int main(){
	initBlah();
	clock_t start = std::clock();
	doMul();
	clock_t end = std::clock();
	cout<<"Time: "<<((double)end-(double)start)/CLOCKS_PER_SEC<<endl;
	return 0;
}


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