Skip to content

Instantly share code, notes, and snippets.

@tasseff
Last active May 1, 2022 17:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tasseff/ee61ef6c15d3c54e0a6b3e488f2a65be to your computer and use it in GitHub Desktop.
Save tasseff/ee61ef6c15d3c54e0a6b3e488f2a65be to your computer and use it in GitHub Desktop.
Compilation of Ipopt with SPRAL

This is a guide detailing the compilation of Ipopt with SPRAL as a linear solver. It was developed assuming a standard installation of Ubuntu 18.04 LTS. To begin, first, compile the LANL ANSI version of SPRAL using the compilation suggestions described therein.

Cloning the Repository

First, create a directory where Ipopt will be compiled from source (not via coinbrew), e.g.,

mkdir -p ${HOME}/Software

The remainder of this guide assumes such a directory has been created. Then, clone the Ipopt repository via

cd ${HOME}/Software
git clone https://github.com/lanl-ansi/Ipopt.git --branch devel

Rebuilding Configuration Files (optional)

To rebuild configuration files for Ipopt, if needed (e.g., during development), execute

cd ${HOME}/Software/Ipopt
git clone https://github.com/coin-or-tools/BuildTools.git
export COIN_AUTOTOOLS_DIR="${HOME}/local2"
./BuildTools/install_autotools.sh
./BuildTools/run_autotools

If you are not modifying the directory or source structure of Ipopt, this step is not required.

Compilation with SPRAL

Multicore CPUs Only

To compile Ipopt with SPRAL (CPU support only), specify ${SPRALDIR} as the directory containing lib/libspral.a, then execute

cd ${HOME}/Software/Ipopt
mkdir build
cd build
../configure --prefix=${PWD} --with-spral-lflags="-L${SPRALDIR}/lib -L${METISDIR}/lib \
    -lspral -lgfortran -lhwloc -lm -lcoinmetis -lopenblas -lstdc++ -fopenmp" \
    --with-spral-cflags="-I${SPRALDIR}/include" --with-lapack-lflags="-llapack -lopenblas"
make && make install

Multicore CPUs and NVIDIA GPUs

To compile with GPU support, execute

cd ${HOME}/Software/Ipopt
mkdir build
cd build
../configure --prefix=${PWD} --with-spral-lflags="-L${SPRALDIR}/lib -L${METISDIR}/lib \
    -lspral -lgfortran -lhwloc -lm -lcoinmetis -lopenblas -lstdc++ -fopenmp \
    -lcudadevrt -lcudart -lcuda -lcublas" --with-spral-cflags="-I${SPRALDIR}/include" \
    --with-lapack-lflags="-llapack -lopenblas"
make && make install

Usage

Ensure the following environment variables are set when using the SPRAL library:

export OMP_CANCELLATION=TRUE
export OMP_NESTED=TRUE
export OMP_PROC_BIND=TRUE

Testing

Within the build directory created above, the examples/ScalableProblems directory contains a set of scalable test problems. After compilation of Ipopt, these examples can be compiled via

cd ${HOME}/Software/Ipopt/build
cd examples/ScalableProblems && make

As an example, if Ipopt was compiled with SPRAL support, try creating a file named ipopt.opt in this directory with the contents

linear_solver spral
spral_use_gpu no

Then, solve a test problem, e.g.,

time ./solve_problem MBndryCntrl1 768

If SPRAL was compiled with GPU support, next try modifying the ipopt.opt file to contain

linear_solver spral
spral_use_gpu yes

Then, solve the same test problem, e.g.,

time ./solve_problem MBndryCntrl1 768

The real time required by the solver should typically decrease on very large, dense problems, compared with a solve using spral_use_gpu no. If this is not the case, ensure your GPU is actually being recognized by SPRAL. This issue is briefly discussed near the end of the associated SPRAL compilation guide.

@rviertel
Copy link

Thank you for these instructions! I ran into a segfault while trying to run a problem using ipopt with spral as a solver. The example problem listed here worked fine, but my problem gets a segfault in __spral_match_order_MOD_mo_split () from /ascldap/users/rv
ierte/ipopt-spral/Ipopt/build/lib/libipopt.so.3

What is the best place to report these types of issues? Neither the ipopt or spral forks on lanl-ansi have an issues tab.

@tasseff
Copy link
Author

tasseff commented Mar 22, 2022

Thanks for the note! It's been a while since these instructions have been updated, so I apologize for that. The forks are also dated, although they should still be usable.

In fact, the SPRAL interface to Ipopt is now supported in the official Ipopt repository. I also know there have been updates to the official SPRAL repository. Nonetheless, I have not seen this segmentation fault in my testing of the forked versions. It's possible that your issue would be resolved using the newer versions of Ipopt and SPRAL.

If it still doesn't work after compiling with newer versions, you could try to report an issue to either the upstream Ipopt or SPRAL repository, but it'd be good to isolate the issue, first. I'd be happy to take a look using the forked versions if you have a minimum working example (maybe an NL file?) that produces the segfault.

@fnekovar
Copy link

fnekovar commented May 1, 2022

Hello. Thank you for the instructions. I have managed to compile latest SPRAL (the fork does not compile) and Ipopt as described above, however, am running into an issue trying to run a test problem with output:

free(): invalid size
Aborted (core dumped)

Also, although SPRAL is successfully recognized on compilation, it doesn't seem to be accessible from code:

Setting: "spral" is not a valid setting for Option: linear_solver. Check the option documentation.

Hopefully last, what is the correct version of Metis being used here? Ipopt documentation specifies 'libmetis-dev' package, while SPRAL specifies 4.0.3 COIN-OR version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment