Question on allocatable arrays in Fortran 90 
Author Message
 Question on allocatable arrays in Fortran 90

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



Sat, 19 Jul 2008 10:40:49 GMT  
 Question on allocatable arrays in Fortran 90

Quote:

> 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.

Quote:
> 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?

Quote:
> 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



Sat, 19 Jul 2008 14:13:25 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Allocatable arrays in Type definition (Fortran 90 question)

2. Allocatable Arrays in Fortran 90

3. Allocatable derived type with allocatable components in fortran 90

4. array storage question Fortran 90

5. Fortran 90/95 array questions

6. A question regarding array-valued functions in fortran 90

7. DEC Fortran 90 -> SGI Fortran 90

8. Passing arrays to subroutines in fortran 90

9. Fortran 90 Arrays and C++

10. Fortran 90 and C dynamic arrays?

11. How to select a subset of an array in Fortran 90

12. FORTRAN 90 Array

 

 
Powered by phpBB® Forum Software