- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is passing a contiguous array section of an allocatable array to a subroutine where the corresponding dummy argument is an explicit shape array efficient? In other words, is a temporary array created?
Consider the following example:
PROGRAM PROG
INTEGER(4) N,P
REAL(8),ALLOCATABLE :: M(:,:)
! Allocate and initialize M(N,P)
CALL SUB(M(:,1),N)
END PROGRAM PROG
SUBROUTINE SUB(A,SIZE)
INTEGER(4) SIZE
REAL(8) A(SIZE)
! Do some work here...
END SUBROUTINE
Is this efficient? Is the array passed by address or by value in SUB (in the later case a copy of the array section would need to be done I suppose).
How does the compiler recognize that the data (the array section) is contiguous?
Thanks,
Olivier
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Olivier,
Consider using
CALL SUB(M(:,1), size(M(:,1)))
This reduces potential for error in the event the allocation is changed without changing N.
The is nothing wrong with using the N as you had before...
as long as the N isn't reused with different values for different arrays.
The above syntax should be within a few memory cycles of using N.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you Jim and Steve for your help. I found the run-time check solution proposed by Steve a very valuable tool.
Olivier

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page