Registered Member
|
I wanted to know if I could stop Eigen from new memory automatically and if I would get a speedup by doing so. I've attached a code snippet which is somewhat characteristic of what my program does.
#define EIGEN_RUNTIME_NO_MALLOC #include <Eigen/Dense> using namespace std; using namespace Eigen; #define UNCONST(t,c,uc) Eigen::MatrixBase<t> &uc = const_cast<Eigen::MatrixBase<t>&>(c); template <typename Derived> void multiply (const MatrixBase<Derived> &A, MatrixBase<Derived> const &const_C){ Matrix<double, Dynamic, Dynamic>B; B.setOnes(500,500); UNCONST(Derived,const_C,C); Eigen::internal::set_is_malloc_allowed(false); C = A*B; Eigen::internal::set_is_malloc_allowed(true); } int main(int argc, char** argv) { Matrix<double,Dynamic,Dynamic>A,C; A.setOnes(500,500); C.setOnes(500,500); multiply(A,C); } I compile this code in debug mode and when I execute it, I get the following error: Assertion failed: (is_malloc_allowed() && "heap allocation is forbidden (EIGEN_RUNTIME_NO_MALLOC is defined and g_is_malloc_allowed is false)"), function check_that_malloc_is_allowed, file ../3rdparty/Eigen/src/Core/util/Memory.h, line 189. Is there a way I can switch off this memory allocation ? I'm careful of making sure that matrices on the left hand side of an assignment have the correct dimensions. Would there be speedups in the code if I stopped these malloc calls ? I deal with large matrices and I use functions like multiply() repeatedly. Thanks a lot for your time! Best, Ashish |
Moderator
|
|
Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot]