Behavior of linear clause on omp simd

Hi,

I wanted to understand if the linear clause on a simd directive is behaving according to spec. Consider the following program:

Hi Arpith,

I think the result is correct. See example 1.8 linear Clause in Loop Constructs in OpenMP 4.5 Examples document. The variable j gets final value 50 after the loop, not 49. So I think 21 is the right answer.

But there is another problem. Should we change the value of lin variable at all, taking into account that there is no code for lin variable incrementation inside the loop body? If the OpenMP program must generate the same result in non-OpenMP mode, then we have to have lin=1 in all iterations and at the end of the loop. What do you think?

I think that the code should be viewed as not conforming to the OpenMP specification, since it is asserting (via the linear directive) something that is patently not true about the variable. (It’s stating that “lin” is incremented by 2 for each iteration of the loop, but that’s not the case since there is no code to do that!).

Therefore the code can produce any result when running with OpenMP enabled.

Though, I admit that at a quick skim, I can’t see where the specification would make this non-conforming…

I suggest you ask in an appropriate forum on the OpenMP web site http://forum.openmp.org/forum/ since this seems to be an issue for the specification, not our specific implementation.