Time really flies! About six years ago, the Fortran 2003 standard (commonly abbreviated as F03) was officially published in an attempt to modernize the language. Over the past few years, we've seen a steady increase of interest in adoption of F03 features in the field, particularly the object-oriented programming (OOP) and C interoperability features. F03's C interoperability features struck a chord in the scientific computation community as mixed language applications are becoming the mainstream. In addition, more and more scientific and engineering programmers realize the power of OOP. We're happy to note there are actual scientific and engineering applications being developed using OOP features of F03. On the vendor side, the initial attitude to OOP was generally lukewarm. However as demand continued to grow, vendors eventually accelerated their implementations in recent years. At this very moment, there are two compilers fully compliant with the Fortran 2003 standard and a number of others that are very close to be fully complaint, according to the latest compiler survey conducted by Fortran Forum.
While there are growing activities on the F03 front, we also see some exciting work in further modernization of the language. Right after the publication of F03, the Fortran committee (WG5/J3) started working on the next revision. The content of the revision was frozen in 2008, resulting in a name of "Fortran 2008" for the upcoming new standard. The F08 standard integrated the existing submodule TR, which facilitates the separation of (module) procedure declarations and implementations. F08 also adds a few other features, e.g, BLOCK construct is added to limit the scopes of variables; CONTIGUOUS attribute is added to pointer or assumed-shape arrays, thus enabling compiler optimizations on accessing these arrays. But the most significant inclusion in F08 is the coarray feature, which brings the Fortran language to a new level. Fortran 2008 is a truly parallel programming language. An overview of the coarray feature in F08 by John Reid can be found at the WG5 web site.
The Fortran 2008 standard was finally published on Oct. 6, 2010, after some initial delay. You can purchase it from the ISO website. If you don't want to pay CHF 338,00. You can go to the J3 site to get the final draft that is very close to the official standard.
We will talk more about new F08 features and what's coming up after F08 in the upcoming months ... stay tuned.
XL Fortran V14.1 supports the Fortran 2008 enhancements to the ALLOCATE statement.
The first enhancement has to do with the SOURCE= specifier. In Fortran 2003, you are not allowed to omit the bounds information when allocating an array in the ALLOCATE statement. In Fortran 2008, when you use an ALLOCATE statement without specifying the bounds for an array, the bounds of source_expr in the SOURCE= specifier determine the bounds of the array.
The second enhancement is the addition of the MOLD= specifier. The MOLD= specifier works almost in the same way as SOURCE=. Like SOURCE=, MOLD= causes the object to be allocated to have the same type and type parameters as the source_expr specified in the MOLD= specifier. Similarly, if you don't specify the bounds for an array in the ALLOCATE statement, the bounds of source_expr in the MOLD= specifier determine the bounds of the array. Unlike SOURCE=, MOLD= does not copy the value of source_expr to the variable to be allocated. Because no copying takes place, if source_expr in MOLD= is a variable, its value need not be defined.
In the same ALLOCATE statement, you can specify only one of SOURCE= or MOLD=.
For more information about the updates, visit ALLOCATE.
Authors: Rafik Zurob, Yvonne Ma
When the compiler knows that an array occupies a contiguous block of memory, it can perform optimizations based on memory layout. Explicit shape arrays, assumed-size arrays and allocatable arrays occupy contiguous blocks of memory. For array pointers and assumed shape arrays, the compiler cannot determine at compile time if it is the case.
In the latest AIX XL Fortran compiler,
When these assertions are made, the compiler can perform more optimizations. But if any of the array pointers or assumed shape arrays in the code are not associated with a contiguous array,
Fortran 2008 introduces a new attribute:
XL Fortran supports implied-shape arrays. An implied-shape array is a named constant that inherits its shape from the constant expression in its declaration.
In the following example, array imp is an implied-shape array. Its declaration contains an implied-shape specification and a constant expression which is an array. Array imp is a rank-one array and its upper bound is 2.
INTEGER, PARAMETER :: imp(0:*) = [0, 1, 2]
For more information about this Fortran 2008 feature, visit Implied-shape arrays (Fortran 2008).
Authors: Yvonne Ma, Rafik Zurob
The Fortran 2008 standard relaxes some rules for internal procedures. Procedure pointers can now point to internal procedures. In addition, you can use internal procedures and pointers to internal procedures as actual arguments. Because an internal procedure has access to the variables of its host procedure, procedure pointers to an internal procedure can only be used before the host procedure completes its execution.
Here is an example of a procedure pointer to an internal procedure:
num_prints = 0
In this contrived example, subroutine work uses procedure pointer iprinter to do its printing. Subroutine sub takes advantage of this to count the number of integers printed by work. The program output is:
Note that calling work after sub has completed its execution is invalid. Module variable iprinter is associated with myprint which accesses host variable num_prints. After sub completes its execution, its stack is freed, including the storage for num_prints.
Support for this Fortran 2008 feature is available in XL Fortran, starting with version 14.1.
Authors: Rafik Zurob, Yvonne Ma
The Fortran 2008 standard has the following exception to argument presence:
A dummy argument or an entity that is host associated with a dummy argument is not present if the dummy argument does not have the ALLOCATABLE or POINTER attribute, and corresponds to an actual argument that has the ALLOCATABLE attribute and is not allocated, or has the POINTER attribute and is disassociated.
In XL Fortran, V14.1, the -qxlf2008=checkpresence option is added so users can detect actual argument presence correctly. The default of the option depends on your invocation command:
Here is an example:
integer, pointer :: p1(:), p2(:)
When -qxlf2008=checkpresence is in effect, the performance of your program is inhibited because of runtime checks for the allocation and association status of actual arguments. To avoid these performance impacts, consider using -qxlf2008=nocheckpresence.
For more information, visit -qxlf2008.
Coauthors: Yvonne Ma, Rafik Zurob
In Fortran 2003, users can declare only one type-bound procedure in each type-bound procedure statement. Fortran 2008 allows derived type definitions to contain multiple type-bound procedures in a single type-bound procedure statement. XL Fortran V14.1 supports this feature.
Here is an example. For more information about the feature, visit Syntax for a specific binding.
In the above example, the declaration of type point_2003 conforms to Fortran 2003 and above. It is accepted by Fortran 2003 compilers, such as XL Fortran 13.1, as well as Fortran 2008 compilers. The declaration of type point_2008, on the other hand, conforms to Fortran 2008, and is only accepted by XL Fortran 14.1 and above.
Authors: Rafik Zurob, Yvonne Ma