This bugzilla service is closed. All entries have been migrated to https://gitlab.com/libeigen/eigen

Bug 789

Summary: Feature Request: Memory allocation only when necessary
Product: Eigen Reporter: Piotr Trebisz <trebisz>
Component: GeneralAssignee: Nobody <eigen.nobody>
Status: DECISIONNEEDED ---    
Severity: Feature Request CC: chtz, gael.guennebaud, jacob.benoit.1
Priority: Normal Keywords: JuniorJob
Version: unspecified   
Hardware: All   
OS: All   
Whiteboard:
Bug Depends on: 707    
Bug Blocks:    

Description Piotr Trebisz 2014-04-10 15:58:53 UTC
Hello,
I'm Piotr Trebisz from the GFaI e.V. institute in Berlin. I work as a software developer in the 3D-Data-Processing departement of the institute. We decided to use "Eigen" because we are tired of spending time on writing our own numerical methods and Eigen seems to yield good results in terms of accuracy.
But we also identified a little performance issue: Eigen frees and allocates memory on every matrix resize, on every computation of a matrix decomposition and on every other change of an objects size, and that costs some time. If you only want to solve 1 or just a few equation systems, then it's not a problem. But our programms often have to solve some 100.000 to some 1.000.000 equation systems whose dimensions vary from iteration step to iteration step.
Freeing and allocating bigger matrices, vectors and matrix-decomposition-objects 100.000 to 1.000.000 times has a negative impact on performance. Therefore in our departement and in many other scientific institutions it is regarded as best practice in numerical algorithms to allocate new memory only when the old memory is not big enough. When an object shrinks, the memory is keept and not freed. Our objects have an extra method called "FreeExtra" if one explicitly wants to free unused memory.
With Eigen's map-templates it is possible to manage the memory of matrices and vectors by our own. But it is not possible to do so with all the other objects like JacobiSVD- and HouseholderQR-Decompositions. Therefore we would like to know if you could think about our suggestion and consider such a memory management for future Eigen releases.

Best Regards
Piotr Trebisz
Comment 1 Christoph Hertzberg 2014-09-07 17:35:46 UTC
In-Place decompositions could partially solve this. 
But we need some general decision if we want to allow independent memory allocation from the matrix size, which would also be helpful for matrices growing during run-time.
API-wise this could be done by using special values for the RowsAtCompileTime/ColsAtCompileTime template arguments and provide a reserve() function similar to std::vector
Comment 2 Gael Guennebaud 2014-09-08 10:39:06 UTC
Instead of special Rows/Cols template argument, I'd rather add a new option bit flag enabling the proposed behavior in Matrix<>. This option would then be passed to all members of a given decomposition. I'd accept such a patch.
Comment 3 Gael Guennebaud 2015-07-20 09:52:22 UTC
See https://bitbucket.org/eigen/eigen/pull-request/125/789-memory-allocation-only-when-necessary/diff for a start and current discussions.
Comment 4 Nobody 2019-12-04 13:12:37 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to gitlab.com's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.com/libeigen/eigen/issues/789.