Associate block performance

Associate block performance

I was just wondering how does the compiler treat associate block when the associate-name "points" to a function results as in:

  associate( Var1 => This%Fun1(a,b) )

	    Var2        =       This%Fun2(c,d,Var1)

	  end associate

My 2 questions are

  1. Does the compiler treats this by simply replacing the associated name (here "Var1") by the selector (here "This%Fun1(a,b)") inside the associated block ? If so, can associate blocks be seen as a sort of inlining for variable instead of procedures.
  2. Does associate blocks really  have no effect on performance ?

Thanks.

4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

I think the real question to ask is with this code:


	type(someType), pointer :: This

	...

	associate( Var1 => This%Fun1(a,b) )

	...

	This => That

	Var2 = This%Fun2(c,d,Var1)

	end associate

	

What value for "This" does Var1 use? Prior "This" or subsequent (current) "This"?

Jim Dempsey

www.quickthreadprogramming.com

ASSOCIATE is not like macro expansion. Probably the best way to think of it is like a pointer that points to the selector expression. There are some limitations as to what you can do inside the block. In the first case shown, the function is called when the block is entered and its result assigned to the newly created variable var1. Inside the block, var1 is used like a normal variable - there's no inlining going on.

It gets more interesting when you use something like:

associate (var1 => a%b(3))

where b is also a derived type. You can, inside the block, do something like var1%c.

In Jim's example, it uses the value of This at entry to the block.

As for performance impact, I would say it is minimal to nonexistent.

Steve - Intel Developer Support

Thanks for the answer.

Leave a Comment

Please sign in to add a comment. Not a member? Join today