polympc icon indicating copy to clipboard operation
polympc copied to clipboard

[QP Solver] In-place LDLT decomposition of KKT matrix

Open msplr opened this issue 6 years ago • 2 comments

The most significant memory cost of the dense QP solver come form storing the KKT matrix and its decomposition. Eigen allows for in-place LDLT decomposition that reuses the coefficient matrix and to save memory. The in-place decomposition requires a reference to the coefficient matrix at construction, which is not available at that point. However, construction can be delayed using a placement new, which is illustrated below.

using linear_solver_t = Eigen::LDLT<Eigen::Ref<kkt_mat_t>>;
char linear_solver_buf[sizeof(linear_solver_t)]; // enforce some alignment somehow?
linear_solver_t* linear_solver;
//...
p = (void*) linear_solver_buf;
linear_solver = new(p) linear_solver_t(kkt_mat);

Note: Another option would be to construct the linear solver as a local object on the stack.

msplr avatar Jul 07 '19 07:07 msplr

std::shared_pointer<linear_solver_t> linear_solver; linear_solver = make_shared<linear_solver_t>(kit_mat)

?

petlist avatar Jul 08 '19 15:07 petlist

I need to learn how to properly insert the code. =)

petlist avatar Jul 08 '19 15:07 petlist