wiki:Ipopt_on_Mac_OS_X_Snow_Leopard_and_Lion

Ipopt and the Matlab Interface on Mac OS X (Snow Leopard 10.6 and Lion 10.7)

by Ray Zimmerman, Nov 7, 2011 (last updated Nov 27, 2012)

Build Notes

(See the current version of this page for details on building Ipopt on Mountain Lion 10.8 with the MUMPS linear solver and the native OS X BLAS/LAPACK.)

Here is an updated summary of my experience building Ipopt 3.10.1 (and now 3.10.2) and the Matlab interface for it on Mac OS X 10.6 Snow Leopard and 10.7 Lion. I believe I have now built almost all combinations of the following:

OS

S = built on Snow Leopard (10.6.8), dev tools from Xcode 3.2.6
L = built on Lion (10.7.2), dev tools from Xcode 4.2

Linear Solver

M = MUMPS
H = HSL MA57

BLAS/LAPACK

A = native OS X optimized BLAS/LAPACK included with the OS (does not work on 10.7 Lion) [*1][*3]
G = Goto BLAS [*2]
N = Netlib BLAS/LAPACK

32 vs 64 bit

32 = 32-bit build (with Matlab R2010a)
64 = 64-bit build (with Matlab R2011b)

For shorthand, I'll use the letters above to distinguish between the options in the build instructions below.

[*1] Note on native OS X BLAS -- Mac OS X includes it's own optimized BLAS and LAPACK libraries in the vecLib framework, which is a sub-component of the Accelerate framework. Using -framework Accelerate or -framework vecLib has the same effect and can be used interchangeably in this context. However, it appears there is an issue with the BLAS/LAPACK in Lion's Accelerate/vecLib framework that causes Ipopt to frequently fail. I think this is related to the issue mentioned here <https://github.com/mxcl/homebrew/issues/6649#issuecomment-1666673>. So the only binaries that I could get to work reliably on Lion were those built (on Snow Leopard or Lion) with the Netlib or Goto BLAS.

[*2] Note on Goto BLAS -- I got an error when attempting to build a 64-bit version of the Goto BLAS from http://www.tacc.utexas.edu/tacc-projects/gotoblas2 so I ended up using the version from http://prs.ism.ac.jp/~nakama/SurviveGotoBLAS2/ which built just fine.

[*3] Update on native OS X BLAS -- A patch is available that appears to fix the issue with using Lion's Accelerate/vecLib framework. See https://projects.coin-or.org/Ipopt/ticket/181. This appears to be fixed in Ipopt 3.10.3.

The Steps

1. Install wget.

I used wget-1.12 from http://www.merenbach.com/software/wget .

2. Install gfortran.

I used the gfortran from http://r.research.att.com/tools/ .

S : gfortran-42-5664.pkg
http://r.research.att.com/gfortran-42-5664.pkg
L : gfortran-lion-5666-3.pkg
http://r.research.att.com/gfortran-lion-5666-3.pkg

3. Download Ipopt and set up build environment.

I use ~/build as my build directory.

cd ~/build
tar zxvf ~/Downloads/Ipopt-3.10.1.tgz
cd ~/build/Ipopt-3.10.1/ThirdParty/Metis/
./get.Metis
cd ~/build/Ipopt-3.10.1
mkdir build64
mkdir build32

4. Choose and set up BLAS.

A - do nothing (remember this option does not work on 10.7 Lion for Ipopt versions before 3.10.3)

G - download and build Goto BLAS

cd ~/build
tar zxvf ~/Downloads/SurviveGotoBLAS2_3.14_RC_20110722.tar.gz
cd ~/build/survivegotoblas2-3.14

64-bit

make BINARY=64 NUM_THREADS=1 CC=gcc-4.2

32-bit

make BINARY=32 NUM_THREADS=1 CC=gcc-4.2

The CC=gcc-4.2 is only needed on 10.7 Lion. Increasing the value of NUM_THREADS only decreased performance in my experience, even on a 12-core Mac Pro.

N - download Netlib BLAS/LAPACK

cd ~/build/Ipopt-3.10.1/ThirdParty/Blas/
./get.Blas
cd ~/build/Ipopt-3.10.1/ThirdParty/Lapack/
./get.Lapack

5. Choose and set up linear solver.

M - get Mumps

cd ~/build/Ipopt-3.10.1/ThirdParty/Mumps/
./get.Mumps

H - download latest source (coinhsl-2011.10.03.tar.gz) from http://www.hsl.rl.ac.uk/ipopt/

cd ~/build
tar zxvf ~/Downloads/coinhsl-2011.10.03.tar.gz
cd ~/build/coinhsl-2011.10.03
cp mc19/mc19d.f ../Ipopt-3.10.1/ThirdParty/HSL/mc19ad.f
cat ma57/ma57d.f common/deps.f > ../Ipopt-3.10.1/ThirdParty/HSL/ma57ad.f

6. Configure Ipopt build.

The BLAS/LAPACK options to configure, which I'll denote <BLAS_OPTIONS> depend on A vs. G vs. N ...

A - none are needed (configure will detect the vecLib framework automatically, but if it makes you feel better to be explicit you can include the following)

  --with-blas="-framework vecLib" --with-lapack="" \

