|The Leading Source for Global News and Information Covering the Ecosystem of High Productivity Computing / November 15, 2007|
I have a bumper sticker on my office door from Lahey and Fujitsu (circa Supercomputing 1999) that states in red and white letters, "Not Your Father's Fortran." If this was true then, it is even more so now with the creation of the existing Fortran 2003 standard and the proposed 2008 standard. From the trivial to the sublime (in some minds at least), Fortran 2008 adds several new features, including explicitly parallel constructs with the addition of co-arrays. This article highlights key new features in Fortran from the perspective of a programmer; what constructs am I looking to use as soon as they are made available by the compiler vendors.
Let's get the minor or seemingly trivial features out of the way first. Soon, programmers will be able to start a line in free format form with a semicolon, ";" (a semicolon terminates a statement). While this may indeed seem trivial, it was done, as with some of the other minor features, to smooth out the rough edges of Fortran and make it more internally consistent.
Minor features include the COMPILER_VERSION and COMPILER_OPTIONS inquiry functions. These functions were added to provide information about the translation phase of a program and will allow a programmer to better document the tool chain used to create an application. Additional mathematical intrinsic functions were also introduced, including the Bessel functions, error functions, the Gamma function, and generalized L2 norms.
From polls taken of the HPC community, the most important new feature in the 2003 standard was interoperability with C, not the object orientation also added in 2003. Interoperability with C is in many of the major Fortran compilers and will soon appear in the next release of GNU Fortran. It allows one to define Fortran interfaces that are callable from either Fortran or C. It is bi-directional in that the implementation of an interface can be in either Fortran or C, and callable for either Fortran or C. Now is an appropriate time for anyone interested in distributing software to the scientific community to consider writing interfaces adhering to this standard, thus expanding their user base by providing access to both C and Fortran programmers.
The 2003 standard was a major revision of the language and 2008 was meant to be an interim standard, basically filling in the gaps left over from 2003. However, the WG5 and J3 Fortran standards bodies realized that as parallel computation becomes more ubiquitous and with multi-core processors on the horizon, something was needed to address parallelism.
Thus co-arrays were introduced, allowing a programmer to directly read or write to memory on a remote processor using the square bracket "" notation. Co-arrays add a new dimension to the normal array dimensions, referred to as the co-dimension. The statement,
A(:) = A(:)
informs the program to copy all of co-array A on image 2 to co-array A located on image 1 (an image in Fortran terminology is similar to processor rank in MPI). As the co-array model is that of a single program executing concurrently on several communicating processes (the SPMD model), it is the programmers responsibility to explicitly guard against concurrent access to the same memory address, for example by writing:
IF (THIS_IMAGE() == 1) A(:) = A(:)
Otherwise, all of the images in the program would attempt to concurrently copy data in co-array A from image 2 to image 1.
Co-arrays also provide for barrier synchronization with a subset of program images with the SYNC TEAM or SYNC IMAGES statements or with all of the images via the SYNC ALL statement. A common programming pattern in Fortran will be to perform a SYNC ALL to ensure that a co-array is ready to be either read from or written to, followed by the transmission of data using the square bracket notation, and completed with an additional SYNC ALL to ensure that the transmission phase is finished and that data is ready for local use again.
A CRITICAL ... END CRITICAL construct was provided to limit the execution of a block of code to a single image at a time. In addition, the maximum total number of array dimensions was increased from 7 to 15 to allow for the addition of the co-dimension.
A DO CONCURRENT ... END DO loop construct was added to increase avenues for on-node parallelism through implicit threading. This allows the programmer to explicitly inform the program that individual iterations of the loop body may be executed concurrently in any order. For example, if there are no repeated values in the index array, indices, the programmer could write:
DO CONCURRENT (i = 1:n)
A(indices(i)) = i
The DO CONCURRENT construct makes it easier for the compiler to generate vector gather/scatter code or parallelize loops, thus potentially improving performance.
A BLOCK ... END BLOCK construct was added to allow one to declare variables within the body of a program and not just at the beginning of a program or procedure. For example:
ocean : BLOCK
real :: global, warming, ...
END BLOCK ocean
Perhaps the most convenient new feature in 2008 allows the compiler to select and return an IO unit number when a file is opened with the OPEN statement. No longer will programmers be forced to ensure that the unit number chosen does not conflict with a unit number already in use.
What's left for a future new standard? Co-arrays, while a step forward, only provide a local view of distributed arrays and are little more than syntactic sugar for MPI. New HPCS languages like Chapel from Cray and X10 from IBM provide a global view of arrays and thus a higher level of abstraction. In my opinion, in the future Fortran should look at ways to introduce some of the work being done in Chapel and X10. In particular, we should allow for multiple tasks (e.g., Ocean and Atmosphere) to run concurrently and should provide mechanisms for individual threads and data to be placed on particular hardware units, not just the one program SPMD model adopted by co-arrays.
But more importantly, what does the HPCwire community think? The Fortran 2008 standard will soon enter a public comment phase and it is critical for informed parties to examine the proposed standard and make suggestions. Please contribute to the future success of Fortran by so doing. Visit http://j3-fortran.org/ for further announcements and working documents.
Craig E. Rasmussen, Ph.D, is a staff member of the Advanced Computing Laboratory (ACL) at Los Alamos National Laboratory. He has an extensive publication record in space plasma physics, medical physics, and computational and computer sciences. His current research interests include studying ways in which computer languages and programming environments can improve productivity in scientific computing. As a member of the Common Component Architecture (CCA) forum, he has worked to make component technology easier to use by developing the Dune CCA/Python framework and experimenting with it as a rapid prototyping environment for scientific computing. As a member of the J3 Fortran standards body, he has worked on the Fortran Bind(C) interoperability standard and on other ways to improve the parallel expressiveness and performance of the Fortran language. He is currently leading an effort to develop a Fortran source-to-source compiler for the Cell/B.E. processor.