Tuesday, May 20, 2014

Installing or rebuilding ParFlow on OS X 10.9 Mavericks

By Nick Engdahl

Yes, we know…it's been quite a while since an update has been posted on how to install ParFlow on Mac OS X. In our defense, for the most part, not much has changed in the last two updates (Lion and Mountain Lion) but the latest update, OS X 10.9 Mavericks, could give you some problems, particularly if you're updating from an older OS X installation. The quick explanation is that Apple has moved a few things around behind the scenes in Mavericks and we need to make sure the compiler we're intending to use is actually the one that gets used.

This post is structured similarly to the last posted instructions with a few changes. Included this time are also notes on how to update your OpenMPI installation and a few other tips for working with a Mac that has been updated to Mavericks as opposed to one that came with Mavericks pre-installed. From here on, I'm assuming you are already running Mavericks.

The basic outline of the process is:
- Install GCC
- Install OpenMPI
- Install SILO
- Install HYPRE
- Install ParFlow
Most of these sections will also include notes about how to recompile or update if you just upgraded from an older OS X version. After all the installation instructions are a few "what ifs" we've seen when building ParFlow on various systems. Alrightythen, here we go.


0. Install GCC

If you don't already have them installed, you'll need the command line tools from Apple before you can proceed. There are two ways to get them: 1) download Xcode (which now includes them starting with OSX Mavericks), or 2) just install command line tools. Xcode is a complete development environment but it takes up 4-5Gb of space that might not be worth it if you don't plan on writing/modifying much code; just the command line tools take up slightly more than 300Mb.

Whichever you decide on, both are available from the Apple developers website (https://developer.apple.com/downloads/index.action). If you're not a registered developer, it's free to register but make sure you download the latest version for your OS. After downloading and running the package installer you chose, download the GNU compiler collection (GCC) from http://hpc.sourceforge.net using this link:
gcc-4.9-bin.tar.gz

This is actually a pre-compiled version of GCC specifically for OS X Mavericks that is very easy to install compared to building your own GCC from the source code. Open a terminal window and navigate to your downloads folder (or wherever the file is saved):

> cd ~/Downloads

Your browser may have automatically unzipped the archive for you, creating a file called "gcc-4.9-bin.tar" (but if not type gunzip gcc-4.9-bin.tar.gz to unzip the archive). In your terminal window, execute the following:

> sudo tar -xvf gcc-4.9-bin.tar -C /

which installs GCC to "/usr/local/". Check the version by typing "gfortran -v" and  you'll see something like this among the output lines:

gcc version 4.9.0 20140309 (experimental) (GCC)

telling us the version we just installed is actually recognized. Now type "gcc -v" and see what comes back. If you see the same thing as before, you should be fine and can move on to the next step

...but if you see something like this in the output:

Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)

Apple's internal C-compiler "clang" is still being used instead of the GCC we just installed; this is one of those "behind the scenes" changes Apple made in Mavericks. There are a few solutions to this problem but the simplest is to change your PATH variable. Navigate to your home area and edit your .bash_profile

> cd ~
> vim .bash_profile

Depending on your setup, there might be a lot in this file or it might be empty. Key down to the bottom of the file, press "i" to enter insert mode, move to the end of this line and hit "return" twice to add some blank lines. Next add the following line to the BOTTOM of the file:

export PATH=/usr/local/bin/:$PATH

This forces your Mac to look in /usr/local/bin/ first while preserving the rest of your PATH variable and any changes made to it in the rest of your .bash_profile. Hit "esc" to exit insert mode, and type ":x" followed by "return" to save the changes and exit. Back at the command prompt, type:

> source .bash_profile

To activate the change. Verify gcc is now being used by typing "gcc -v" and you should now see:

gcc version 4.9.0 20140309 (experimental) (GCC)

Now we can move on to the next step.


1. Installing or updating OpenMPI

To start, let's assume you've never installed OpenMPI; we'll cover updating/recompiling in a minute. If you're recompiling a previously installed version of ParFlow, you probably followed the last posted instructions and placed all of your required code in a folder called "ParF". If not, go ahead and create one now. In a terminal window, type the following:

> cd ~
> mkdir ParF
> cd ParF

We're now going to download the latest version (as of this writing) of OpenMPI directly in to this folder then install it:

