A guide to compile Parflow (Ubuntu only)

I assume that you already know what Parflow is, otherwise you would not read these lines.

Here I’m attempting to describe the steps but more importantly the tweeks one need to do under Ubuntu.

Before that, I should acknowledge this article which was my starting point.

1) Dependencies:

2) Installation of dependencies:

TCL:

There are two options here:

  •  install it from the repositories: This is easy as doing sudo apt-get install tcl-dev and sudo apt-get install tk-dev. However later during pftools configuration you will run into few troubles.
  •  Compile Tcl from source and decide yourself where to put this. pftools will search for the tcl.h and libtcl.* files in the directories ${dir}/include and ${dir}/lib where ${dir} is either the directory provided with the option –with-TCL=${dir} or the usr and usr/local if you run configure without the option –with-TCL

Here I took the first approach. So I’ll come back on the troubles later below.

MPI:

My recomendation is to get it from the repositories. If you are attempting to install it on a cluster there should be already somewhere where the libraries can find it. In my PC I had already installed it from the Ubuntu Software Center quite sometime ago. Doing so the mpi libraries will be installed somewhere that can be found and you dont have to provide any mpi paths.

HYPRE:

After you extract the files you should go into the directory ../hypre-2.9.0b/src (in my case that was 2.9 version) and run ./configure. By default hypre enables mpi so this will configure hypre so that the installation files be under ../hypre-2.9.0b/src/hypre. Although in general its good not to mix the builds with the code but we keep things simple here. If you dont want mpi you need to add the option –without-MPI. After successfull completion of configure you can build by typing make all install. After this is completed you should see two non-empty folders: an include and a lib under  ../hypre-2.9.0b/src/hypre. You can also check by running make check

SILO:

In a similar fashion extract the files, enter the directory and run $ ./configure   –disable-silex. I had never problems with that and after a succesfull configuration the make all install will put the libraries and include files under the directory where you extracted silo, for example ../silo-4.7.2.

3) Installation of Parflow

Extract the zip file. Lets say this is the directory $ ../parflow.693. Go to pfsimulator cd pfsimulator. Run the configure command with the following options if you want clm and mpi

./configure –prefix=${HOME}/Downloads/PARFLOW/parflow.693 –enable-timing –with-clm –with-silo=${HOME}/Downloads/PARFLOW/silo-4.7.2 –with-hypre=${HOME}/Downloads/PARFLOW/hypre-2.9.0b/src/hypre –with-amps=mpi1

To keep things a bit organized I had extracted all individual libraries under the directory ${HOME}/Downloads/PARFLOW/.  The configure step went pretty smoothly in every attempt I have made so far.

Next to build parflow run $ make install. Under ubuntu you might get errors at the very end of the building process related to gfortran and m libraries. This is probably a bug in the configuration process and you need to edit manually the Makefile.config under the config folder. If your current directory is the ../pfsimulator do the following: $ gedit config/Makefile.config. Search for a line that starts with LDLIBS    = $(LDLIBS_EXTRA)  (Note this is a very long line).

-edits required in Makefile.config

In this line you may see a gfortran m. Change those to -lgfortran -lm. Further right on the same line you may see two -l -l.  Those probably are the -ls that where missing. Anyway now delete them. Keep going right you may see some gfortran and m that they apart from their -ls i.e. -l gfortran -l m. Remove the spaces between them.

Save the file, cross fingers and rerun $ make install. (DO NOT RERUN .configure). If for any reason you need to rerun configure, the process will generate the buggy file and you need to edit again.

This hopefully will finish the installation of parflow successfully.

4) Installation of pftools

Enter the pftools directory. If you are under pfsimulator then do $ cd ../pftools. Run configure with the following options

$ ./configure –prefix=${HOME}/Downloads/PARFLOW/parflow.693 –with-silo=${HOME}/Downloads/PARFLOW/silo-4.7.2  –with-amps=mpi1.


Depending on the TCL installation the configuration might fail to find TCL even if the command tclsh works perfectly for you.

If configuration was succesfull ignore the following paragraph.

Force configure to find your TCL installation

To overcome this you would have to edit the configure file under the pftools directory. To understand what edits you need to do, lets first have a look to see what the scripts attempts to do:

Selection_002

 

Line 9263: The script will loop through the folders /usr and usr/local and attempt to find the file tcl.h under various locations. For example under usr/include (line 9266) or usr/include tcl8.4 (9270) etc. In my case tcl.h was under  /usr/lincude/tcl therefore I added an extra elseif statement which would make the configure script finding my location. My edits are highlighted in the red rectangle.

This will set the variables tcl_PREFIX = /usr and tcl_INCLUDES =-I${tcl_PREFIX}/include/tcl.

