The SUNDIALS project from Lawrence Livermore National Lab is a package of tools for solving systems of ordinary differential equations (ODEs) and related problems, including MPI parallelization and GMRES-based step methods. I am testing it for use on large food web models, in the hope that it will be faster and more robust than Matlab’s methods (or, certainly, than implementing fancy methods myself). This entry covers the steps I took to get it built and working on Mac OS X Lion.
- If you just upgraded to Lion and haven’t done this yet, install Xcode from the Mac App Store.
- Install gfortran prebuilt for Lion: http://r.research.att.com/gfortran-4.2.3.dmg
- If you haven’t done this already, install and set up MacPorts.
- Install OpenMPI via MacPorts with the command
sudo port install openmpi. This can take a long time (hours), since it depends on also doing a separate MacPorts install of GCC 4.4. Starting this install is a good way to end the day. - Download SUNDIALS 2.4.0 (the whole package,
sundials-2.4.0.tar.gz) from the SUNDIALS download page. Move it to wherever you like and extract it (double-clicking works fine). - Open a terminal window,
cdinto the SUNDIALS directory, and run the following (I set my CC to gcc for the sake of safety, even though Lion defaults to LLVM):
./configure CC=gcc F77=gfortran \ --prefix=/usr/local/sundials \ --enable-shared \ --with-mpicc=/opt/local/bin/openmpicc \ --with-mpif77=/opt/local/bin/openmpif77 make sudo make install
That’s it; SUNDIALS should now be installed in /usr/local/sundials. You can use the prefix /usr/local if you like, but this way it’s conveniently kept separated from everything else.
To use it, it’s a matter of making sure that /usr/local/sundials/include is in your header search path, /usr/local/sundials/lib is in your library search path, and you give the linker -l[library name] (that’s a “hyphen lowercase ell”) for any libraries you need. For example, for the SUNDIALS example file cvsFoodWeb_ASAi_kry.c, I needed -lsundials_nvecserial -lsundials_cvodes
In Xcode, you can do this via the following steps:
- Make a new Application/Command-Line Tool project.
- Add your source code, e.g.,
cvsFoodWeb_ASAi_kry.c - In the project settings, add
/usr/local/sundials/includeto Header Search Paths. Oddly, this causes Header Search Paths to remain empty, but a User Header Search Paths field appears with your desired path. - Check Always Search User Paths
- Add your library flags, e.g.,
-lsundials_nvecserial -lsundials_cvodes, to Other Linker Flags.
If everything has gone according to plan, the code should now build and run successfully.
So far, these steps only work for serial code: when I get an MPI example compiling and running, I’ll post those steps as well.








