Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Intel Community
- Software Development Tools (Compilers, Debuggers, Profilers & Analyzers)
- Intel® Fortran Compiler
- optimization: merging redundant sums into one single sum/loop

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

Highlighted
##

A__King

New Contributor III

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-15-2019
10:38 AM

21 Views

optimization: merging redundant sums into one single sum/loop

Consider the following concise beautiful one-line Fortran code, which computes the mean of a wieghted sample of points,

mean = sum(Weight*Point) / sum(Weight)

Here real(real64) :: Point(1:np) contains all the data points and integer(int32) :: Weight(1:np) of the same length contains the wieghts.

However, in a loop implementation of the above code, the two sum() in the above can be merged into a single do-loop, potentially avoiding the extra looping and loop-overhead.

Is ifort smart enough to merge the two sums into a single loop with optimizations enabled, given that both Point(np) and Weight(np) are declared as automatic dummy arrays of the same length np?

1 Reply

Highlighted
##

The compiler CAN merge loops. Whether it will or not depends on whether it thinks it is safe and efficient to do so. But you could do this in one loop, accumulating two sums, then do the single divide.

Steve_Lionel

Black Belt Retired Employee

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-15-2019
11:39 AM

21 Views

For more complete information about compiler optimizations, see our Optimization Notice.