How to avoid array temporaries when calling subroutine

How to avoid array temporaries when calling subroutine

Hello,
I am using Intel(R) Fortran Compiler XE on a Linux cluster. I would like to know how to efficiently
pass slices of an array to subroutines.

Here are relevant portions of the code:

in the main program
 REAL,ALLOCATABLE,DIMENSION(:,:,:) ::  DTC
 ALLOCATE(DTC(0:MTLOC,KBM1,NCP));        DTC   = 0.0

CALL CARBON(DTC(0:MTLOC,1:KBM1,9), DTC(0:MTLOC,1:KBM1,10), DTC(0:MTLOC,1:KBM1,11),DTC(0:MTLOC,1:KBM1,12),FLUXS(0:MTLOC,1:KBM1,5))

in the subroutine

   SUBROUTINE CARBON(DTLDOC,DTRDOC,DTLPOC,DTRPOC,FLXSPOC)
   USE WQM
     
   IMPLICIT NONE
   REAL,DIMENSION(0:MTLOC,KBM1) :: DTLDOC, DTRDOC, DTLPOC, DTRPOC, FLXSPOC

calculate values for DTLDOC, etc

   RETURN
   END SUBROUTINE CARBON

integers MTLOC = 5760, KBM1 = 20, and NCP = 27 are declared in module WQM

when I received the code, the call sytax was

  CALL CARBON(DTC(0,1,9), DTC(0,1,10), DTC(0,1,11), DTC(0,1,12), FLUXS(0,1,5))

This was a bug because it only passed one element of the array. Would this syntax work on some systems
to pass all elements of the first two dimensions, and only the specified element of the third dimension?

I changed the array indices in the call as indicated above to specify the range of indices. This caused the subroutine to act on the correct
portions of the array, but array temporaries were created, which may slow down performance.  

What would be the most efficient way to pass portions of the array to the subroutines? Or, would it be as efficient to
declare the array in a module and make it available within the subroutine to act on it directly?

3 帖子 / 0 全新
最新文章
如需更全面地了解编译器优化,请参阅优化注意事项

Steve Lionel wrote an explanation of that F77 style sequence association:

http://software.intel.com/en-us/blogs/2009/03/31/doctor-fortran-in-ive-c...

It should be equivalent to your array section code, provided that MTLOC is the full size of the first rank, as you showed.

I suppose the compiler couldn't suppress the array temporary for the array section notation, unless you have set up for interprocedural optimization.  Module arrays look good if they will satisfy the requirement.

Giving the subroutine an inerface, either an implicit one by placing it in a module, or an explicit one, although I recomend the former, as well as declaring the intent of the arguments might help reduce the number of array temporaries created.

I'm not sure of the details of the algorithm, but if it's performing pointwise operations on the arrays, then an elemental subroutine might also help speed things up, but this requires that each element of the dummy arguments can be independently operated on.

-Zaak

发表评论

登录添加评论。还不是成员?立即加入