Thursday, October 20, 2011

Building ParFlow on OS X 10.7.x Lion

By Sophia Seo

1. Open a terminal window and set environmental variables.
       1)   Go to your Mac home folder: cd ~
       2)   List the files there: ls -al
       3)   Check for a file called .bash_profile (it's a hidden file, so it has the period in front of the file name).
       4)   If it doesn't exist, you need to create one using any text editor. You need to make sure you save it to your home folder and have the first line be: 
       5) export PATH=/usr/local/bin:$PATH

       6)   If you already have a .bash_profile file, open it: vi .bash_profile
       7)   and just add the above line to the top.

       8)   To insert before cursor, type i.
       9)   To save and exit VI, type ZZ.
     10)  Doing this tells your terminal shell to give you access to the commands (ie. gfortran) in the /usr/local/bin directory.
    11)  Set environmental variables. You can do this on the command line, but I find it is easy to set them in the .bash_profile file.

export PATH=/usr/local/bin:$PATH
export PARFLOW_DIR=~/ParF/parflow/
export SILO_DIR=~/ParF/silo/
export HYPRE_DIR=~/ParF/hypre/

export CC=gcc
export CXX=g++
export FC=gfortran
export F77=gfortran

12) Then, source your .bash profile: source .bash_profile

2. Create a new directory for ParFlow installation.

mkdir ParF

This will create a new directory “ParF”, and OpenMPI, Silo, Hyper, and Parflow will be installed in this directory.  

3. Download compilers and software.
       1)   gcc (gcc-lion.tar.gz) : This will install both gcc and gfortran. If you use gcc that comes with X-Code Version 4.2 for lion, you will have hard time configuring gfortran.
       2)   OpenMPI (openmpi-1.4.4.tar.bz2) : Apple did not include OpenMPI in Mac OS X Lion (it was supported in Leopard and Snow Leopard), so you need download and install it.
-
http://www.open-mpi.org/software/ompi/v1.4/
       3)   ParFlow (ParFlow.r605.tar.gz)
-
http://inside.mines.edu/~rmaxwell/maxwell_software.shtml
       4)   Hypre (hypre-2.7.0b)
       5)   Silo (Silo-4.8.tar.gz)
-
https://wci.llnl.gov/codes/silo/downloads.html

4. Install
You will find all downloaded files in the “Downloads” directory under Mac home folder. Go to the “Downloads” directory and make sure you have all files.

cd Downloads
ls
parflow.r605.tar
gcc-lion.tar        
hypre-2.7.0b.tar    
openmpi-1.4.4.tar.bz2    
silo-4.8.tar

       1)   Extract and Install gcc and gfortran          

sudo tar -xvf gcc-lion.tar -C /.

This command will install both gcc and gfortran in the root directory, so you will be asked to provide a password. After installation, you can check the path and version of each compiler.

which gcc
/usr/local/bin/gcc  

gcc --version
gcc (GCC) 4.6.1
Copyright (C) 2011 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.

which gfortran
/usr/local/bin/gfortran

gfortran --version
GNU Fortran (GCC) 4.6.1
Copyright (C) 2011 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

       2)   Extract and Install openmpi

Extract openmpi-1.4.4.tar.bz2 to the “ParF” directory. Make sure you are in the “Downloads” directory.
 
sudo tar -vxf openmpi-1.4.4.tar.bz2 -C /Users/hseo/ParF
Password:

Go to the openmpi-1.4.4 directory and install it.

cd ../ParF/openmpi-1.4.4/
sudo ./configure
sudo make install
cd ..

       3)   Extract and Install silo

Now you are in the “ParF” directory. Grab silo-4.8.tar from the “Downloads” directory and extract to the “ParF” directory.
 
tar -vxf /Users/hseo/Downloads/silo-4.8.tar

You will see the directory “silo-4.8” is created.  I renamed “silo-4.8” to “silo” just for simplicity. Go to the “silo” directory and install it.

mv silo-4.8/ silo
cd silo/
./configure --disable-silex
make install
cd ..

       4)   Extract and Install hypre

Make sure you are in the “ParF” directory. Grab hypre-2.7.0b.tar from the “Downloads” directory and extract to the “ParF” directory.

tar -xvf /Users/hseo/Downloads/hypre-2.7.0b.tar

You will see the directory “hypre-2.7.0b” is created.  I renamed “hypre-2.7.0b” to “hypre” just for simplicity. Go to the “hypre/src” directory and install it.

mv hypre-2.7.0b/ hypre
cd hypre/src
./configure --prefix=$HYPRE_DIR
make install
cd ../..  

       5)   Extract and Install ParFlow

Make sure you are in the “ParF” directory. Grab parflow.r605.tar from the “Downloads” directory and extract to the “ParF” directory.

tar -xvf /Users/hseo/Downloads/parflow.r605.tar

You will see the directory “parflow.r605.tar” is created.  I renamed “parflow.r605” to “parflow” just for simplicity. Go to the “parflow/pfsimulator” directory and install it.

mv parflow.r605/ parflow
cd parflow/pfsimulator/
./configure --prefix=$PARFLOW_DIR --with-clm --enable-timing --with-silo=$SILO_DIR --with-hypre=$HYPRE_DIR --with-amps=mpi1
make install

You will see the following errors at the end.

gcc: error: gfortran: No such file or directory
make[1]: *** [../bin/parflow] Error 1
make: *** [all] Error 1

You need to edit Makefile.config to make changes in LDLIBS. Go to the “config” directory and open Makefile.config with VI.

hseo$ cd config
vi Makefile.config

Search for gfortran using slash.

/gfortran

