[4.7, RFC, Fortran] Coarray: Moving towards real parallelization

Tobias Burnus burnus@net-b.de
Wed Mar 2 20:34:00 GMT 2011


For gcc-patches readers: Fortran has since the 2008 version of the 
standard a build-in means of parallelization called "coarrays". That 
makes Fortran a PGAS language (PGAS = Partitioned Global Address Space); 
the C equivalent is called UPC (Unified Parallel C) but contrary to 
coarray it is not an ISO standard. (There is a certain demand by users 
to have a coarray implementation and other Fortran vendors are also 
planning to support coarrays or have already implemented it in released 
products. The latter includes Cray, Intel and g95.)


The attached patch makes the first moves towards multi-image coarray 
support. The idea is that the front end generates calls to a library. 
That library will be first implemented using MPI (Message Passing 
Interface), which brings me to a problem: How to include that library, 
which is heavily depending on the MPI installation, in GCC?

(Later it is planned to also offer a shared memory version. But first 
the library version needs to be working.)


Example usage

Compile the parallelization (wrapper) library:
    mpicc -c libgfortrancaf_mpi.c
Compile the actual program:
    mpif90 -fcoarray=lib caf.f90 libgfortrancaf_mpi.o -o caf
Run the program
   mpirun -n 10 ./caf

Attached you find a patch which adds the necessary calls for:
- Initialization and finalization
- STOP/ERROR STOP
- SYNC IMAGES, SYNC ALL and SYNC MEMORY
- this_image() and num_images()
- CRITICAL; ...; END CRITICAL block

Known limitations:
- SYNC IMAGES won't work with an array of non-c_int integers
- this_image() only works without arguments
- The library implementation is very rough and for SYNC IMAGES() is 
mostly wrong
- For CALL EXIT and CALL ABORT the parallelization library is not finalized

NOTE: All items not listed are not implemented. In particular accessing 
remote coarrays is not supported; neither is locking, atomic,  
image_index, etc.

I would like to include - at least the front-end part - in GCC as when 
the 4.7 trunk opens.

Questions:

- Could someone review the front-end patch?

- Where to place the library *.h and *.c files? How to make them 
available with "make install"?

- How to create test cases for the test suite?

- Are there other comments?

- Do we have a function which converts a rank-1 array from, let's say, 
INTEGER(1) or INTEGER(16) to INTEGER(4)? Possibly, the the packing of 
the array (if needed) and the conversion could be done in one step...

Tobias

PS: Just for the sake of it: An example program. Compare the 
-fdump-tree-original dump between -fcoarray=single and -fcoarray=lib; 
also for -fcheck=bounds.

program test_caf
   character(len=40) :: errstr
   integer:: st
   integer :: images(2) = [1,4]
   print *, 'Hello World', this_image(), num_images()
   SYNC IMAGES(images,errmsg=errstr, stat=st)
   print *, 'Sync Image stat=', st
   SYNC MEMORY
   CRITICAL
      write(*,*) 'In critical section: ',this_image()
   END CRITICAL
end program test_caf
-------------- next part --------------
A non-text attachment was scrubbed...
Name: caf.diff
Type: text/x-patch
Size: 20742 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20110302/868c6455/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: libgfortrancaf.h
Type: text/x-chdr
Size: 1908 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20110302/868c6455/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: libgfortrancaf_mpi.c
Type: text/x-csrc
Size: 4420 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20110302/868c6455/attachment-0002.bin>


More information about the Gcc-patches mailing list