Quick Overview of Coarrays
Coarrays are an exciting parallel programming extension for fortran. They are special variables that can be shared across multiple instances of the same program, which are called 'images'. The main advantage of coarrays is the high level of integration with the fortran language itself, making programs vastly more readable than subroutine calls to parallel libraries. Synchronization primitives are also provided.
Coarrays look vaguely like fortran arrays, except with square
brackets instead of round. The square brackets indicate a reference
to a coarray on another (or maybe the same) image. A simple coarray
declaration looks like:
INTEGER :: x[*]
This declares x to be an integer that is sharable
across images. In an expression x refers to the
x on the current image. x[1] refers to the
x on image one and so on. The *-notation is
like a fortran assumed-size array-- the bounds of the coarray are
determined at run time, not compile time.
Using a coarray variable without square brackets refers to the
local value within expressions. Using a coarray variable with square
brackets refers to the coarray variable on a particular image. On the
right side of an assignment, the value is loaded from an image. On
the left side of an assignment, the value is stored to that image.
The statement:
causes the value of x[1] = x[2]
x on image two to be loaded, then
stored to x on image one. The statement has the same
effect when executed on any image.
A simple coarray program is:
integer :: m[*]
m = THIS_IMAGE()
SYNC ALL
if (THIS_IMAGE() == 1) then
do i=1, NUM_IMAGES()
print *, i, m[i]
enddo
endif
end
The THIS_IMAGE() intrinsic returns the image number
of the current image, which is one, up to NUM_IMAGES()
which returns the total number of images in the calculation.
The SYNC ALL statement causes all images to wait
until all images have reached the SYNC ALL statement.
Once this has happened image one prints the value of m
for all other images. All other images quietly terminate.
A huge advantage that coarrays have over message passing libraries is that the programs are much more readable. Message passing libraries have to be called, and the argument lists can be lengthy and hard to read. With coarrays, the square brackets tell you that cross-image communication is taking place and language statements are used to implement synchronization instead of subroutines.
For more information on coarrays and how to use them, see John Reid's paper "Coarrays in the next Fortran Standard" and my own Coarray Compendium. The compendium is a gentle but not exhaustive introduction to coarrays. It includes some example programs.
Standards issues:
Coarrays are part of the upcoming Fortran 2008 standard. The original proposal of Numrich and Reid was recently scaled back in the draft. Many of the more advanced features were moved to a Technical Report (TR), and the core features were left in the draft.
G95 currently supports coarrays as an extension and implements the
F2008 draft of coarrays with the exception of the LOCK
and UNLOCK statements which are still being debated. The
QUERY and NOTIFY statements of the coarray
Technical Report are implemented, and the rest of the TR will
eventually be implemented as well.
If J3 chooses to delete coarrays from the standard, I will continue to support them as an extension, but as a long-time J3 observer I believe this is very unlikely. J3 has balked at several proposals to delete or scale back coarrays as they are now.
G95's support for coarrays comes in two major flavors. The first flavor involves support for running images across networks. This requires a central program, the 'G95 Coarray Console' to initialize the network and start images on the machines of the network.
The second major flavor is a version that is optimized for a single machine with multiple cores. This part is still in the design stage, but will use large chunks from the network version. This version will include a Windows port. The network version is perfectly capable of running multiple images on a multicore machine and uses shared memory where possible, but will not be as fast for certain synchronization operations.
The library modules for coarrays and coarray console are closed source shareware programs. The library object files and coarray console are free for use with five images or less. Running with more than five images requires a license, available at http://www.g95.biz.
Links
| G95 Coarray Console: x86 | HTTP | (2009-02-26 23:16) |
| G95 Coarray Console: x86-64 | HTTP | (2009-02-26 23:14) |
| G95 Coarray Console: IA64 | HTTP | (2009-02-26 23:13) |
| Coarrays in the next Fortan Standard (John Reid, N1747) | HTTP | ([an error occurred while processing this directive]) |
| Coarray Compendium | HTTP | (2008-10-29 09:54) |


