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

call by reference/ value

qmdlm
Beginner
371 Views
Say I've got a subroutine foo(A,output) where A is dimension(:,:) and intent(in). Say output is real and intent(out).

I have a nxp matrix X and call foo(X(:,whichcols),output), where size(whichcols) < p and all elements of whichcols are positive integers <= p.

What is made available to foo? A pointer to the column subset of X ?

What is the best way to handle such calls involving submatrices? Do functions and subroutines behave in the same fashion?

Thanks.
0 Kudos
1 Reply
Jugoslav_Dujic
Valued Contributor II
371 Views
Yes, a "pointer" to column subset of X is passed to foo --(actually, it is referred to as "descriptor" or "dope vector" in this context) but its format (at least in CVF) is identical to the one of pointer arrays (see "Handling Arrays and Visual Fortran Array Descriptors" in CVF docs). That's the reason why routines with assumed-shape arguments require explicit interfaces.

Functions and subroutines behave in the same fashion. Of course, the exception is function's return value. It can get tricky to return a pointer as function's return value, so IMO it's best to stick with normal arguments.

Jugoslav
0 Kudos
Reply