Michael Kirkpatrick wrote:
>
> Hello,
>
> I'm new to this discussion group, so while I have read a lot of previous
> corrospondence, I'm not sure whether these questions have come up before.
>
> I'm writing a computational fluid dynamics code and use a lot of temporary
> storage arrays. In general I use 3D arrays which are the same same size as
> the computational grid, but in some subroutines involving tensor
> quantities, I also need a fourth dimension.
>
> In its present state, my code declares and then allocates and deallocates
> these temporary storage arrays within subroutines as they are required. I
> have done some profiling using the Lahey F90 compiler, and, contrary to my
> expectations, array allocation is very quick in comparison to other array
> operations.
>
> So, my first question is whether this sounds like a reasonable way to
> tackle the problem, or is there some other method which is recommended. I
> have tried using pointers to reference chunks of a huge 4D storage array
> allocated at the beginning of the program and found it fraught with
> problems, and considerably slower.
Seems reasonable, especially if the arrays are large and/or you do lots
of
things to them between allocates and reallocates. Things might change
on a farm of multi-processors where you effectively reduce the ammount
of computation you do between allocations.
>
> Secondly, I would also like to check that declaring and allocating dynamic
> arrays in subroutines is strictly legal. A colleague says he has had a
> problem with the Lahey F95 compiler when he does this. I would have
> thought, this would defeat the purpose of dynamic arrays?
>
Yes, this is perfectly legal provided that the arrays are local to the
subroutine (or are used from a module). Fortran 90 and 95 do NOT allow
you to allocate or deallocate a dummy argument.
> Finally, for clarity, I sometimes use pointers to alias dynamic storage
> arrays which are used sequentially for a number of different variables
> within a given subroutine. From the profiling I have done using the Lahey
> F90 compiler, this appears to > double the time taken for operations. Is
> this likely to improve in the future, or with other compilers?
> Alternatively I could deallocate and reallocate these arrays each time I
> want to use it for a different variable as I have been doing between
> sections of the code as I described above or possible use the dreaded
> EQUIVALENCE statement?
Hard to say if it will improve, I'd guess not. The problem is that
Fortran 90 pointers are moderately undisciplined and the compiler can't
be sure that two different pointers don't point to the same thing. This
means that there will be unnecessary loads and stores and that common
subexpressions won't always be recognized. Also, because pointers can
have strides (as well as upper and lower bounds) compilers are less
likely to recognize common subexpressions in index calculations. Also,
because the compiler might not recognize that adjacent array operation
lines have the same bounds and ranges they might not fuse adjacent loops
to save on loop and index computation overhead. As a rule of thumb,
use pointers to process linked lists, use allocatable to process arrays.
(Not everyone agrees with that rule and there are exceptions.) In
theory, for relatively simple pointer uses, (the kind that could be
easily replaced with straight forward allocate/deallocates) the compiler
could do enough analysis to deduce that the pointers are unambiguous and
all have the same shapes and strides. But, it's not something that I
would count on.
Dick Hendrickson
>
> To put all this in context, at present I do most of my development on a PC
> but I intend for the final product to be run using Digital HPF on a small
> farm of parallel computers.
>
> Cheers
> Michael
>
> Michael Kirkpatrick
>
> Department of Mechanical Engineering
> The University of Sydney
> Sydney, NSW, 2006
> Australia
>
> Tel: +61 2 9351 4064
> Fax: +61 2 9351 7060
> Email: [log in to unmask]
>
> :)><
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|