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

Re: array manipulations and optimisation

Steven_L_Intel1
Employee
660 Views
Semantically, the language establishes that the right side of the assignment is fully evaluated before the left side is modified. This in effect means two (at least) loops - one to create a temporary array with the expression result, then one to store the result. Early F90 compilers in fact did it this way.

Over the years, compiler writers have enhanced dependence analysis techniques that can often let a compiler detect that there is no overlap or loop-carried dependence and the operation can be simplified using direct stores as the computation progresses. Then the two loops can be combined into one in an optimization called loop fusion.

In the particular cases you mention, additional optimizations such as "strength reduction" can make the array operation as efficient as a DO loop, but sometimes a temp may still be created if the compiler isn't able to determine that it can be avoided.

Steve
0 Kudos
1 Reply
Steven_L_Intel1
Employee
660 Views
I don't know of any rules to suggest. My recommendation is to write the code in a clear manner and let the compiler worry about it. If you find you need more performance, use a profiler to find the hot spots and look more closely at what those hot spots are doing.

Steve
0 Kudos
Reply