Explanation of the warning: 'This argument produces a possible copy in and out to a temporary variable'

In some situations, the Fortran standard requires that actual arguments
to procedure calls be copied to and from temporary variables. Often
this occurs because a program employs array features introduced in the
Fortran 90 standardalong with procedures having traditional Fortran 77
style implicit interfaces. In particular, Fortran 77 style procedures
expect all arrays to be contiguous inmemory, but Fortran 90 permits
arrays whose elements are scattered or strided.

The copying takes time, but contiguous arrays may better use the
processor cache memory. Whether the program runs faster or slower
depends on whether one of those factors dominates the other, and that
depends on the details of the program.

Because unintended copying can slow program execution, the compiler
provides optional warnings about it. The example below shows two out of
many situations in which copying takes place: one in which copying is
conditional on the nature of the array, and another in which copying is
unconditional.

One way to minimize copying is to use explicit interfaces for all
procedures, either with "interface" blocks, or with module "use"
statements, or by nesting one procedure inside another with "contains".
Each of those methods provides the compiler with an explicit interface
from the viewpoint of the Fortran standard (and note that it is a
mistake to provide redundant interfaces: don't provide an "interface"
block for a procedure whose interface is already imported via a "use"
statement).

The compiler will also copy noncontiguous arrays to temporary
variables in some situations where the standard does not require it,
but where heuristics suggest that this will improve performance by
better using the cache. To disable this category of copying, use the
command-line option "-LANG:copyinout=off".

~> cat cico.f90
subroutine possible(a, n)
implicit none
integer :: n
integer, dimension(n) :: a
print '(a,25i5)', "possible:", a
end subroutine possible


program copier
implicit none
logical :: l
integer :: i
integer, target :: a(5,5) = reshape((/ (i, i=1,25) /), (/ 5, 5 /))
integer, pointer, dimension(:,:) :: p
read *, l
if (l) then
p => a
else
p => a(1:5:2, 1:5:2)
endif

! Because "possible" does not have an explicit interface, it expects a
! contiguous array. Therefore, the compiler generates a runtime test to check
! a "contiguous" bit belonging to the pointer "p", and if the target is not
! contiguous, the values are copied to a temporary array before the call and
! copied back after the call
call possible(p, size(p))

! The compiler must always copy this sequence array to a temporary variable
! to make it contiguous
call possible(a((/1,2,5/),(/2,3,5/)), size(a((/1,2,5/),(/2,3,5/))))

end program copier
~> pathf90 -fullwarn -c cico.f90

call possible(p, size(p))
^
pathf95-1438 pathf90: CAUTION COPIER, File = cico.f90, Line = 26, Column = 17
This argument produces a possible copy in and out to a temporary variable.

call possible(a((/1,2,5/),(/2,3,5/)), size(a((/1,2,5/),(/2,3,5/))))
^
pathf95-1438 pathf90: CAUTION COPIER, File = cico.f90, Line = 30, Column = 18
This argument produces a copy in to a temporary variable.

pathf95: PathScale(TM) Fortran Version 2.9.99 (f14) Thu Dec 7, 2006 06:03:17
pathf95: 32 source lines
pathf95: 0 Error(s), 0 Warning(s), 2 Other message(s), 0 ANSI(s)
pathf95: "explain pathf95-message number" gives more information about each message

categories [ ]