Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29277 Discussions

Passing an array section to a subroutine

intelgg
Beginner
631 Views
I have a real (8) array A(0:m,0:n,0:p) where
m, n and p are positive integers.
I also have a subroutine or function f(x) where
x is a real(8) array x(0:m,0:p).
I need to call f(A(0:m,i,0:p)) where i
is an integer between 0 and n.
When m and p are large, the program crashes.
Are there other ways to let f knows that what
goes into array x is the section
A(0:m,i,0:p) of array A?
0 Kudos
3 Replies
TimP
Honored Contributor III
631 Views
You are asking your program to allocate an (m+1) by (p+1) matrix at run time. Are you allowing for the necessary stack space (if on Windows, /link /stack:nnnnnnn ) ? You could declare this array yourself and assign the section to it, then pass the array to the subroutine.
0 Kudos
intelgg
Beginner
631 Views
I actually have declared the array x
inside subroutine f.
Is there a way to just pass the address of
the array (as in the C language) so that
the program does not have to haul large
chunks of data?
0 Kudos
Steven_L_Intel1
Employee
631 Views
If I am reading your description correctly, the array section you are trying to pass is not contiguous, so just passing the address wouldn't do what you want. If you don't want the compiler to generate a contiguous copy of the section and pass that, you could declare the argument in the called routine as (:,:,:) and supply an explicit interface. Note that this would be a rank 3 array, though the second rank would be 1:1. You'd have to adjust the code for that.

Steve
0 Kudos
Reply