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

Eigen and c++ cli

Tags: cli, eigen cli, eigen cli, eigen
(comma "," separated)
kgoedde
Registered Member
Posts
6
Karma
0

Eigen and c++ cli

Thu Feb 27, 2014 1:10 pm
Hello,

we try to do some real time simulation. Our main application runs under c# and our simulation library under c++ cli. So we updated our linear solver to the eigen framework (from openblas), because we have to deal with al lot sparse matrices.

In tests in c++ the eigen dense solver is as fast as the open blas one, but in our simulation library it is up to a hundred times slower. we integrated eigen directly in our library whereas openblas is in its own dll. We think the differences are due to the cli stuff. Is there a way around the slow down or a workaround / alternative?

Thanks in advance,

Kai Gödde
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Eigen and c++ cli

Thu Feb 27, 2014 1:49 pm
I've no idea as I never used C# nor CLI. Perhaps it's just a matter of compilation options?
kgoedde
Registered Member
Posts
6
Karma
0

Re: Eigen and c++ cli

Thu Feb 27, 2014 2:41 pm
So now we put the eigen stuff in its own static library and kill openBlas, but only in 32 bit. The 64 bit mode is still painfully slow. Are there any compiler options or other things we might do to speed up the 64 bit mode (which runs actually slowerr than the 32 bit mode)?

Thanks in advance,

Kai Gödde
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Eigen and c++ cli

Thu Feb 27, 2014 5:03 pm
That's weird. What if in 32bit mode you enable SSE in the compiler? Perhaps the intrinsics are not inlined or something... Eigen is typically slow when optimizations are not enabled ("debug" mode). So make sure you are in "release" mode.
mikity
Registered Member
Posts
4
Karma
0

Re: Eigen and c++ cli

Sat Oct 16, 2021 7:13 am
Hi, I was trying to call Eigen subroutines from a C++/CLI code and experienced the same issue.
Since there is no enough information on the internet regarding this topic, I decided to leave what I found out so far here.

Using C++/CLI environment, pure C++ code and C++/CLI code can coexist. Theoretically, this is a good environment to create an Eigen wrapper to be called from C# codes.
But, Eigen functions run too solowly.
I have turned on optimization switches and turned off debug mode for sure.

As far as I tested, this could be solved by separating the pure c++ code part from the C++/CLI project and put it in an independent pure c++ project to host the pure c++ code part that calls Eigen functions. The static library can be easily linked to the C++/CLI DLL, so the final output is still a single DLL.

For example, a SparseLU solver with 1000x1000 matrix took 3secs to solve an equation when the pure c++ code was hosted in the C++/CLI project, and the same code runs in 130ms when the pure C++ part is segregated.


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Google [Bot], Yahoo [Bot]