> curl "http://www.open-mpi.org/software/ompi/v1.8/downloads/openmpi-1.8.1.tar.gz" -o "openmpi-1.8.1.tar.gz"
> tar -xvf openmpi-1.8.1.tar.gz
> cd openmpi-1.8.1
> ./configure --prefix=/usr/local/
> sudo make all install

Doing all that can take anywhere from "a short while" to "a very long time" in order to finish but MPI should now be installed. If you want to remove the "openmpi-1.8.1.tar.bz" you can. Note: If you're not familiar with "curl" it's the OS X equivalent of "wget"


These next two sub-sections are special installation cases; if you're installing ParFlow for the first time, just skip to Step 3.

a. Recompiling a previous OpenMPI installation

Let's say you upgraded your Mac to Mavericks but already had ParFlow installed. It is very likely you'll need to recompile OpenMPI in order to run ParFlow but be sure to verify that the correct compiler is being used first! The installation might seem to go fine, but you'll probably see strange errors once you try to run a model if you don't rebuild.

Navigate to your OpenMPI installation. My old installation is in "~/ParF/openmpi-1.6.5"

> cd ~/ParF/openmpi-1.6.5
> sudo make uninstall
> ./configure --prefix=/usr/local/
> sudo make all install

The "make uninstall" completely removes all of the files associated with an installation and the rest rebuilds everything using the compilers we set up in step 1.


b. Updating your OpenMPI version

This is just a combination of the last two items, but we're going to remove the old install completely, then install the new version. Again, be sure to verify that the correct compiler is being used first!

Navigate to your OpenMPI installation. Again, my old installation is in "~/ParF/openmpi-1.6.5"

> cd ~ParF/openmpi-1.6.5
> sudo make uninstall
> cd ..
> sudo rm -rf openmpi-1.6.5

The old version of OpenMPI is now completely wiped from your system. Installing the new version is exactly the same as above:

> curl "http://www.open-mpi.org/software/ompi/v1.8/downloads/openmpi-1.8.1.tar.gz" -o "openmpi-1.8.1.tar.gz"
> tar -xvf openmpi-1.8.1.tar.gz
> ./configure --prefix=/usr/local/
> sudo make all install

Version 1.8.1 (or whatever version you picked) of OpenMPI is now installed.



3. Setup environment variables 

In the terminal, navigate to your home folder and edit your ".bash_profile" for example "vim .bash_profile". We want to make sure the following lines are included in this file:

export SILO_DIR=~/ParF/silo/
export HYPRE_DIR=~/ParF/hypre/
export PARFLOW_DIR=~/ParF/parflow/

Assuming those are the paths you intend to use, if not modify as necessary. Modify or add the following lines:

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

Save the file and type "source .bash_profile" to apply the changes to your active terminal.


4. Download and install SILO

Navigate to "ParF", download SILO and extract the archive with:

> cd ~/ParF
> curl "https://wci.llnl.gov/codes/silo/silo-4.9.1/silo-4.9.1.tar.gz" -o "silo-4.9.1.tar.gz"
> tar -xvf silo-4.9.1.tar.gz

If you have an existing folder named silo, remove it (i.e. "rm -rf silo") or rename it (i.e. "mv silo silo_old"), then complete the setup with:

> mv silo-4.9.1 silo
> cd silo
> ./configure --disable-silex
> make install
> cd ..

If the setup was successful, near the end of the output you'll see a "NOTICE:" about the test cases not being compiled by default.


5. Download and install HYPRE

Assuming you're back in the folder "ParF", download, extract, and install HYPRE with:

> curl "http://computation.llnl.gov/casc/hypre/download/hypre-2.9.0b.tar.gz" -o "hypre-2.9.0b.tar.gz"
> tar -xvf hypre-2.9.0b.tar.gz
> mv hypre-2.9.0b hypre
> cd hypre/src
> ./configure --prefix=$HYPRE_DIR
> make install

It might take a little time to install, but much less than OpenMPI took. HYPRE should now be installed.

Note: If you are changing versions of HYPRE, the method for removing the old version is very similar to what's outlined for OpenMPI. Just switch out the OpenMPI paths for the HYPRE path.

6. Install ParFlow

Note: If you are reinstalling a perviously downloaded/installed version of ParFlow, navigate to "$PARFLOW_DIR/pfsimulator" and type "make veryclean" before proceeding, or remove the "parflow" folder entirely from ~/ParF

