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

Expression and temporary array

abhimodak
New Contributor I
256 Views
Hi

The snippet below passes the expression (A) and the actual array A. Thus, there is no argument aliasing involved. As I understand, (i) the expression references A, (ii) is evaluated completely before invoking the subroutine, and (iii) changes to A won't affect the expression.

Although I am using assumed-shape array in subroutine Method, I am wondering where is the expression stored? i.e. is there something going on stack? I don't see the array temporary being created message when I use /check:arg_temp_created flag.

Abhi

----

Module OM
Implicit None
Contains
Subroutine Method(n, A, m, B)
Integer, Intent(IN) :: n
Real, Intent(IN) :: A(:)
Integer, Intent(OUT) :: m
Real, Intent(OUT) :: B(:)
!Real :: A(:), B(:)

m = 2*n
B = 3*A
End Subroutine Method
End Module OM

Program Test_ExpressionArgument
Use OM
Implicit None
Integer :: n = 2, m
Real :: A(5) = -1.0
Real :: c

Call Method(n, (A), m, A)
Print *, A
End Program Test_ExpressionArgument
0 Kudos
3 Replies
Steven_L_Intel1
Employee
256 Views
It is creating a stack temp. You don't get the warning when you have explicitly asked for an expression.
0 Kudos
abhimodak
New Contributor I
256 Views
Thanks Steve. I guess then if the array size is large, one may get stack overflow error. Is the /heap-arrays only way to avoid it?

Also, I get a warning when I use assumed-sized arrays, I believe that is correct behavior. Is that right?

Abhi
0 Kudos
Steven_L_Intel1
Employee
256 Views
Yes. If you are forcing a copy to be made, it has to go somewhere.

What warning for assumed-size arrays?
0 Kudos
Reply