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

vector data Access slow

Tags: None
(comma "," separated)
sip
Registered Member
Posts
5
Karma
0
OS

vector data Access slow

Fri Jan 22, 2010 10:02 am
hello

i have the same code , one using boost ublas and the same using Eigen 2
for the vector

for(int i=0;i<size_;i++)
{
T s = 0.0;

for(int k=lpos_(i);k<lpos_(i+1);k++)
{
int j = cpos_(k);
s += lo_(k) * b(j);
}

b(i) = (b(i) - s)/dia(i);
}

i have done some benchmark under windows 7 with visual c++ 2008

the code using ublast is 3 time faster as this with Eigen 2

is there some explanation ?

is it possible to optimize the eigen code using some tricks ?

thanks
User avatar
bjacob
Registered Member
Posts
658
Karma
3

Re: vector data Access slow

Fri Jan 22, 2010 1:17 pm
Are you working in Debug or Release mode? Eigen only claims to be fast in Release mode. In particular, in addition to enabling optimization, this should disable assertions. Otherwise, Eigen will use assertions to guard every coefficient access in a vector. You can access coefficients without assertions by using vector.coeff(i) / vector.coeffRef(i) instead of vector(i).


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
sip
Registered Member
Posts
5
Karma
0
OS

Re: vector data Access slow

Fri Jan 22, 2010 1:23 pm
thanks for your answers

I use eigen in release mode. but i will try the direct access function to the vector element . this slow access can have some relation with the inlining of this access function.
User avatar
bjacob
Registered Member
Posts
658
Karma
3

Re: vector data Access slow

Fri Jan 22, 2010 1:26 pm
The other explanation could be vectorization. Make sure to enable SSE2 in your project.

There is no reason whatsoever why we should be slower than ublas ;)
http://eigen.tuxfamily.org/index.php?ti ... August2008


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
User avatar
bjacob
Registered Member
Posts
658
Karma
3

Re: vector data Access slow

Fri Jan 22, 2010 1:28 pm
Also make sure that your own project must be compiled in Release mode, since eigen is just headers.


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
sip
Registered Member
Posts
5
Karma
0
OS

Re: vector data Access slow

Fri Jan 22, 2010 1:32 pm
yes the project is compiler in release mode and i have activated the sse2 optimisation.

the part of the code i have posted is slower with eigen but the dot product with eigen code is faster than ublas ex : alpha=r.dot(dc);

thanks
User avatar
bjacob
Registered Member
Posts
658
Karma
3

Re: vector data Access slow

Fri Jan 22, 2010 1:35 pm
One never knows: you might have encountered one of these cases where MSVC faisl to inline a crucial function.

If you could either:
- send us a list of the symbols (demangled) in your executable, or
- examine the assembly and find out yourself what functions are not inlined...

that could help us fix it.


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: vector data Access slow

Fri Jan 22, 2010 1:42 pm
also make sure you are using initialized variables with valid values, NaN, inf and the likes might kill the performance.
sip
Registered Member
Posts
5
Karma
0
OS

Re: vector data Access slow

Fri Jan 22, 2010 1:51 pm
replacing the cpos_ lpos with Eigen integer vector (before there were stl:vector)

and using the function .coeff(i) and .coeffref(i), the Eigen code work now at same speed as ublas , a little faster

thanks very much
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: vector data Access slow

Fri Jan 22, 2010 1:54 pm
that probably means that NDEBUG is not defined in your "release mode" that is weird because this should not be the default.


Bookmarks



Who is online

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