Skip to content

Getting Started with LBL

LBL is a part of the NASOQ repository and is similarly a header-only library and does not need installation. Here we explain how LBL C++ API can be used to solve your sparse indefinite linear systems in your code.


An example of how to use LBL in your code is provided in thenasoq/examples directory, and here we explain the example step by step. We assume your project is somewhere like in nasoq\examples\.

First you need to clone the NASOQ repository in your project folder:

cd nasoq/examples/
git clone

After cloning NASOQ, you need to modify the CMakeLists of your project file to include NASOQ dependencies. Project LBL_Test in the CMakeLists of the nasoq/examples/ directory shows the components that you need to add to your CMake file. After modifying the CMake file of your project, you need to ensure the library dependencies of NASOQ are installed. NASOQ needs METIS and MKL BLAS Libraries as prerequisites.
If the installation paths of these libraries are in the system path, CMake should be able to handle dependencies. If not, you need to set CMake variables as shown below:

cd where/cloned/nasoq
mkdir build
cd build
cmake -DMKL_ROOT_PATH=path/to/intel -DMETIS_ROOT_PATH=path/to//metis-5.1.0/build/Linux-x86_64/  -DCMAKE_BUILD_TYPE=Release ..

After setting up dependencies, You can call LBL solver to solve your linear system by including <linear_solver_wrapper.h> and preparing its inputs, as shown in the following code.

#include "linear_solver_wrapper.h"

 * Solving Hx = q
 * H is a sparse matrix stored in CSC format
 * q is a dense array

int main(int argc, char *argv[]){

 /// Declaring input matrices
 // allocate
 q[0] = -4; q[1] = -4;


 auto *H = new nasoq::CSC; H->nzmax = nnzH; H->ncol= H->nrow =sizeH;
 H->p = Hp; H->i = Hi; H->x = Hx; H->stype=-1;

/// Solving the linear system
 auto *lbl = new nasoq::SolverSettings(H,q);
 lbl->ldl_variant = 4;
 lbl->req_ref_iter = 2;
 lbl->solver_mode = 0;
 lbl->reg_diag = pow(10,-9);
 double *x = lbl->solve_only();

 /// Printing results
 // expected x={-2,-2};
 std::cout<<"Solution: ";
 for (int i = 0; i < sizeH; ++i) {
 /// Free memory

For details about inputs, outputs, and settings of LBL, please see the LBL document page. Finally, you will build your project with NASOQ by emitting the make command.

You can also use LBL inside the NASOQ source tree. One example of using LBL is shown in the repository in the nasoq/eigen_interface directory. Choosing between in-source or out-source depends on your project settings.