Wednesday, March 10, 2010

Building ParFlow on OSX 10.6.x Snow Leopard

Snow Leopard has a number of nice features but because it is 64 bit there are a few tricks to compiling ParFlow and associated libraries. Here's step-by-step tips to get everything built.

Compilers:
1) gcc, I use the gcc that comes w/ X-Code Version 3.2.1 available free from Apple.
Its' version statement is:
i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5646) (dot 1)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


2) mpi, mpicc (an mpi-wrapper for c) comes packaged w/ X-Dev. I've found this works just fine with ParFlow.

3) gfortran, The only 64-bit compatible gfortran I've found, pre-built, is here:http://r.research.att.com/tools/
Its' version statement is:
GNU Fortran (GCC) 4.2.3
Copyright (C) 2007 Free Software Foundation, Inc.
GNU Fortran comes with NO WARRANTY, to the extent permitted by law.
You may redistribute copies of GNU Fortran
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING


4) Libraries, I download and build SILO and HYPRE libraries from scratch.
SILO: https://wci.llnl.gov/codes/silo/silo-4.7.2/silo-4.7.2.tar.gz
HYPRE: v. 2.4.0b https://computation.llnl.gov/casc/hypre/software.html


5) Configure Lines
I find that all packages need to be told to build in 64 bit. This is usually done w/ an '-arch x86_64' flag in the configure line.
For SILO:
setenv SILO_DIR path-to-silo/silo-4.7.2/
or for bash
export SILO_DIR=path-to-silo/silo-4.7.2/

./configure CC='gcc -arch x86_64' CXX='g++ -arch x86_64' F77='gfortran -arch x86_64' FC='gfortran -arch x86_64' --disable-silex
make install

For HYPRE
setenv HYPRE_DIR path-to-hypre/hypre-2.4.0b/
or for bash

export HYPRE_DIR=path-to-hypre/hypre-2.4.0b/

./configure CC='gcc -arch x86_64' CXX='g++ -arch x86_64' F77='gfortran -arch x86_64' FC='gfortran -arch x86_64' --prefix=$HYPRE_DIR
make install

PARFLOW
I'm assuming you've set environmental variables PARFLOW_DIR to point to where PF is installed, SILO_DIR to point to SILO and HYPRE_DIR to point to hypre as above.
1) cd $PARFLOW_DIR/pfsimulator
2) ./configure CC='gcc -arch x86_64' F77='gfortran -arch x86_64' FC='gfortran -arch x86_64' --prefix=$PARFLOW_DIR --with-clm --enable-timing --with-silo=$SILO_DIR --with-hypre=$HYPRE_DIR --with-amps=mpi1
3) make install

The compilation process goes fine to almost the end, then errors out w/
ld: duplicate symbol start in /usr/lib/crt1.o and /usr/lib/crt1.10.6.o

These steps will fix this:
1) cd config
2) manually edit Makefile.config to change crt1.o in LDLIBS to crt1.10.6.o
3) cd ..
4) make install

PFTOOLS
1) cd $PARFLOW_DIR/pftools
2) ./configure CC='gcc -arch x86_64' F77='gfortran -arch x86_64' FC='gfortran -arch x86_64' --prefix=$PARFLOW_DIR --enable-timing --with-silo=$SILO_DIR --with-amps=mpi1
3) make install
The build process is very similar, it errors out on same linking step/error duplicate libraries. Here is how to fix:
1) cd config
2) manually change Makefile.config to reflect crt1.10.5.o to crt1.10.6.o this time in two places in the LDLIBS line (it might also be crt1.o in two places as above depending on the system)
3) make install
This now almost seems to work, but errors with an odd message at the end during the linking step
4) Manually adding the -arch x86_64 to the end of the tools linking step will fix this, you can link manually by typing:

ld -dylib pftappinit.o printdatabox.o readdatabox.o databox.o error.o velocity.o head.o flux.o diff.o stats.o tools_io.o axpy.o getsubbox.o enlargebox.o load.o usergrid.o grid.o region.o file.o pftools.o top.o water_balance.o water_table.o sum.o -o ./bin/parflow.dylib -L/usr/lib -L$PARFLOW_DIR/lib -lparflow -L$SILO_DIR/lib -lsilo -ltcl -lc -arch x86_64

from the command line.
5) make install
Everything should now work and you can cd $PARFLOW_DIR/test and make check to test that everything is working.

-Reed

1 comment:

Reed Maxwell said...

Two comments here:

1) As tools evolves, this static linker line will not always work since the additional components (toposlopes in this case) won't always be included. The easiest approach is to copy your linker line "ld -dyline ..." and add the "-arch x86_64" to it so you link with the 64 bit libs that you compiled with.

2) the most common problem when building PF on snow leopard is the 32/64 bit compilers and libraries. The version of gfortran and c I use have to match and it's usually best if they are the exact same version as I used in my example. If you have multiple versions of Fortran and/or C on your machine this almost always causes problems. You can delete the other versions or find the location and set your CC / FC etc environmental variables to those specific locations, e.g. CC='/usr/someplace/gcc -arch x86_64' instead of the default "gcc" which uses what is in your path (though in truth, setting your path up to point to the correct one is also probably a good idea). You can also use the which command to show you the location of your default version. E.g. "which gcc" might return '/usr/thewrongplace/gcc' letting you know that your defaulting to some other version of the compiler than you want.