Unit-Tests with Fortran using pFUnit (supports MPI)

Real world example

A friend of mine is meteorologist and wrote a radiative transfer model in fortran and finally we integrated pfUnit into cmake (autoinstall!) and he wrote some first tests.

Have a look here for the code:

https://github.com/tenstream/tenstream

(outdated) Setting up pfUnit

This tutorial is a bit outdated and not too useful, better just have a look at the realworld example above. It even contains cmake code to download and build pfUnit!

Minimum requirements

The current master can only be built using unreleased gcc versions (4.8.3, or 4.9). The recommended solution is to use pfunit 2.1.x , which I will do in this tutorial.

I used gcc 4.8.1.

Getting the framework

git clone git://pfunit.git.sourceforge.net/gitroot/pfunit/pfunit pFUnit
git checkout origin/pfunit_2.1.0

Building and testing pfUnit

make tests MPI=YES
make install INSTALL_DIR=/opt/pfunit

Testing if the setup and installation succeeded

In the git main directory do:

cd Examples/MPI_Halo
export PFUNIT=/opt/pfunit
export MPIF90=mpif90
make
make -C /somepath/pFUnit/Examples/MPI_Halo/src SUT
make[1]: Entering directory `/somepath/pFUnit/Examples/MPI_Halo/src'
make[1]: Nothing to be done for `SUT'.
make[1]: Leaving directory `/somepath/pFUnit/Examples/MPI_Halo/src'
make -C /somepath/pFUnit/Examples/MPI_Halo/tests tests
make[1]: Entering directory `/somepath/pFUnit/Examples/MPI_Halo/tests'
make[1]: Nothing to be done for `tests'.
make[1]: Leaving directory `/somepath/pFUnit/Examples/MPI_Halo/tests'
mpif90 -o tests.x -I/home/jonas/data/programs/pfunit/mod -I/home/jonas/data/programs/pfunit/include -Itests /home/jonas/data/programs/pfunit/include/driver.F90 /somepath/pFUnit/Examples/MPI_Halo/tests/*.o /somepath/pFUnit/Examples/MPI_Halo/src/*.o -L/home/jonas/data/programs/pfunit/lib -lpfunit -DUSE_MPI 
mpirun -np 4 ./tests.x
.......F...F
Time:         0.002 seconds
  
 Failure in: testBrokenHalo[npes=3]
   Location: []
Intentional broken test. (PE=0)
  
 Failure in: testBrokenHalo[npes=3]
   Location: []
Intentional broken test. (PE=2)
  
 Failure in: fails[npes=3]
   Location: [beforeAfter.pf:33]
intentionally failing test expected: <0> but found: <3> (PE=0)
  
 Failure in: fails[npes=3]
   Location: [beforeAfter.pf:33]
intentionally failing test expected: <0> but found: <2> (PE=1)
  
 Failure in: fails[npes=3]
   Location: [beforeAfter.pf:33]
intentionally failing test expected: <0> but found: <1> (PE=2)
  
 FAILURES!!!
Tests run: 10, Failures: 2, Errors: 0

The output should look like the one above. There are errors in the written tests, but intentionally. If there are compiling errors, go fix them.

More Examples

More examples can be found in the Examples Directory. The examples are all nice and small and self explainatory.

Common errors

Sometimes if you forget to export the compilervariable:

export F90=gfortran
export MPIF90=mpif90

You will receive these errors:

...
make[1]: c: Command not found
...
make[1]: o: Command not found
...
pixelstats trackingpixel

Leave a comment

Your comment

Time limit is exhausted. Please reload the CAPTCHA.