Skip to content

Commit

Permalink
Merge pull request #267 from Robbybp/without-hsl
Browse files Browse the repository at this point in the history
Better support building without HSL
  • Loading branch information
Robbybp committed Jan 28, 2024
2 parents 9aaab31 + 6d1356a commit 449d332
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 46 deletions.
17 changes: 8 additions & 9 deletions doc/build-local.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@ The build scripts were not designed for local use, so there are a few gotchas:

- We look for patch files in a specific location relative to the original
working directory. I.e. you must run `compile_solvers.sh` from *one level above*
the scripts directory in order for patches (e.g. `ipopt.pc.patch`) to be
the scripts directory in order for patches (e.g. `CouenneMatrix.hpp.patch`) to be
correctly applied.
- `ipopt.pc.patch` assumes that `coinmumps` and `coinhsl` are listed as
dependencies in the `ipopt.pc` file. If either is not found (i.e. we are
compiling without HSL), the patch application will fail.
- By default, Petsc is assumed to be installed in hard-coded, OS-dependent
location. If you are compiling locally, you have probably installed it
in your own preferred location. To override the default, set the `PETSC_DIR`
environment variable to the location where you have installed Petsc.
- If you have your own system-installed HSL libraries that are discoverable
by the linker (i.e. `LD_LIBRARY_PATH` is set), the COIN-OR solvers will likely
be able to find and link against them. In this case, you will see a
`HSL Present: NO` message (as there was no `coinhsl.zip` in the parent of the
working directory), but will likely still build HSL-enabled solvers.
- By default, we look for a `coinhsl.zip` file in the parent of the original
working directory. If this file is not found, we attempt to compile Ipopt with an
installed coinhsl library in a linker-accesible location. If no coinhsl library
can be found (or compiled from source in `coinhsl.zip`), the `compile_solvers.sh`
script will fail attempting to build `k_aug`, which cannot be built without HSL.
To avoid this failure, send the `--without-hsl` argument to `compile_solvers.sh`
after the OS name.
18 changes: 16 additions & 2 deletions doc/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,14 @@ There is a GitHub actions test.

## Testing a non-default branch

