OpenMP® Forum

Discussion on the OpenMP specification run by the OpenMP ARB. OpenMP and the OpenMP logo are registered trademarks of the OpenMP Architecture Review Board in the United States and other countries. All rights reserved.

From what I can understand on p147, "The value corresponding to the sequentially last iteration of the associated loops is assigned to the original list item.",linear clause behavior is closer to lastprivate than plain private.On p118 "If the canceled construct contains a reduction or lastprivate clause, the final value of the reduction or lastprivate variable is undefined."Shouldn't this also talk about linear clauses (for the case of #pragma omp for simd or #pragma omp parallel for simd), while you can't cancel #pragma omp simd, one can cancel#pragma omp for simd or #pragma omp parallel for simd?On p122 we have "The loop iteration variable(s) in the associated for-loop(s) of a simd construct is (are) linear with a linear-step that is the increment of the associated loop."Again, shouldn't this talk about simd or for simd or parallel for simd constructs? Also, could it be made clearer (probably also for the lastprivate wording) what exact valueis assigned for the linear or lastprivate iteration variables?#pragma omp for lastprivate (i) for (i = 0; i < 16; i++) ;should set original list item i to 16, not 15 (i.e. value from last iteration after performing the IV increment). Similarly#pragma omp simd linear (j, 2) for (i = 0; i < 15; i += 2) a[i] = j = i;should assign to original i 16 and to original j 14. Also, on p124 it doesn't have exceptions for {,parallel }{,for }simd iteration variables, is that intentional that given those don't havebackwards compatibility, one isn't allowed to write#pragma omp simd linear (i, 1) for (i = 0; i < 16; i++) ;?

jakub wrote:On p118 "If the canceled construct contains a reduction or lastprivate clause, the final value of the reduction or lastprivate variable is undefined."Shouldn't this also talk about linear clauses (for the case of #pragma omp for simd or #pragma omp parallel for simd), while you can't cancel #pragma omp simd, one can cancel

As "No OpenMP construct can appear in the simd region." the above is irrelevant, because #pragma omp cancel can't appear there either.

? As the linear clause description talks about the original list item being assigned some value, therefore it acts pretty much like listing the item in both firstprivate and lastprivate clauses, shall the above be parsed as:

i.e. must the original list item always have to be assigned even to the original list item of the parallel? There wouldn't be a way to say that the variable is linear in the simd loop, yet nothing after the loop uses the value (of course, the compiler can analyze the following code and optimize it away).

Also, as the iteration variable is predetermined linear rather than private in the simd loops, does that also mean that

? No firstprivate clause here, because clearly the iteration variable has to be initialized inside of the loop, so outer firstprivate doesn't make sense, but still compared to just #pragma omp parallel for where iteration variable is predetermined private and just optionally allowed to be specified in lastprivate clause it is more expensive by default.

jakub wrote:should set original list item i to 16, not 15 (i.e. value from last iteration after performing the IV increment). should assign to original i 16 and to original j 14. Also, on p124 it doesn't have exceptions for {,parallel }{,for }simd iteration variables, is that intentional that given those don't havebackwards compatibility, one isn't allowed to write

Another issue I came up on today. If loop iteration vars are predetermined linear, they should have linear semantics, but in collapsed loops with collapse 2 and above they certainly don't have such semantics.

Here i, j, n and o should be predetermined linear, but none of them satisfy the rules, in the iteration of the combined loop none of these can be computed as start + step * iteration, all of them are like:start + (((iteration / X) * step) % Y)where start, step, X and Y are some integers computable before the loop.So, perhaps shouldn't iteration vars be predetermined linear only in simd loops without collapse clause or with collapse(1)? For #pragma omp for simd the compiler will need to treat the iteration vars special (compute the initial values), but they certainly can't be treated like linear variables.

The collapse(4) clause says that all the 4 loops are collapsed together, into one loop that iterates 13*13*13*(13/2) times on this testcase, so there is no I loop and other loops.So, either the standard should forbid the collapse clause on #pragma omp simd and say that it isn't allowed on #pragma omp for simd either, then all these issues are gone and in real-world not sure how often collapsed loops would be successfully vectorized, or the iterator vars can't be predetermined linear if collapse clause is present and is bigger than 1.In the combined loop not even I, the outermost iterator, has linear behavior.

In the linear clause description the step doesn't have to be an integral constant expression, can be any integral expression, which is just fine in #pragma omp {,for,parallel for} simd, but for #pragma omp declare simd I wonder if it shouldn't be integral constant expression.