Download the source code and move it to a folder called "parflow" within the "ParF" directory (if you already have ParFlow, navigate to "$PARFLOW_DIR/pfsimulator" and reconfigure). One way of getting ParfFow is to execute the following "curl" command, just make sure to check Reed Maxwell's download page and substitute the "r670" part of the "tar.gz" for whatever the most recent version is. To do so, execute the following:

> cd ~/ParF
> curl "http://inside.mines.edu/%7Ermaxwell/parflow.r670.tar.gz" -o "parflow.tar.gz"
> tar -xvf parflow.tar.gz
> cd parflow/pfsimulator
> ./configure --prefix=$PARFLOW_DIR --with-clm --enable-timing --with-silo=$SILO_DIR --with-hypre=$HYPRE_DIR --with-amps=mpi1 --with-amps-sequential-io

and pause for a moment. First, past users might not recognize the "sequential-io" flag. This is optional but it tells ParFlow to use a single file for distributed PFB outputs instead of 1 file for each processor. More importantly, before continuing we need to modify the Makefile to fix a few errors or else the installation will fail.

Within the "config" folder, there exists a file called "Makefile.config"; locate it and open it in the editor of your choice. The changes we need to make happen in the LDLIBS specification near the bottom of the file. There are three changes to make: 1) add a "-l" in front of "gfortran", 2) remove the stray "-l", and 3) remove the space between a "-l" and "gfortran". Each change is highlighted in red below:

BEFORE:
LDLIBS        = $(LDLIBS_EXTRA)  -lHYPRE  -lsilo    -lmpi  gfortran -L/usr/local/lib/gcc/x86_64-apple-darwin13.1.0/4.9.0/../../.. -L/usr/local/lib/gcc/x86_64-apple-darwin13.1.0/4.9.0  -l -lgfortran -lSystem -lgcc_ext.10.5 -lgcc -lquadmath -lm -lm -lm  -lgfortran -lquadmath -lm  -lgfortran -lquadmath -lm -l gfortran -lgfortran -lSystem -lgcc_ext.10.5 -lgcc -lquadmath -lm -lm

AFTER:
LDLIBS        = $(LDLIBS_EXTRA)  -lHYPRE  -lsilo    -lmpi  -lgfortran -L/usr/local/lib/gcc/x86_64-apple-darwin13.1.0/4.9.0/../../.. -L/usr/local/lib/gcc/x86_64-apple-darwin13.1.0/4.9.0  -lgfortran -lSystem -lgcc_ext.10.5 -lgcc -lquadmath -lm -lm -lm  -lgfortran -lquadmath -lm  -lgfortran -lquadmath -lm -lgfortran -lgfortran -lSystem -lgcc_ext.10.5 -lgcc -lquadmath -lm -lm

Some of the paths might be slightly different on your machine, but the changes should be the same. This line cannot have any stray "-l" characters or anything that doesn't begin with "-l" or "-L", so if you're getting additional errors, check the LDLIBS line for any of those. Save "Makefile.config", make sure you're in "~/ParF/parflow/pfsimulator" and type

> make install

You'll see lots of things flash by, including lots of warnings, but at the end you should see:

Installing parflow to /Users/nengdahl/ParF/parflow

which means pfsimulator is installed. Of course, your username will be in the path instead of mine.


7. Install pftools

Note: If you are reinstalling a perviously installed version of pftools, navigate to "~/ParF/parflow/pftools" and type "make veryclean" before proceeding

We also need to install PFtools so from "~/ParF/parflow/pfsimulator" do the following:

> cd ../pftools
> ./configure --prefix=$PARFLOW_DIR --with-clm --enable-timing --with-silo=$SILO_DIR --with-hypre=$HYPRE_DIR --with-amps=mpi1 --with-amps-sequential-io

You need to make the exact same change to the "Makefile.config" in the "pftools/config" folder that you did for pfsimulator. After making that change, type "make install" to finish the installation.


8. Test the installation

It would be very bad to assume a seemingly error free installation is valid, so a suite of test cases are provided with ParFlow to verify its behavior. To run them all, navigate to the "test" folder:

> cd $PARFLOW_DIR/test
> make check

Some of the tests will indicate failures but that has to do with specific processor topologies that don't exist on your computer. As long as most are passing, you're in good shape.

If you just want to run one test, try seeing if default_richards.tcl passes:

> tclsh default_richards.tcl 1 1 1

Hopefully that returns:

default_richards : PASSED