By default, the Docker driver scripts (`docker/build.sh` and `docker\build.ps1`)
By default, the Docker driver scripts
(`docker/build-extensions/build.sh` and `docker\build-extentions\build.ps1`)
checkout the `main` branch of `https://github.com/idaes/idaes-ext.git` to use
for the build process. To test a different branch, arguments can be provided
to the Docker driver scripts. For example, to test the `ubuntu2204` build with
a custom branch called `mybranch` on `user`'s fork, run
```bash
./build.sh ubuntu2204 https://github.com/user/idaes-ext.git mybranch
./build.sh ubuntu2204 x86_64 https://github.com/user/idaes-ext.git mybranch
```
To test the Windows build, run
```powershell
Expand All @@ -141,3 +142,16 @@ Collect all the tar files for a release in the same directory.
With IDAES installed, run ``idaes hash-extensions --path <path to tar files> --release <release>``
A text file with the hash of all the files will be written to the directory with the
release files.

## Building without HSL

For testing purposes, it may be useful to build for multiple operating systems
(via Docker) without HSL. This may be accomplished by passing the `--without-hsl`
argument to `docker/build-extensions/build.sh`, after the OS name, architecture name,
repository URL, and repository branch.
This fifth positional argument to `build.sh` is interpreted as an argument (or arguments)
to send to `compile_solvers.sh`.
For example:
```bash
./build.sh ubuntu2204 x86_64 https://github.com/IDAES/idaes-ext.git main --without-hsl
```
5 changes: 4 additions & 1 deletion docker/build-extensions/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ if [ ! "$branch" ]; then
branch="main"
fi

solver_buildargs=$5

echo "build.sh script arguments:
OS: $flavor
Arch: $mname
Repo: $repo
Branch: $branch
Args to compile_solvers.sh: $solver_buildargs
"

if [ "$flavor" = "windows" ]; then
Expand Down Expand Up @@ -46,7 +49,7 @@ docker cp ./extras/ "$flavor"_"$mname"_build_tmp:"$wdir"
docker exec "$flavor"_"$mname"_build_tmp sh -c "cp ${wdir}/extras/* ${wdir}"
docker exec "$flavor"_"$mname"_build_tmp sh -c "cd ${wdir}/extras && pwd"
docker exec "$flavor"_"$mname"_build_tmp sh -c "cd ${wdir} && git clone ${repo} && cd idaes-ext && git checkout ${branch}"
docker exec "$flavor"_"$mname"_build_tmp sh -c "cd ${wdir}/idaes-ext && bash scripts/compile_solvers.sh ${flavor}"
docker exec "$flavor"_"$mname"_build_tmp sh -c "cd ${wdir}/idaes-ext && bash scripts/compile_solvers.sh ${flavor} ${solver_buildargs}"
docker exec "$flavor"_"$mname"_build_tmp sh -c "cd ${wdir}/idaes-ext && bash scripts/compile_libs.sh ${flavor}"
docker stop "$flavor"_"$mname"_build_tmp

Expand Down
95 changes: 61 additions & 34 deletions scripts/compile_solvers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,26 @@ export MNAME=`uname -m`
# to be the root of the idaes-ext repository.
export IDAES_EXT=`pwd`

if [ -f $IDAES_EXT/../coinhsl.zip ]
then
arg2=$2
if [ $arg2 = "--without-hsl" ]; then
echo "--without-hsl flag received. Building solvers without HSL." >&2
echo "HSL: NO"
hslflag="--without-hsl"
with_hsl="NO"
build_hsl="NO"
elif [ -f $IDAES_EXT/../coinhsl.zip ]; then
echo "coinhsl.zip found. Building solvers with HSL." >&2
echo "HSL: YES"
hslflag="--with-hsl"
with_hsl="YES"
build_hsl="YES"
else
echo "HSL: NO"
echo "coinhsl.zip not found. Attempting to build with installed HSL." >&2
echo "To skip HSL-reliant build steps, send the --without-hsl argument to this script" >&2
echo "HSL: YES"
hslflag="--with-hsl"
with_hsl="YES"
build_hsl="NO"
fi

# Set a few basic things
Expand Down Expand Up @@ -156,12 +171,6 @@ if [ -f $IDAES_EXT/../coinhsl.zip ]; then
cd ThirdParty/HSL/coinhsl
unzip coinhsl.zip
cd $IDAES_EXT/coinbrew
echo "HSL is available, building with HSL"
with_hsl="YES"
else
# If the HSL isn't there, build without it.
echo "HSL Not Available, BUILDING SOLVERS WITHOUT HSL" >&2
with_hsl="NO"
fi

echo "#########################################################################"
Expand All @@ -186,12 +195,14 @@ cd $IDAES_EXT/coinbrew
echo "#########################################################################"
echo "# Thirdparty/HSL #"
echo "#########################################################################"
cd ThirdParty/HSL
./configure --disable-shared --enable-static --with-metis \
--prefix=$IDAES_EXT/coinbrew/dist FFLAGS="-fPIC" CFLAGS="-fPIC" CXXFLAGS="-fPIC"
make $PARALLEL
make install
cd $IDAES_EXT/coinbrew
if [ $build_hsl = "YES" ]; then
cd ThirdParty/HSL
./configure --disable-shared --enable-static --with-metis \
--prefix=$IDAES_EXT/coinbrew/dist FFLAGS="-fPIC" CFLAGS="-fPIC" CXXFLAGS="-fPIC"
make $PARALLEL
make install
cd $IDAES_EXT/coinbrew
fi

echo "#########################################################################"
echo "# Thirdparty/Mumps #"
Expand All @@ -207,7 +218,7 @@ echo "#########################################################################"
echo "# Ipopt ampl executables #"
echo "#########################################################################"
cd Ipopt
./configure --disable-shared --enable-static --with-mumps --with-hsl \
./configure --disable-shared --enable-static --with-mumps $hslflag \
--prefix=$IDAES_EXT/coinbrew/dist
make $PARALLEL
make install
Expand All @@ -218,11 +229,11 @@ echo "# Ipopt_L1 ampl executables #"
echo "#########################################################################"
cd Ipopt_l1
if [ ${osname} = "el7" ]; then
./configure --disable-shared --enable-static --with-mumps --with-hsl \
./configure --disable-shared --enable-static --with-mumps $hslflag \
ADD_CXXFLAGS="-std=c++11" \
--prefix=$IDAES_EXT/coinbrew/dist_l1
else
./configure --disable-shared --enable-static --with-mumps --with-hsl \
./configure --disable-shared --enable-static --with-mumps $hslflag \
--prefix=$IDAES_EXT/coinbrew/dist_l1
fi
make $PARALLEL
Expand Down Expand Up @@ -348,7 +359,7 @@ echo "# Ipopt Shared Libraries #"
echo "#########################################################################"
cd Ipopt_share
./configure --enable-shared --disable-static --without-asl --disable-java \
--with-mumps --with-hsl --enable-relocatable --prefix=$IDAES_EXT/coinbrew/dist-share
--with-mumps $hslflag --enable-relocatable --prefix=$IDAES_EXT/coinbrew/dist-share
make $PARALLEL
make install
cd $IDAES_EXT/coinbrew
Expand Down Expand Up @@ -395,15 +406,27 @@ cp ./coinbrew/dist/bin/bonmin ./dist/bin/
cp ./coinbrew/dist/bin/couenne ./dist/bin/
# Run strip to remove unneeded symbols (it's okay that some files
# aren't exe or libraries)
strip --strip-unneeded ./dist/bin/*
if [ $osname = "darwin" ]; then
# I'm not sure if this exactly reproduces --strip-unneeded on darwin
strip ./dist/bin/*
else
strip --strip-unneeded ./dist/bin/*
fi

# Copy contents of dist-share (ipopt lib, include, and share) into dist
cp -r ./coinbrew/dist-share/* ./dist/

# Patch to remove "Requires.private: coinhsl coinmumps"
# Note that we are patching the file *after* we copy it into the directory
# we will distribute.
patch ./dist/lib/pkgconfig/ipopt.pc < $IDAES_EXT/scripts/ipopt.pc.patch
#patch ./dist/lib/pkgconfig/ipopt.pc < $IDAES_EXT/scripts/ipopt.pc.patch

# Handle platform-dependent sed behavior...
if [ $osname = "darwin" ]; then
sed -i "" "s/^Requires\.private/#Requires.private/" dist/lib/pkgconfig/ipopt.pc
else
sed -i "s/^Requires\.private/#Requires.private/" dist/lib/pkgconfig/ipopt.pc
fi

echo "#########################################################################"
echo "# Copy License and Version Files to dist-solvers #"
Expand Down Expand Up @@ -478,21 +501,25 @@ cd $IDAES_EXT
echo "#########################################################################"
echo "# k_aug, dotsens #"
echo "#########################################################################"
git clone $K_AUG_REPO
cp ./scripts/k_aug_CMakeLists.txt ./k_aug/CMakeLists.txt
cd k_aug
git checkout $K_AUG_BRANCH
if [ ${osname} = "windows" ]
then
cmake -DWITH_MINGW=ON -DCMAKE_C_COMPILER=$CC -G"MSYS Makefiles" .
if [ $with_hsl = "YES" ]; then
git clone $K_AUG_REPO
cp ./scripts/k_aug_CMakeLists.txt ./k_aug/CMakeLists.txt
cd k_aug
git checkout $K_AUG_BRANCH
if [ ${osname} = "windows" ]
then
cmake -DWITH_MINGW=ON -DCMAKE_C_COMPILER=$CC -G"MSYS Makefiles" .
else
cmake -DCMAKE_C_COMPILER=$CC .
fi
make $PARALLEL
cp bin/k_aug* $IDAES_EXT/dist/bin/
cp dot_sens* $IDAES_EXT/dist/bin/
# Return to root directory
cd $IDAES_EXT
else
cmake -DCMAKE_C_COMPILER=$CC .
echo "Skipping k_aug and dot_sens as we are not using HSL"
fi
make $PARALLEL
cp bin/k_aug* $IDAES_EXT/dist/bin/
cp dot_sens* $IDAES_EXT/dist/bin/
# Return to root directory
cd $IDAES_EXT

echo "#########################################################################"
echo "# PETSc #"
Expand Down

0 comments on commit 449d332

Please sign in to comment.