- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
Link Copied
6 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I would not expect it to affect performance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Many people think of ASSOCIATE as a sort of macro expansion - this is one case where that is shown to be inaccurate.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
So, associate constructs are basically just static aliases for given components, right?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page