For Programmers: Free Programming Magazines  


Home > Archive > Fortran > January 2006 > Question on allocatable arrays in Fortran 90









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Question on allocatable arrays in Fortran 90
Shi Jin

2006-01-30, 9:57 pm

Hi there,
Is the allocatable arrays in Fortran 90 always continuous in memory?
I recently had some problem with this.
I allocated a 4-dimensional array, say top(N,N,N,3).
When I use it in my code, e.g. call myfunc(top), this call takes a long time to finish
+while timing inside this subroutine shows that it should finish very fast. Then I figured
+out that the top array does NOT seem to be continuous and was somehow copied first to a
+continuous array and then the function was called.

If I declare a regular variable of the same size, the timing will be much smaller.
Here I have two pieces of codes:
code1:real,allocatable::top(:,:,:,:)
allocate(top(N,N,N,3))
call myfunc(top)
code2:real,allocatable::top(:,:,:,:)
allocate(top(N,N,N,3))
real::newtop(N,N,N,3)
newtop=top
call myfunc(newtop)
These two codes use almost the same amount of time.
And while in code2, most of the time is spent in the copying: newtop=top

Anyone has any idea what is going on here?
Thanks a lot.
Shi
Richard Maine

2006-01-31, 4:08 am

Shi Jin <jinzishuai@hotmail.com> wrote:

> Is the allocatable arrays in Fortran 90 always continuous in memory?


In essense, yes. The standard doesn't say so in quite those terms, but
there are requirements that pretty much demand it in practice.

> Then I figured +out that the top array does NOT seem to be continuous and
> was somehow copied first to a +continuous array and then the function was
> called.


How did you "figure this out?" You are giving us your conclusions
instead of the raw data. I don't see enough actual data to comment
intelligently. In particular.

Is the subroutine called absolutely identical in both cases, or is there
a difference that you thought was unimportant, so you didn't mention?

How did you time this and determine what times the various parts took?
Is there a chance that your timing includes the time of the allocate
itself?

> code2:real,allocatable::top(:,:,:,:)
> allocate(top(N,N,N,3))
> real::newtop(N,N,N,3)
> newtop=top
> call myfunc(newtop)


This is "obviously" not actual code because you have an executable
statement between the two declarations. This makes me wonder what other
parts of the actual code you thought were unimportant and therefore
didn't show us.

It is often the case that when someone asks for debugging help, the
problem lies in the part of the code that they didn't think was
relevant, and thus didn't show.

--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com