Skip to content
ReidDye edited this page Jan 30, 2024 · 31 revisions

The IPOPT solver comes with a feature to detect the presence of 'libhsl.so'/'libhsl.dll' at runtime. Here is a report on how to obtain this 'libhsl.so'/'libhsl.dll'.

Step 1: Installation

Option 1: Compile the solvers from source

The following instructions work on Linux/Mac and Msys environment on Windows.

  1. Make sure that BLAS, LAPACK and a Fortran compiler are installed on your system (on Ubuntu/Debian systems, you can install these by running sudo apt-get install libblas3gf libblas-dev liblapack3gf liblapack-dev gfortran and for Ubuntu >= 16.04 sudo apt-get install libblas3 libblas-dev liblapack3 liblapack-dev gfortran).
  2. Obtain the proprietary source coinhsl package from http://www.hsl.rl.ac.uk/ipopt/. When filling out the forms, please mention that you plan to use the routines with Ipopt/CasADi. Note that, unfortunately, we cannot guarantee the stability of using the newer linear solvers (MA57, MA77, MA86 and MA97 that are only free for academics) since HSL has not granted us any maintenance license.

⚠️ Make sure that you download the coinhsl-2022-11-09 package, not the 2023 one. These instructions only work with the 2022 version (and presumably earlier ones). The 2023 package does not contain the configure script we use here.

  1. wget http://glaros.dtc.umn.edu/gkhome/fetch/sw/metis/OLD/metis-4.0.3.tar.gz

  2. tar -xvf metis-4.0.3.tar.gz

  3. Unpack the coinhsl package and navigate into the resutling coinhsl sources folder.

  4. mv ../metis-4.0.3 . (For OSX in loadmetis/loadmetis.c change #define SHLIBEXT "so" to #define SHLIBEXT "dylib")

  5. $> ./configure --prefix=(where_you_want_to_install) LIBS="-llapack" --with-blas="-L/usr/lib -lblas" CXXFLAGS="-g -O2 -fopenmp" FCFLAGS="-g -O2 -fopenmp" CFLAGS="-g -O2 -fopenmp" (For Windows, make sure to use forward slashes in paths. Also for Windows, you probably need to compile and include -lcoinblas and -lcoinlapack as well.)

  6. $> make

  7. $> make install

  8. Create a symbolic link from libcoinhsl.so to libhsl.so (libcoinhsl.dylib -> libhsl.dylib on OSX):

    $> ln -s (hsl_install_directory)/libcoinhsl.so (hsl_install_directory)/libhsl.so

MacOS procedure

Tested on MacOS 12.3.1 - Intel core i5

Preliminary: make sure have brew, a packet manager for MacOS.

  1. Run
brew install gcc
brew install gfortran
brew install metis

The libraries blas and lapack are already shipped in MacOS in the Accelerate Framework.

  1. Obtain the proprietary source coinhsl package from http://www.hsl.rl.ac.uk/ipopt/. When filling out the forms, please mention that you plan to use the routines with Ipopt/CasADi. Note that, unfortunately, we cannot guarantee the stability of using the newer linear solvers (MA57, MA77, MA86 and MA97 that are only free for academics) since HSL has not granted us any maintenance license.
  2. From coin-or-ipopt-guide follow the instructions HSL (Harwell Subroutines Library). Therefore run
git clone https://github.com/coin-or-tools/ThirdParty-HSL.git
cd ThirdParty-HSL
  1. Unpack the HSL sources archive, move and rename the resulting directory so that it becomes ThirdParty-HSL/coinhsl.
  2. Add the following lines to your Bash profile (e.g. .zshrc) in order to compile with gcc (MacOS deafult is clang).
export CC=/usr/local/bin/gcc-12
export CXX=/usr/local/bin/g++-12
alias gcc=/usr/local/bin/gcc-12
alias cc=/usr/local/bin/gcc-12
  1. Open a new terminal in order to make effective the changes of your Bash profile. Then, run
./configure --prefix=(where_you_want_to_install)  --with-metis-cflags=-I/usr/local/Cellar/metis/5.1.0/include --with-metis-lflags="-L/usr/local/Cellar/metis/5.1.0/lib -lmetis" CXXFLAGS="-g -O2 -fopenmp" FCFLAGS="-g -O2 -fopenmp" CFLAGS="-g -O2 -fopenmp" LDFLAGS="-fopenmp"
make
make install
  1. Create a symbolic link from libcoinhsl.dylib to libhsl.dylib:
ln -s (hsl_install_directory)/lib/libcoinhsl.dylib (hsl_install_directory)/lib/libhsl.dylib
  1. Restore your Bash profile by deleting the rows added at point 4.

Option 2: Obtain pre-compiled binaries

Obtain pre-compiled libraries as a tar/zip file from http://www.hsl.rl.ac.uk/ipopt/ Note that the Win32 bit version works fine on a 64 bit machine, too.

Note: Some users reported that they had problems using the pre-compiled binaries. So in case you first try the pre-compiled binaries and fail with them, you probably have to wait an additional day until you can use the solvers since you have to request a different download link for the source files.

Step 2: Make IPOPT see the solvers

Once you have the solvers, you should just append the directory where it resides to the LD_LIBRARY_PATH environment variable (or DYLD_LIBRARY_PATH on OSX, or PATH on Windows).

The most common way to set LD_LIBRARY_PATH=(hsl_install_directory), or DYLD_LIBRARY_PATH for OSX users, is to add something like this to your .bashrc or .bash_profile

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:(hsl_install_directory/lib)

Note: if you use CasADi from Matlab, do check if your env variable is correctly passed on getenv('LD_LIBRARY_PATH'). If it's not, try firing up Matlab from a terminal where that variable is set correctly.

On Ubuntu/Debian systems, if you configured the compilation of the solvers with --prefix=/usr, this step 2 is not necessary.

Threaded execution

Since you went to the trouble of compiling with -fopenmp, you should export OMP_NUM_THREADS=7 or something so that HSL knows to go faster.

Clone this wiki locally