C/C++ and Fortran

 View Only

Argument presence enhancements

By Archive User posted Thu June 13, 2013 04:02 PM


Originally posted by: 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:

  • If you specify the f2008, xlf2008, or xlf2008_r command, the default is -qxlf2008=checkpresence. When -qxlf2008=checkpresence is in effect, dummy argument presence is checked according to the Fortran 2008 standard.
  • If you specify other invocation commands, the default is -qxlf2008=nocheckpresence. When -qxlf2008=nocheckpresence is in effect, dummy argument presence is checked according to previous Fortran standards.

Here is an example:

integer, pointer :: p1(:), p2(:)
integer, target :: t1(2)
integer, allocatable :: a1(:), a2(:)
p2 => t1
allocate (a2(1))
call sub(p1,p2,a1,a2)
subroutine sub(w,x,y,z)
integer, optional :: w(:), x(:), y(:), z(:)
! Output: with -qxlf2008=checkpresence:    F T F T
!               with -qxlf2008=nocheckpresence:  T T T T
end subroutine

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