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

referencing actual arguments

Ray_R_1
Beginner
3,937 Views
The 10.0.027 compiler quide quotes
"Similarly, if any part of the actual argument is defined through a dummy argument, the actual argument can only be referenced through that dummy argument during execution of the procedure. For example, if the following statements are specified:
  MODULE MOD_A
REAL :: A, B, C, D
END MODULE MOD_A

PROGRAM TEST
USE MOD_A
CALL SUB_1 (B)
...
END PROGRAM TEST

SUBROUTINE SUB_1 (F)
USE MOD_A
...
WRITE (*,*) F
END SUBROUTINE SUB_1

Variable B must not be directly referenced during the execution of SUB_1 because it is being defined through dummy argument F. However, B can be indirectly referenced through F (and directly referenced when SUB_1 completes execution)."

why then does this program work?

MODULE MOD_A
REAL :: A, B, C, D
END MODULE MOD_A

PROGRAM TEST
USE MOD_A
b=1.0
CALL SUB_1 (B)
write(*,*)B
END PROGRAM TEST

SUBROUTINE SUB_1 (F)
USE MOD_A
B=2.0
WRITE (*,*) B,F
f=3.0
END SUBROUTINE SUB_1

2.000000 2.000000
3.000000
Press any key to continue . . .
should it not give an error? I have written code like subroutine SUB_1 and I am concerned that it is incorrect, even though it seems to work. Have I been getting away with something that is wrong?



0 Kudos
22 Replies
Steven_L_Intel1
Employee
439 Views
Sorry, you are right - your example does have aliasing and that is exactly the sort of code that can cause aliasing problems. Adding the /assume:dummy_aliases switch would help with that.

In MOST cases, when you change a setting for a source file and the behavior changes, it means that there is an issue for that source file. But not always...
0 Kudos
jimdempseyatthecove
Honored Contributor III
439 Views

Jarvuslunt,

>>
Node = 5
NodeArray(3) = NodeArray(3) + 10
<<

The compiler is free to reorder statements when the code does not exhibit a temporal dependency. In the above example the first statement could occur after the 2nd statement as well as occur within the second statement.

Consider:

Node = 5
NodeArray(3) = NodeArray(3) + 10
Node = 6

The optimized code will likely not perform the Node=5 as it will assume it is non-functional.

Jim Dempsey


0 Kudos
Reply