and all is now well in the world of ParFlow. Within "parflow/test", type "make clean" to remove the outputs of the tests and that's all there is to the installation.


9. What if TCL isn't found?

Some folks have reported that TCL isn't found sometimes during the installation of pftools. TCL is installed on your Mac by default so you just need to point the configuration utility to the correct path for TCL. To do this, add the following line to the end of the ./configure line above for pftools:

--with-tcl=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/

The path on your system might be slightly different so you may have to find the path yourself. Regardless, once you know the path to TCL, add it to the ./configure and you should be fine.


10. What if I'm using different compilers?

The main change that needs to be made in order to use a different compiler is in the setup of your .bash_profile since this is where ParFlow, HYPRE, and SILO look to determine which compiler to use.  So, if we had access to and wanted to use the MPI wrapped Intel compilers our .bash_profile would change to something like:

export CC=mpiicc
export CXX=mpiicpc
export FC=mpif90
export F77=mpif90

Everything else should be about the same in the installation but there or may not be changes that need to be made to your  LDLIBS line in the Makefile.config for pfsimulator and pftools. We've found that the configure script sometimes tries to link to a library as -lrt" (yes, it has a quotation mark hanging off the back) when using the Intel compilers and this will usually cause the installation to fail. If you see one or more flags in your LDLIBS line that includes a single quotation mark, just delete the entire flag.


11. What if aliens from the Andromeda galaxy invade the planet while I'm installing?

Now would be a good time to step away from the computer.






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

Wednesday, March 31, 2010

Running ParFlow on Windows using VirtualBox (also updated instructions for installing ParFlow in Ubuntu)


-->
The title of this post may be a little misleading. This is not actually an instruction to run ParFlow on Windows, but a quick and easy way for Windows users to have access to ParFlow on Ubuntu Linux using virtualization. Sun Microsystems’ VirtualBox is a free and open source virtualization package that allows additional operating systems to run inside another operating system as an application.
This post is divided into three parts. The first section will detail the steps for setting up VirtualBox in Windows. The second part provides instructions for installing and configuring Ubuntu Linux on the virtual machine. The third section is an updated set of instructions for building ParFlow on an Ubuntu system, applicable to both native and virtual Ubuntu installations.
I completed this installation using Microsoft Windows XP SP3 (32-bit), VirtualBox 3.1.4, and Ubuntu 9.10 (32-bit). If you are running a 64-bit version of Windows, you can run a 32-bit or 64-bit version of Ubuntu in your VirtualBox. 64-bit Ubuntu will not work unless you are running a 64-bit version of Windows. When in doubt, install the 32-bit version. These instructions detail the 32-bit installation, but I will make note where differences appear for 64-bit. Excluding download time, setting up a virtual Ubuntu machine takes a little more than an hour.

Installing VirtualBox and setting up your virtual machine
  1. Download the following:
    • Sun VirtualBox – select the version for Windows hosts
    • Ubuntu – for a 64-bit version, Click “Alternative download options” and select “64-bit version” before starting your download. The file is around 700 MB.
  1. Install VirtualBox. This is a standard Windows installation wizard. On Windows XP, you may see several “Logo Testing” failures, which you may ignore.
  1. Start VirtualBox. You will be required to register the software. I did this three weeks ago, and they haven’t sent me any emails to date.
  1. Click “New” in the upper left corner to start the wizard. You may name it anything you like. Select “Linux” in the Operating System dropdown, and select “Ubuntu” in the Version dropdown (or select Ubuntu (64-bit) for a 64-bit install)
  1. Choose how much memory to allocate to Ubuntu. You may choose up to half of the total memory of your computer. 512 MB is the minimum recommended. I went with 1200 MB
  1. Create a Virtual Hard Disk when prompted by the wizard, and check “Boot Hard Disk.”
    • You will be given the choice between dynamically expanding storage or fixed-size storage. The wizard provides a good explanation of each. I picked dynamically expanding.
    • Next, set the size (or maximum size for dynamically expanding) of your virtual hard disk. 10.00 GB will cover you for the operating system, ParFlow and support software, and it will leave room for a small amount of data. I went with 20.00 GB to make sure I have plenty of space for small runs. I would not recommend going under 10.00 GB.
  1. After you finish the wizard, create a shared folder. This will allow you to transfer files between your Ubuntu virtual machine and your Windows machine.
    • In Windows Explorer, create a folder that you want to use as your shared folder.
    • In the VirtualBox window, select the virtual machine you just created, click Settings, then click Shared Folders
    • Click the icon to add a folder (looks like a folder with a green ‘plus’ sign), and enter the path (or click other and navigate) to the folder you just created. “Folder name” is not the name you gave it in Windows. It is the name that will identify it in Ubuntu later. I called it “shared_folder.” Don’t make it read only: that would make it pretty useless.
    • Click OK, click OK.
  1. You’re almost ready to start installing Ubuntu. If you have ever installed Windows, this is painless in comparison. First, we must mount the Ubuntu iso file. The virtual machine will recognize this as a CD.
    • In the VirtualBox window, click File>Virtual Media Manager.
    • Click the CD/DVD Images tab, then click Add.
    • Find and select the Ubuntu image file you downloaded from ubuntu.com, and click OK.
    • Select your virtual machine again and click settings, then click Storage. Under Storage Tree, click the icon that looks a bit like a CD.
    • Under Attributes, select the Ubuntu image file from the CD/DVD Device dropdown list.
    • While you’re dealing with settings, click Display and check the box to “Enable 3D Acceleration.” This will eventually allow you to work in full screen.
