Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29285 Discussions

Performance impact when using associate blocks

FlyingHermes
New Contributor I
889 Views
Hi,

I was just wondering if the use of associat blocks impacts performance when used inside large loops such as in the following piece of code:
[fortran]j=5 do i=1,100000 associate ( Var => MyType%Something(j)%Another%Var) ... end associate end do[/fortran] Thanks
0 Kudos
6 Replies
Steven_L_Intel1
Employee
889 Views
I would not expect it to affect performance.
0 Kudos
jimdempseyatthecove
Honored Contributor III
889 Views
Steve,

Can you comment on the following:
[fortran]j=5 do i=1,100000 associate ( Var => MyType%Something(j)%Another%Var) write(*,*) Var j = j + 1 write(*,*) Var ... end associate end do[/fortran] IOW is the new j used or the initial j used on the second use of Var?

The example in the documentation is not clear on this.

Jim Dempsey

0 Kudos
Steven_L_Intel1
Employee
889 Views
Jim, I agree that the standard's wording here is obscure. What it says is "Execution of an ASSOCIATE construct causes evaluation of every expression within every selector that is a variable designator and evaluation of every other selector, followed by execution of its block." This means that the value of J that exists at the time the ASSOCIATE construct is entered is what is used to evaluate the selector, and subsequent changes to J do not affect the selector.

Many people think of ASSOCIATE as a sort of macro expansion - this is one case where that is shown to be inaccurate.
0 Kudos
Izaak_Beekman
New Contributor II
889 Views
So, associate constructs are basically just static aliases for given components, right?
0 Kudos
jimdempseyatthecove
Honored Contributor III
889 Views
Thanks Steve, this clears things up.

Additional questions not covered by the documentation:

The selector can effectively map to an array or array slice (with or without stride). In some respects this resembles a pointer (in others it is a function/expression). The questions are:

Must (should)arrays being selector-ed have TARGET attribute?

If in the associate block, what happens when the selector is used in an expression in conjunction with that which the selector is associated to? IOW you effectively have multiple access paths (alias) to the same memory locations. Is this prohibited? Or recommended to avoid?

Jim
0 Kudos
Steven_L_Intel1
Employee
889 Views
You don't have to give the variable in a selector TARGET, though if it has TARGET (or POINTER) the associating entity gets TARGET. One important point is that if the selector has POINTER or ALLOCATABLE, the associating entity does NOT get these attributes.

Yes, you effectively are creating an alias here and the compiler is supposed to be aware of it. You are not prohibited from accessing the selector directly within the construct but it's not good practice.
0 Kudos
Reply