G

  --with-blas="/Users/ray/build/survivegotoblas2-3.14/libgoto2.a" \
  --with-lapack="" \

(change path to match your directory structure)

N

  --with-blas=BUILD --with-lapack=BUILD \

Then the rest of the configure command depends on whether it is a 64-bit or 32-bit build:

64-bit

cd ~/build/Ipopt-3.10.1/build64
../configure --disable-shared \
  <BLAS_OPTIONS>
  F77=gfortran FFLAGS="-fexceptions -m64 -fbackslash" \
  CFLAGS="-fno-common -no-cpp-precomp -fexceptions -arch x86_64 -m64" \
  CXXFLAGS="-fno-common -no-cpp-precomp -fexceptions -arch x86_64 -m64"

32-bit

cd ~/build/Ipopt-3.10.1/build32
../configure --disable-shared \
  <BLAS_OPTIONS>
  F77=gfortran FFLAGS="-fexceptions -m32 -fbackslash" \
  CFLAGS="-fno-common -no-cpp-precomp -fexceptions -arch i386 -m32" \
  CXXFLAGS="-fno-common -no-cpp-precomp -fexceptions -arch i386 -m32"

7. Build, test and install Ipopt.

make
make test
make install

8. Set up Matlab MEX environment.

Create mexopts.sh file. This assumes you have your Matlab installed in /Applications.

64-bit

/Applications/MATLAB_R2011b.app/bin/mex -setup

(select option 1)

This creates a mexopts.sh file in the ~/.matlab/R2011b directory.
Make the modifications below in the maci64 section of this file.

32-bit

/Applications/MATLAB_R2010a.app/bin/mex -setup

(select option 1 or 2)

This creates a mexopts.sh file in the ~/.matlab/R2010a directory.
Make the modifications below in the maci section of this file.

Make these changes in the appropriate section of the mexopts.sh file:

  • change both instances of libgfortran.dylib to libgfortran.a in FC_LIBDIR line
    (my gfortran includes only static libs, besides I want this to work on machines without gfortran installed)
  • remove -Wl,-syslibroot,$SDKROOT from LDFLAGS line
    (otherwise it can't find gfortran libraries)

If using A (as opposed to G or N), you also need to add the following line, below the existing LDFLAGS line(s):

LDFLAGS="$LDFLAGS -framework vecLib"

9. Build MEX file

Go to the MEX build directory, make the indicated modifications to the Makefile, then run make.

64-bit

cd ~/build/Ipopt-3.10.1/build64/Ipopt/contrib/MatlabInterface/src
  • change:
    MATLAB_HOME = /Applications/MATLAB_R2011b.app
    MEXSUFFIX   = mexmaci64
    
  • delete, from the LIBS line:
    • all duplicates
    • S : -L/usr/lib/gcc/i686-apple-darwin10/4.2.1/../../..
      L : -L/usr/lib/gcc/i686-apple-darwin11/4.2.1/../../..
      (this causes it to find the wrong libmx.dylib, the one in /usr/lib rather than the Matlab one)
    • A (as opposed to G or N) : all instances of -framework vecLib
      (this is added in mexopts.sh now)
  • save Makefile, run make, then copy the MEX file to somewhere in your Matlab path, e.g.
    make
    cp ipopt.mexmaci64 ~/Documents/MATLAB
    

32-bit

cd ~/build/Ipopt-3.10.1/build32/Ipopt/contrib/MatlabInterface/src
  • change:
    MATLAB_HOME = /Applications/MATLAB_R2010a.app
    MEXSUFFIX   = mexmaci
    
  • delete, from the LIBS line:
    • all duplicates
    • S : -L/usr/lib/gcc/i686-apple-darwin10/4.2.1/../../..
      L : -L/usr/lib/gcc/i686-apple-darwin11/4.2.1/../../..
      (this causes it to find the wrong libmx.dylib, the one in /usr/lib rather than the Matlab one)
    • A (as opposed to G or N) : all instances of -framework vecLib
      (this is added in mexopts.sh now)
  • add -maci to beginning of MEXFLAGS line
  • save Makefile, run make, then copy the MEX file to somewhere in your Matlab path, e.g.
    make
    cp ipopt.mexmaci ~/Documents/MATLAB
    

Performance Notes

I did a number of tests on my 10.6 Snow Leopard machine to compare the performance of the various Ipopt Matlab MEX file builds. My test problems were 4 different optimal power flow problems for electricity grids, ranging in size from ~700 vars and ~1400 constraints to ~50,000 vars and ~110,000 constraints. Here is what I found.

  1. Netlib BLAS/LAPACK was on average about 30% slower than the optimized version in the Accelerate/vecLib framework. The difference was much greater (about 100%) on the larger models.
  1. Goto BLAS running as a single thread had very similar performance to the optimized version in the Accelerate/vecLib framework, noticeably better than Netlib. Increasing the number of threads for Goto BLAS only slowed it down, even on a 12-core Mac Pro.
  1. MUMPS is noticeably faster (over 50% in some cases) than MA57 on the larger models, and vice versa for the smaller models. On average they were about the same.
Last modified 6 years ago Last modified on Nov 27, 2012 1:31:31 PM