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

INTENT(IN) overhead with derived types

Andrew_Smith
Valued Contributor I
560 Views
If we have a dummy derived type with intent in, does the caller pass a copy of the whole data structure to ensure no data is changed by the callee or do you rely on the compiler to check for assignments?

I am wondering if we would get better performance if we avoided INTENT(IN) for derived types.
0 Kudos
1 Solution
Steven_L_Intel1
Employee
560 Views
INTENT(IN) does not change how an argument is passed.

Derived types can be passed by value, and a copy is therefore made, but that doesn't seem to be the issue here.

View solution in original post

0 Kudos
4 Replies
TimP
Honored Contributor III
560 Views
Quoting - Andrew Smith
If we have a dummy derived type with intent in, does the caller pass a copy of the whole data structure to ensure no data is changed by the callee or do you rely on the compiler to check for assignments?

I am wondering if we would get better performance if we avoided INTENT(IN) for derived types.
/check:arg_temp_created should tell you whether a copy is in use. This would not depend on what is done on the callee side, only on the context in the caller. If anything, looking at the callee by interprocedural optimization (-Qip) might help the compiler avoid a copy.
If this doesn't help, please give a working example.
0 Kudos
Jugoslav_Dujic
Valued Contributor II
560 Views
Quoting - Andrew Smith
If we have a dummy derived type with intent in, does the caller pass a copy of the whole data structure to ensure no data is changed by the callee or do you rely on the compiler to check for assignments?

I am wondering if we would get better performance if we avoided INTENT(IN) for derived types.

It does not make a copy; it relies solely on the compiler check. It is akin to C++ const-by-reference argument. Thus, you can actually modify an INTENT(IN) argument, by means of cheating.
0 Kudos
jimdempseyatthecove
Honored Contributor III
560 Views

Fortran is pass by reference. A reference (pointer) to the derived type will be passed regardless of INTENT.
The compiler will, within the subroutine/function, assure use conformes with INTENT.

The IVF help does not state what happens with combination of VALUE and derived type. It states:
"Character values, substrings, assumed-size arrays, and adjustable arrays cannot be passed by value."
This said, a derived type is of arbitrary size, but the convention for VALUE of derived type might permit pass of temporary copy of derived type. The documentation is not clear on this issue.

Jim Dempsey


0 Kudos
Steven_L_Intel1
Employee
561 Views
INTENT(IN) does not change how an argument is passed.

Derived types can be passed by value, and a copy is therefore made, but that doesn't seem to be the issue here.
0 Kudos
Reply