Updates 1/8/98

Makefile rewritten. Compiled and tested on Hitachi SR2201. Fortran modules for defining f90 derived types as MPI types are automatically generated. Auto allocating scatterv, and vectorv have been written. All constants as well as functions now have the prefix 'fmpi_'. mpif.h is now directly included so library should work with all implementations of MPI. Great care needs to be taken with non-blocking functions in Fortran 90 since the correct result depends on specific details of the compilers implementation. To get these to work correctly on the SR2201 it is necessary to pass only the first element of an array. That is in the library MPI functions for non-blocking routines are called with argument list 'buf(1),size(buf)' instead of 'buf,size(buf)'. This works on LINUX with NAG f90 and MPICH, and on the SR2201 but may not work on other systems. There is no way to guarantee the behavior of non-blocking calls in f90 (that I have found) and these should be tested on each platform by running the test programs with 'make test'.

A f90 MPI interface

Fortran 90 is a powerful language that is very suitable for coding scientific problems. Native multi-dimensional array handling make programs compact and also enable compilers to spot many errors. The more restrictive nature of Fortran 90 (as compared to C) for example also enable compilers to perform more effective optimizations.

There is no native F90 binding available for MPI however. Due to the nature of Fortran 90 this would require an MPI Fortran compiler. Michael Hennecke has written a good paper about the issues involved Documentation and made an interface available Software This is interface provides type checking for arguments and conceals from the compiler that it is linking to the same functions with different arguments. It does not however make use of any of the convenient features of Fortran 90.

I have built an Fortran 90 MPI interface with the following features:

MPI types. Communicators, errors, groups, tags, requests, data types, operations, errhandler and addresses have all been defined as derived types in the MPI_typedefs module. This enables compiler type checking and reduces the chance of errors. The following operators are also overloaded. Tags and requests can be tested for equality or inequality. Integers can be added to and from addresses to give addresses. Addresses can be subtracted to give integers. These operations are defined for combinations of scalars and rank(1) arrays.

Optional arguments. All inessential arguments have become optional. Error arguments, communicator arguments, status arguments and root argument have become optional. Optional arguments have been to the end of the arguments. A status argument always comes before a communicator argument.

unnecessary arguments have been removed. Since Fortran arrays have there own size counts are no longer needed as arguments except in 'vector' functions such as MPI_gatherv. Data types are never given since the compiler automatically invokes the correct overloaded functions which calls the MPI function with the appropriate data type.

Derived types. Derived types can easily be added by linking a f90 definition module and a the necessary MPI type definition commands are then automatically generated and linked. These can also be defined manually if required. The Makefile will then automatically generate the necessary interface functions so that derived types can be used transparently in user program identically to MPI intrinsic types.

Testing functions. Various automatic tests of the interface can be performed. These programs provide an example of how to use the interface as well as validating it. Some are based on the contributed Fortran programs from MPICH. Using Fortran 90 syntax and this interface most programs become four or five times smaller and much easier to understand. I am fairly confident that point to point and collective communication work fine. I have not tested most of the communicator, topology and group stuff.

Normal MPI functions still accessible. All the MPI functions in the Fortran f90 interface have had there 'MPI_' prefix changed to 'FMPI_' so that all the standard MPI functions can be used if desired.

Strings. Interfaces have been defined for strings (character(len=*) types).

Efficiency. In theory an optimizing compiler that can inline code should eliminate the interface entirely producing a program the same as if it had had every MPI call written out in full.

I'll be developing this actively over the next few months. Any problems I'll try and fix quickly. Any suggestions or queries are welcome. You can do whatever you like with the software but I'll be grateful if you let me know if you're using it.

Here is the software. Unzip it untar it (it creates a directory called "f90_mpi_interface". Change to this directory and type 'make' to make the interface. Type 'make test' to run a series of test programs. If there are no problems it will print a load of informational messages about the tests and then 'Tests all passed'. If there are any problems it will stop with some error messages. Let me know how you get on.

Jim McElwaine
Last modified: Thu Oct 18 17:45:55 BST 2001