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

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?

Link Copied

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

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.

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