Use Ipopt

#unix #Ipopt #Linux

This note shows a successful use of Ipopt on Linux.



If the libA is installed?

How to check if a library is installed or not even if I don’t know the exact name? On Ubuntu, one can use

    # fix library full name
    dpkg --list | grep -i blas
    # ii  libblas-dev:amd64                             3.7.1-4ubuntu1                                  amd64        Basic Linear Algebra Subroutines 3, static library
    # ii  libblas3:amd64                                3.7.1-4ubuntu1                                  amd64        Basic Linear Algebra Reference implementations, shared library
    # ii  libopenblas-base:amd64                        0.2.20+ds-4                                     amd64        Optimized BLAS (linear algebra) library (shared library)

    # show library full info
    dpkg -s libopenblas-base

    # locate the library
    dpkg -L libopenblas-base

for example, to check if the BLAS library is installed.

Manage multiple blas with update-alternatives

For example, there are two versions of shared blas libraries in my Ubuntu, as shown above, libblas-dev and libopenblas-base. update-alternatives can be used to maintain these different realizations of blas.

    # To check if libblas.so already exists
    update-alternatives --list libblas.so

    # Install a new alternative for libblas.so
    # update-alternatives --install <link> <name> <path> <priority>
    sudo update-alternatives --install /usr/lib/libblas.so libblas.so /usr/lib/x86_64-linux-gnu/blas/libblas.so 1000
    sudo update-alternatives --install /usr/lib/libblas.so libblas.so /usr/lib/x86_64-linux-gnu/openblas/libblas.so.3 1010

    # show current installed alternatives
    update-alternatives --display libblas.so
    # show in etc
    ls /etc/alternatives | grep libblas

    # change the current link point to lib
    sudo update-alternatives --config libblas.so
    # or switch to the highest priority installed alternatives
    sudo update-alternatives --auto libblas.so

    # remove an alternative 
    sudo update-alternatives --remove libblas.so /usr/lib/x86_64-linux-gnu/blas/libblas.so

    # use libblas.so
    g++ pardiso_sym.cpp -o pardiso_sym -L/usr/local/lib -lpardiso600-GNU720-X86-64 -L/usr/lib -lblas -llapack -lgfortran -fopenmp -lpthread -lm

Install ThirdParty Libraries

OpenBLAS

    # https://www.openblas.net/
    make FC=gfortran
    sudo make install PREFIX=/opt/OpenBLAS

    # link the library
    gcc test_cblas_dgemm.c -o test_cblas_dgemm -I/opt/OpenBLAS/include -L/opt/OpenBLAS/lib -lopenblas -lpthread -lgfortran
    # -pthread: add support for multithreading using the POSIX threads library
    # -lpthread: as -pthread but  doesn't set the preprocessor flags
    # https://stackoverflow.com/questions/39782602/what-does-gcc-option-pthread-mean#:~:text=From%20man%20gcc,of%20libraries%20supplied%20with%20it.
    # -lgfortran: to get the Fortran runtime libraries for g++

PARDISO

    # https://www.pardiso-project.org/
    cp libpardiso600-GNU720-X86-64.so /opt/PARDISO
    cp pardiso.lic /opt/PARDISO
    ln -s libpardiso600-gnu720-x86-64.so libpardiso.so

    # link the library
    g++ pardiso_sym_schur.cpp -o pardiso_sym_schur -L/opt/PARDISO -lpardiso -L/opt/OpenBLAS/lib -lopenblas -lgfortran -fopenmp -lpthread -lm
    # -lm: link to libm.so, the math library

HSL

Ipopt

    ../configure --prefix=/opt/coinIpopt --with-lapack="-I/opt/OpenBLAS/include -L/opt/OpenBLAS/lib -lopenblas -lpthread -lgfortran" --with-pardiso="-L/opt/PARDISO -lpardiso -lgfortran -fopenmp -lpthread -lm"
    make
    make test
    make install

    # to be updated