Extremely slow ALLOCATABLE array

robert.funnellNOSPAM_at_NOSPAMmcgill.ca
Date: 11/28/04


Date: Sun, 28 Nov 2004 18:39:17 GMT

I have a case in which use of an ALLOCATABLE array is much much slower
than using a static array. The following is a small test programme
that demonstrates the problem:

      IMPLICIT NONE
      INTEGER, PARAMETER :: NN=860
      INTEGER, PARAMETER :: NPLANES=1
      INTEGER, PARAMETER :: NPIXH=NN
      INTEGER, PARAMETER :: NPIXV=NN
      INTEGER, PARAMETER :: NSLICE=NN
      INTEGER IROW,ICOL,ISLICE,IPLANE,ISTATUS
      INTEGER(1),ALLOCATABLE :: STACK_XZ(:,:,:,:)
C
      INTEGER(1) :: PIX_XZ(NPLANES,NPIXH,NSLICE)
C
c INTEGER(1),ALLOCATABLE :: PIX_XZ(:,:,:)
c ALLOCATE(PIX_XZ(NPLANES,NPIXH,NSLICE),STAT=ISTATUS)
c IF(ISTATUS.NE.0) STOP 1
C
      ALLOCATE(STACK_XZ(NPLANES,NPIXH,NSLICE,NPIXV),STAT=ISTATUS)
        IF(ISTATUS.NE.0) STOP 2
C
      OPEN(UNIT=0,CARRIAGECONTROL='FORTRAN')
C
      WRITE(0,'('' Copying'',I5,'' images''/X)') NPIXV
      DO IROW=1,NPIXV
        IF(MOD(IROW,10).EQ.0) WRITE(0,'(''+'',I5)') IROW
c PIX_XZ=STACK_XZ(:,:,:,IROW)
        DO ISLICE=1,NSLICE
          DO ICOL=1,NPIXH
            DO IPLANE=1,NPLANES
              PIX_XZ(IPLANE,ICOL,ISLICE)=
     * STACK_XZ(IPLANE,ICOL,ISLICE,IROW)
            END DO
          END DO
        END DO
      END DO
C
      STOP
C
      END

In the form shown here, with a static array, the run time is too short
to measure with a watch; if I comment out the static declaration of
PIX_XZ and uncomment the ALLOCATABLE declaration and its ALLOCATE, the
run time is ~13 seconds. This is on an Alpha with 768 MB using Compaq
Fortran V1.2.0 under Linux.

On an Intel laptop with 512 MB and CVF 6.6.C, the allocatable version
gets to row 550 out of 860 in about half a second then takes over 30
seconds to get to 860, paging heavily; the static version finishes in
much less than half a second. The results are about the same if I use
the commented line PIX_XZ=STACK_XZ(:,:,:,IROW) rather than the
explicit DO loops.

I don't understand why the allocatable array should be so much slower.
Can anyone offer insight? Is this something that would be fixed if I
updated my compilers?

This may be a FAQ, in which case I apologise, but I haven't found the
answer anywhere, and what I'm observing seems to be more extreme than
what I've seen described. The original context is handling CT-scan
data with up to 1024 slices, each being 1024x1024.

- Robert



Relevant Pages

  • Re: allocatable result of a function
    ... > Is there a TR allowing a function to return an allocatable array? ... because ivec has not been allocated. ... One way to get the behaviour you desire is to change alloc() to a ... allocate ) ...
    (comp.lang.fortran)
  • Re: Passing allocatable arrays into subroutine outside argument list
    ... > called by a IMSL optimization routine. ... I also can't specify the allocatable array in a COMMON ... also involving an IMSL subroutine. ... subroutine that calls the IMSL routine to allocate and deallocate the ...
    (sci.math.num-analysis)
  • Re: can an allocatable array be really dynamic?
    ... array work like a linklist to allocate a node when needed? ... The Fortran 2003 standard includes an intrinsic which allows for adding to an existing allocatable array without erasing the existing data. ... subroutine allocate_expandable ... Also, since a%data is a pointer rather than an allocatable, you probably also want a deallocate_expandable subroutine. ...
    (comp.lang.fortran)
  • Re: Read dynamic string
    ... >I use this code to read dynamic string: ... s1 is an uninitialized pointer; ... how much you allocate, the user might enter something larger. ... >The problem is not present if I use a static array. ...
    (comp.lang.c)
  • Re: Fortran memory allocation (stack/heap) issues
    ... systems allocating a static array of 100K bytes. ... how much space was allocate to them and the offset. ... map and compile map to see what was there. ...
    (comp.lang.fortran)