Next configure will attempt to find the tcl.so library. Below is the code in the configure script that does that

Selection_003

 

The code has already set tcl_PREFIX to a value depending where the tcl.h was found. Next will look into various folders under the ${tcl_PREFIX} to find the files with names libtcl8.4.so or libtcl.so etc. In my case the tcl.so was under the ackward folder /usr/lib/x86_64-linux-gnu. To force configure script find my tcl I added the lines in the red rectangle.

There is stil on final edit to make. Just right after the above else if statements end there is the following snippet

Selection_004

 

Note that this is how it looks like after I edited according to my needs. I just added the  x86_64-linux-gnu after the lib.

A footnote here: You need to be able to locate the folders that contain the tcl.h and tcl.so files. If you are new linux user like me you migh find it very hard to track down those files. Here are few options: i)locate file ii) whereis file iii) and the best of all apt-file search file (Note that you may need to install the apt-file tool first)

After those edits you should be able at least to complete successfully the configure step.

Next run $ make install.

If  make install failed during parflow building, then it is very likely that this make install will also fail. Hopefully for the very same reasons. Therefore follow the steps above. However make sure you are editing the correct file. Assuming you are into pftools folder, do

$ gedit config/Makefile.config 

and make the same edits.

Rerun make install and Voila!! You just finish a local parflow installation.

5) Test

To run parflow you need to have the environmental variable PARFLOW_DIR specified. There are quite a few options about this with the simplest being every time you open a terminal run

$ export PARFLOW_DIR=${HOME}/Downloads/PARFLOW/parflow.693.

You need of course to change the path according to your preferences.

Under the  ${PARFLOW_DIR}/test directory you can run a simple example such as

$ tclsh default_single.tcl 1 1 1

or try something more complicated under ${PARFLOW_DIR}/test/washita/tcl_scripts

$ tclsh Dist_Forcings.tcl

$ tclsh LW_Test.tcl

Compilation guides

One of the most common problems for linux starters and inexperienced programmers is not only how to write a piece of code to do a certain task, but how to compile the code that is based on a particular library. Now if you intend to combine few libraries under the same program things are getting harder.

This list here provides few examples about the compilation processes of various libraries I have used in the past.

Compiling & Building c++ application with Hdf5
A guide to Compile Parflow (Ubunty only)
Compile C++ pgojects with OpenSceneGraph
Compile code based on CGAL
Compile Trilinos

 

UPDATE:

If you look into the above posts you will soon find out why I started writing about compilation.

However since I first wrote about it, things have changed a lot. To be honest, I no longer attempt to build libraries as I mention above.

Instead I use vcpkg when developing for windows and Spack when developing for linux/clusters. With both systems, building any library and their dependencies is a matter of write few lines of code. Yet, from time to time there is a need for troubleshooting but you don’t get even close to the frustration of doing everything on your own.

Git basic commands

I have been using git for a while but not to often so as to remember all the commands. The goal the following list is to have a summary of the most frequently used by me Git commands.

Upload to remote repository

The process of updating a remote repository involves the following commands

will return a list of untracked changes

(Dont forget a space between add and the dot)

will add all untracked files, while

will add only the given file

In case there are files to delete from the repo the following command does the trick

while

will submit the files that have been added so far for upload but it will not upload anything yet.

This finally will update the remote repository.


 Download from remote repository

It is always a good idea before start working on a project to check if there are updates on the remote repository

and then

This will tell whether the local repository is behind.

In that case

will update the local repository


 Exclude files

Typically files which are created as part of compile process and depend on the operating or local system as well as autosaved files should not be uploaded to the remote repository.

To avoid this one can specify rules locally in the file

.git/info/exclude

For example to ignore mex object files we can add *.mex.

There is also the .gitignore option. This is good option when only few files need to be uploaded to the remote repo. One can exclude all files and the include the sources only. See this at the end of the page for example

However the gitignore can be a bit strange in case there are multiple folders in a project and selected files from each folder need to be tracked. Lets say there is a project with 2 folders folder1 folder2 and each folder contains source code with extension *.cpp and *.hpp and other files and folders like CMakeCache.txt CMakeFiles/ etc. and we need to track only the code. The .gitignore should look like this: 


 

Resolve Conflicts


It is possible that the git push command will refuse to upload the changes. This can happen when two people A and B modify the same file. If A uploads the changes first then git will refuse to push the changes of B.

In that case the B should do the following:

First the git pull –rebase will update the local repository. However there will be some conflicts. The git status command will tell which files contain the conflicts (see more detailed description here). Then B has to edit the files and resolve the conflicts. When its done B need to add the files with git add and finally

will complete the pull and the local branch will ready for git push.


 

Find the remote URL

 

Getting help

Last but not least for every command you can get help using the flag –help e.g.