ADVRHumanoids / XBotControl

XBotControl framework: XBotCore + OpenSoT + CartesI/O
33 stars 3 forks source link

Dynamic memory allocation problem in Eigen3 #28

Closed rsubburaman closed 4 years ago

rsubburaman commented 4 years ago

@liesrock @alaurenzi @ntsagarakis

I was running an RT plugin on CogIMon realtime pc, and it was repeatedly coming out of the real-time loop whenever it has to evaluate an expression that involved some matrix multiplications. This was happening even after predefining the size of all the matrices involved in that expression. The matrices size were no more than 15x15. After some browsing, I found that this is happening due to a temporary variable dynamically created by Eigen during such matrix multiplications. I also found the following link where a solution has been proposed to avoid this issue.

https://github.com/stulp/tutorials/blob/master/test.md

I tried the above solution, and it works. But the solution seems to make the code a little messy, especially if we have to evaluate a complex expression that involves several matrix multiplication operations. I was wondering if this issue has been addressed already and if the solution is better than the one proposed above.

liesrock commented 4 years ago

Hi Raj,

yes as I already explained in person the problem is the temporary: @alaurenzi can tell you more about this.

alaurenzi commented 4 years ago

Correct, matrix multiplications by default cause temporaries to be created. The reason is

Eigen3 is written to perform well in a general purpose scenario, and not to be real-time safe!

liesrock commented 4 years ago

I close this, since it is related to a 3rd party library in a specific use case.