2000-09-21
boein@nsc.liu.se

Co-Array Fortran for parallel programming

John Reid, Rutherford Appleton Laboratory, UK

Seminar Wednesday 14th October 1998, 10.15 - 12:00, at the Mathematics Department, Beurling room, second floor, building B, Valla Campus, Linköping University.

The seminar was sponsored jointly by the Swedish National Supercomputer Centre and the Mathematics Department, Linköping University.


Co-Array Fortran, formerly known as F--, is a small extension of Fortran 95 for parallel processing. A Co-Array Fortran program is interpreted as if it were replicated a number of times and all copies were executed asynchronously. Each copy has its own set of data objects and is termed an image. The array syntax of Fortran 95 is extended with additional trailing subscripts in square brackets to give a clear and straightforward representation of any access to data that is spread across images.

References without square brackets are to local data, so code that can run independently is uncluttered. Only where there are square brackets, or where there is a procedure call and the procedure contains square brackets, is communication between images involved.

There are intrinsic procedures to synchronize images, return the number of images, and return the index of the current image.

The extension is both clear, powerful, and flexible.

For a full description, see R. W. Numrich and J. K Reid (1998). Co-Array Fortran for parallel programming. Report RAL-TR-1998-060. ACM Fortran Forum, Volume 17, Number 2, August 1998, pp. 1-31. Also available by ftp from matisa.cc.rl.ac.uk in /pub/reports/nrRAL98060.ps.gz.

SGI/Cray has made a subset available in CF90 3.1 (and later) for CRAY T3E systems. Compile with

	f90 -Z program.f90
Cray has a manual CF 90 Co-array Programming Manual, number 004-3908-001.

For further information see also the Co-Array Fortran home page and the article in the ARSC T3E Newsletter by John Reid.

Co-Array Fortran may require a fix which is not yet included in the standard distribution from Cray. We have now added this fix, which is in the form of a module caf_intrinsics. You may include the compiled version at your linking simply by adding the -p switch at compilation, for example

       f90  -p'/usr/local/lib' -Z program.f90
where your program must include a call call caf_init() once on each image at the start of the program and you also have to add use caf_intrinsics anywhere where sync_images is called. The module also contains some additional intrinsics, missing in the Cray implementation: sync_file, sync_memory, sync_all, sync_team, start_critical, end_critical. Some of these are used by the revised sync_images in the module. The present module was compiled with Fortran Cray CF90 Version 3.3.0.2. Its main purpose is to avoid that the execution hangs, which sometimes happens when the module is not present.

Example

A very simple example is the summation of the squares of the inverted natural numbers available in the file caf_sum.f90. In accordance with numerical analysis the summation is performed backwards for better precision. It is compiled (together with the timing function wtime.f90) with
	f90 -Z caf_sum.f90 wtime.f90
and run on one processor (image) with the command
	a.out
and on two processors (images) with the command
	mpprun -n 2 a.out
For additional processors (images) the digit 2 is replaced with the actual number. This example has perfect parallelization!

Assistance is available from Bo Einarsson.