Keep pressing “n” to find the following sentence.  You will see there are missing characters in front of gfortran. Press “i” to insert letters. Type “-l” and exit by pressing the esc key. And press ZZ to save and exit.

LDFLAGS       =  -L$(PARFLOW_LIB_DIR)  -L/Users/hseo/ParF/hypre//lib  -L/Users/hseo/ParF/silo//lib    -L/usr/local/lib   -L/usr/local/lib/gcc/x86_64-apple-darwin11.0.0/4.6.1 -L/usr/local/lib/gcc/x86_64-apple-darwin11.0.0/4.6.1/../../..  -L/usr/local/lib/gcc/x86_64-apple-darwin11.0.0/4.6.1 -L/usr/local/lib/gcc/x86_64-apple-darwin11.0.0/4.6.1/../../.. -L/usr/local/lib/gcc/x86_64-apple-darwin11.0.0/4.6.1 -L/usr/local/lib/gcc/x86_64-apple-darwin11.0.0/4.6.1/../../.. $(LDFLAGS_EXTRA)
LDLIBS        = $(LDLIBS_EXTRA)  -lHYPRE  -lsilo    -lmpi  -lgfortran -L/usr/local/lib/gcc/x86_64-apple-darwin11.0.0/4.6.1/../../.. -L/usr/local/lib/gcc/x86_64-apple-darwin11.0.0/4.6.1  -l -lcrt1.10.5.o -lgfortran -lSystem -lgcc_ext.10.5 -lgcc -lquadmath -lm -lm -lm  -lgfortran -lquadmath -lm  -lgfortran -lquadmath -lm -l gfortran -lcrt1.10.5.o -lgfortran -lSystem -lgcc_ext.10.5 -lgcc -lquadmath -lm -lm

Go back to the “pfsimulator” directory and try install again.

cd ..
make install

The following errors will show up at the end.

ld: library not found for -l-lcrt1.10.5.o
collect2: ld returned 1 exit status
make[1]: *** [../bin/parflow] Error 1
make: *** [all] Error 1

Go back to the “config” directory and open Makefile.config with VI.

cd config
vi Makefile.config

Search for crt using slash.

/crt

Keep pressing “n” to find the following sentence

LDFLAGS       =  -L$(PARFLOW_LIB_DIR)  -L/Users/hseo/ParF/hypre//lib  -L/Users/hseo/ParF/silo//lib    -L/usr/local/lib   -L/usr/local/lib/gcc/x86_64-apple-darwin11.0.0/4.6.1 -L/usr/local/lib/gcc/x86_64-apple-darwin11.0.0/4.6.1/../../..  -L/usr/local/lib/gcc/x86_64-apple-darwin11.0.0/4.6.1 -L/usr/local/lib/gcc/x86_64-apple-darwin11.0.0/4.6.1/../../.. -L/usr/local/lib/gcc/x86_64-apple-darwin11.0.0/4.6.1 -L/usr/local/lib/gcc/x86_64-apple-darwin11.0.0/4.6.1/../../.. $(LDFLAGS_EXTRA)
LDLIBS        = $(LDLIBS_EXTRA)  -lHYPRE  -lsilo    -lmpi  -lgfortran -L/usr/local/lib/gcc/x86_64-apple-darwin11.0.0/4.6.1/../../.. -L/usr/local/lib/gcc/x86_64-apple-darwin11.0.0/4.6.1  -l -lcrt1.10.5.o -lgfortran -lSystem -lgcc_ext.10.5 -lgcc -lquadmath -lm -lm -lm  -lgfortran -lquadmath -lm  -lgfortran -lquadmath -lm -l gfortran -lcrt1.10.5.o -lgfortran -lSystem -lgcc_ext.10.5 -lgcc -lquadmath -lm –lm

Delete –l which is marked in red and save and exit.
Go back to the “pfsimulator” directory and try install again.

cd ..
make install

Change the directory to go “pftools” and configure and make install.

cd ../pftools/
./configure --prefix=$PARFLOW_DIR --with-clm --enable-timing --with-silo=$SILO_DIR --with-amps=mpi1
Make install

You will get the same errors.

gcc: error: gfortran: No such file or directory
make: *** [bin/pfwell_cat] Error 1

Manually edit Makefile.config to make changes in LDLIBS.

cd config
vi Makefile.config

/gfortran

Delete “-l” in front of “-lcrt1.10.5.o” and delete a space between “–l” and “gfortran” and save and exit.

LDFLAGS       =   -L/Users/hseo/ParF/silo//lib    -L/usr/lib   -L/usr/local/lib/gcc/x86_64-apple-darwin11.0.0/4.6.1 -L/usr/local/lib/gcc/x86_64-apple-darwin11.0.0/4.6.1/../../.. $(LDFLAGS_EXTRA)
LDLIBS        = $(LDLIBS_EXTRA) $(PARFLOW_TOOLS_LIBS)  -lsilo    -ltcl8.5  gfortran -L/usr/local/lib/gcc/x86_64-apple-darwin11.0.0/4.6.1/../../.. -L/usr/local/lib/gcc/x86_64-apple-darwin11.0.0/4.6.1  -l -lcrt1.10.5.o -lgfortran -lSystem -lgcc_ext.10.5 -lgcc -lquadmath -lm -lm -lm  -l gfortran -lcrt1.10.5.o -lgfortran -lSystem -lgcc_ext.10.5 -lgcc -lquadmath -lm –lm

Go back to the “pftools” directory and make install.

cd ..
make install

Everything should now work and you can cd $PARFLOW_DIR/test and make check to test that everything is working.

cd $PARFLOW_DIR/test
make check