Now you’re ready to configure and install Ubuntu on your virtual machine.

Installing and configuring Ubuntu on a Virtual Machine
  1. In the VirtualBox window, select your virtual machine and click Start. This should start installing Ubuntu. Simply follow the on-screen prompts. When you get the part about partitioning, make sure the virtual hard disk you created earlier is selected. If you know what you’re doing, you can set up your partitions manually. If not, select “Erase and use entire disk.” Don’t worry; this won’t touch anything but the virtual hard disk you created earlier, which exists only as a single file on your Windows machine.
  1. Installation may take 45 minutes to an hour, depending on how fast your computer is. When it’s done, you will be prompted to restart. Go ahead and restart. When it tells you to remove the CD from the drive, close the window.
  1. Back in the VirtualBox window, select your virtual machine, click Settings, click storage. Select the CD icon under Storage Tree, then select “Empty” from the CD/DVD Device dropdown list under Attributes. Click OK.
  1. Start the virtual machine again. When it has finished booting into Ubuntu, start setting up Ubuntu to access the shared folder you created in Windows.
    • Go to Devices>Install Guest Additions. Cancel the dialog box that appears (don’t worry if it doesn’t appear).
    • Open a terminal window (Applications>Accessories>Terminal) and enter the following commands:
sudo apt-get install dkms [you will be prompted for your password]
cd /media/cdrom
sudo ./VBoxLinuxAdditions-x86.run
(for a 64-bit installation, enter “sudo ./VBoxLinuxAdditions-amd64.run” instead)
sudo reboot
*If you can't get this to work correctly, try restarting the virtual machine, then try again. If it still won't work, see the comment at the bottom of this post.
  • When Ubuntu finishes rebooting, open a terminal window again and create a directory for your Windows/Ubuntu shared folder. I created mine in the home directory and called it “send_to_XP.”
mkdir send_to_XP
  • In step 7 of installing VirtualBox above, you named a folder for use in Ubuntu. I called mine “shared_folder.” Let’s see if it works. It should. When you input your directory in Ubuntu in the following command, it is best to use the full absolute path, to avoid putting it in the wrong place or overwriting something important (I tell you this because it happened to me).
sudo mount –t vboxsf shared_folder /home/john/send_to_XP
  • If that worked, you now have access to a folder shared between Ubuntu and Windows. Try it out. Stick a file in the folder in Windows. Then open the directory in Ubuntu (Places>Home Folder) and see if the file is in the “send_to_XP” folder (or whatever you decided to call it).
  1. You will have to run the above command every time you start Ubuntu in order to use your shared folder. Here’s a way to mount it automatically so you don’t have to run that command every time:
    • Open the “fstab” file in a text editor (vi and gedit are installed by default).
sudo gedit /etc/fstab
    • Copy the following line to end of the “fstab” file, changing the directory names to the ones you used and "john" to your own username .
shared_folder /home/john/send_to_XP vboxsf defaults,uid=john,gid=john,fmask=111,dmask=022 0 0
  1. You can skip this step and come back to it after you’ve installed ParFlow. It involves up to 2 hours of unattended downloading and updating.
