Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

Error in example (15.0 compiler online manual)

James_C_Intel2
Employee
383 Views

The page at https://software.intel.com/en-us/node/524530 (Description of omp simd) has an example that is wrong (or weird) in two ways.

The example is 

#pragma omp simd collapse(2)
for(i=0; i<N; i++) { a = b * c;
   for(i=0; i<N; i++) { d = e * f; }
}

Firstly, that loop nest cannot be collapsed, since it is not perfectly nested.

Secondly the same loop variable is used in each loop, a definite bug!

 

0 Kudos
4 Replies
TimP
Honored Contributor III
383 Views

If I use the search tool to see if a corrected version has been posted, it shows the version before the one quoted here, with the same oddity.  So it seems there is a bug in the search tool as well.

According to OpenMP standard, the first use of i should be implied private, but it seems more legible to make it explicit by int i=0;

0 Kudos
James_C_Intel2
Employee
383 Views

My issue with the loops is not that whether the first i is private or not, but that the same loop control variable variable is used in both loops! It's not an OpenMP issue, just a general bug in the serial code even without OpenMP. (Aside from the fact that the example makes no sense as serial code even if you make the inner loop iterate on "int j", since it executes the identical inner loop N times, unless we assume that there is some funky aliasing between what appear to be independent arrays, of course, but that's just getting obtuse!).

The issue with the OpenMP aspect is that it's supposed to be showing an example of the collapse clause, but the code as written can't have a  collapse clause on it!

0 Kudos
TimP
Honored Contributor III
383 Views

The simd clause seems to assert that the compiler should ignore any aliasing.  As I think you said, it's directly contradictory to the inner loop over-writing i.  I didn't mean to imply any approval of this example.  If Intel C does anything special here, it could replace the inner loop by a single assignment, but I'd prefer a compiler to warn where such things are done, as it's probably a coding error.

omp simd collapse is unusual enough that a real working example would be appreciated.  I believe there is also some automatic simd collapse analysis in Intel compilers (but it should not take effect in the presence of any suspicious dependencies).  Applying omp simd on an outer loop (outer loop vectorization) is rare enough, and I have posted examples where it works with Intel compilers but others simply ignore the vectorization hint.

0 Kudos
Judith_W_Intel
Employee
383 Views

 

Thanks for pointing this out. I have submitted a bug report for our documentation team to fix this ... The internal tracking number is

DPD200415644.

0 Kudos
Reply