efficiency question: type versus array


Suppose I want to allocate an array of coordinate values. I could do it in two
different ways. (Let's pretend that all compilers allow allocatable components
of derived types)

Classical method:

real(8), dimension(:,:), allocatable :: coord

! ndim = Spatial dimension
! numpts = Number of points

Modern method:

type :: point
real(8), dimension(:), allocatable :: x
end type point

type(point), dimension(:), allocatable :: coord

do i = 1,numpts
end do

My question is: which one will be more efficient in terms of memory access?

This probably a FAQ, but I couldn't seem to find anything.



Ushnish Basu ubasu@xxxxxxxxxxxxxxx
+1 510 644-1906 www.ce.berkeley.edu/~ubasu

Relevant Pages

  • Re: xlf Fortran Oddity
    ... I do not believe that Allocatable Derived Type is a Fortran 90/95 construct. ... This is supported by some compilers as an F2k extension. ... When compiled with array bounds checking, ... allocate & initialize derived type ...
  • Re: allocatable array component with intent(out)
    ... Now, most of my compilers support the allocatable TR, so I'm switching these to allocatable arrays in the declarations. ... My code apparently works with pointer components, but it gives me a bus error when I use allocatable components. ... With several other compilers both calls apparently succeed. ... allocate(x(2)) ...
  • Re: how to allocate a array in subroutine
    ... I hope to allocate and initial a in subroutine inital. ... End Module testmodule ... OK - it appears x should be allocatable or a pointer, ... full fortran 2003 compilers. ...
  • Re: well formed flag ?
    ... compilers. ... "no pointer resulting from allocate is an alias to any pointer that ... M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html ...
  • Re: Proper way Variable declaration
    ... certainly not worth it. ... Compilers aren't required to allocate ... declared variables in the order of declaration anyway, ...