By now, “[Update Manager]” should appear at the bottom of the Ubuntu window. Click it. Click “Check.” You’ll be prompted for your password. When the check finishes, click “Install Updates.” When it is finished, you will probably be prompted to restart. Go ahead and restart.

Installing Parflow in Ubuntu
The instructions in this section are applicable to building ParFlow on both native and virtual installations of Ubuntu. These instructions should be much easier and more effective than those in my previous post about installing ParFlow on Ubuntu.
  1. Open a terminal window.
  1. You will first need to download and install C, C++ and Fortran compilers and Tcl/Tk. The download list below also includes optional, but recommended text editors. Ubuntu ships with vim-lite, which sucks. At the very least, install the full version of vim. Downloading and installing these is very easy. All you have to do is enter the following commands:
sudo apt-get install gcc
sudo apt-get install g++
sudo apt-get install gdc
sudo apt-get install gfortran
sudo apt-get install tcl-dev
sudo apt-get install tk-dev
Optional
sudo apt-get install vim [highly recommended]
sudo apt-get install jedit [my favorite text editor – allows vertical selection]
  1. Now, download software from the internet. OpenMPI is optional if you are using a machine with a single-core processor. Silo is optional if you do not intend to use the VisIt visualization package. VisIt is also optional, but recommended as it is a good visualization package that lends itself well to use with ParFlow.
    • ParFlow
    • Hypre – A powerful solver package that greatly enhances the performance of ParFlow
    • Silo
    • VisIt
Choose a version for Ubuntu 8.04 (which will work for 9.10 also). Be sure to pick the correct 32-bit or 64-bit version.
    • OpenMPI – if you intend to utilize a multi-core processor, you will need this in order to do so.
  1. Build a directory structure for your ParFlow installation. It really helps to keep this organized, I’ve found, and it’s easy to do. Make a directory in your home directory for ParFlow and its supporting software. I called mine “parflow.” Then place the downloads from step 3 into that directory. If you’re not already working in the terminal window, now you must. I’ll use my directory structure as the example here.
    • Move into the new parflow directory and unpack the downloaded *.tar.gz files. If you’re new to linux command line operations, the [tab] button auto-completes your typing on the command line. I’ll use that in the commands below.
cd [takes you to your home directory]
cd parflow
tar –xvf parflow[tab]
tar –xvf hypre[tab]
tar –xvf silo[tab]
tar –xvf visit[tab]
tar –xvf openmpi[tab]
  • Each “tar” command creates a directory with version numbers at the end of the name (except visit). I renamed the parflow, hypre and silo directories to simply “parflow,” “hypre,” and “silo” for simplicity.
  1. Set environmental variables. This makes the installation a breeze, when we get to it. You can do this on the command line, but it is better to set them in the .bash_aliases file. Then you only have to do it once.
Depending on your text editor of choice:
vi ~/.bash_aliases
jedit ~/.bash_aliases or
gedit ~/.bash_aliases
Add the following lines, adjusted for your own directory structure, of course.
export CC=gcc
export CXX=g++
export FC=gfortran
export F77=gfortran

export PARFLOW_DIR=/home/john/parflow/parflow

export SILO_DIR=/home/john/parflow/silo
export HYPRE_DIR=/home/john/parflow/hypre
export PATH=$PATH:/home/john/parflow/visit/bin

Now it’s time to start installing. But first, source your bash aliases
source ~/.bash_aliases
  1. Install OpenMPI
cd openmpi[tab]
sudo ./configure
sudo make all
sudo make check
sudo make all install
cd ..
  1. Install Silo
cd silo
./configure --prefix=$SILO_DIR --disable-silex

make all
make check
make all install
cd ..
  1. Install Hypre
cd hypre/src
./configure --prefix=$HYPRE_DIR --with-MPI [if you’re not using MPI, use --without-MPI]
make all
make check
make all install
cd ../..
  1. Install ParFlow and PFTools, run the test cases
cd parflow/pfsimulator
./configure --prefix=$PARFLOW_DIR --enable-timing --with-clm --with-silo=$SILO_DIR --with-hypre=$HYPRE_DIR --with-amps=mpi1 [if you’re not using MPI, leave the last flag off]
make install
cd ../pftools
./configure --prefix=$PARFLOW_DIR --with-silo=$SILO_DIR --with-amps=mpi1 [if you’re not using MPI, leave the last flag off]
make install
cd ../test
sudo ldconfig
make check