Skip to content

Getting Started with NASOQ

Here we explain how you can install NASOQ and use its C++ API to solve your QP problems.


First you should clone the NASOQ repository in your project folder:

cd nasoq/examples/
git clone
NASOQ needs the following dependencies:

  • CMake
  • C++ compiler (gcc, icc, or clang)
  • OpenMP (optional) : OpenMP is an optional dependency but without OpenMP, NASOQ runs sequentially.
  • METIS (Optional) : METIS dependency is already handled by CMake.
  • a BLAS Library (MKL or OpenBLAS)

If the installation paths of these libraries are in the system path, CMake should be able to handle dependencies. If not, you should 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 ..
A header-only version NASOQ is accessible from here.


To use NASOQ C++ API, you should first install NASOQ and then follow the example provided in nasoq/examples. Here we explain the example step by step. After installing NASOQ, you should modify the CMakeLists of your project file to add nasoq and its dependent libraries, i.e., METIS and a BLAS library.
After setting up dependencies, You can call NASOQ solver to solve your QP problems by including <nasoq.h>, and by preparing its inputs, as shown in the following code.

#include <nasoq.h>

int main(){
 /// Allocate
 /// Inputs
 q[0] = -4; q[1] = -4;
 // H should be the lower part of a symmetric matrix
 // A and C matrices are general matrices


 /// Solving the QP pronlem
 nasoq::Nasoq *qm;
 qm = new nasoq::Nasoq(sizeH,Hp,Hi,Hx,
                       q,CRows,CCols,Cp, Ci, Cx, d);
 qm->max_iter = 0;
 qm->variant = nasoq::PREDET;
 int converged = qm->solve();

 /// Printing results
  std::cout<<"The problem is converged\n";

 // expected x={0.4,1.2};
 auto *x = qm->primal_vars;
 std::cout<<"Primal variables: ";
 for (int i = 0; i < sizeH; ++i) {

 // expected z = {1.6,0,0,0}
 std::cout<<"\nDual variables: ";
 auto *z = qm->dual_vars;
 for (int i = 0; i < CRows; ++i) {

 /// Free memory
For details about inputs, outputs, and settings of NASOQ, please see the NASOQ document page.

You can also use NASOQ inside the NASOQ source tree. One example of using nasoq is shown in the nasoq/eigen_interface directory.

Command-line interface

In addition to C++ API, a terminal interface is also provided in the NASOQ repository. To use this interface, you should follow NASOQ instructions to build the interface, i.e., NASOQ-BIN. After the build is done, the terminal interface can be launched by calling NASOQ-BIN with an input QP problem and the list of switches, which can be seen by commanding NASOQ-BIN -h. Some important options are shown below:

-i : input SMP file
-e : Requested accuracy ,e.g., -3
-v : NASOQ variant, e.g., fixed or tuned
For details of options please check NASOQ document page. And for details about SMP format, please check SMP repository page.