[Openmp-dev] Behavior of linear clause on omp simd

Alexey Bataev via Openmp-dev openmp-dev at lists.llvm.org
Mon Nov 21 01:16:24 PST 2016


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?

Best regards,
Alexey Bataev

On 11/18/2016 11:02 PM, Arpith C Jacob wrote:

Hi,

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

---
#include <stdio.h>

int main() {
int a[11];
int lin = 1;

#pragma omp simd linear(lin:2)
for (int i=1; i<=10; i++) {
a[i] = lin;
}

printf("linear= %d\n", lin);
printf("A = \n");
for (int i=1; i<=10; i++) {
printf("%d ", a[i]);
}

printf("\n");

return 0;

}
---

Output:

linear= 21
A =
1 3 5 7 9 11 13 15 17 19

The variable 'lin' has a value of '21' after the simd loop. According to the spec, should it have a value of '19' instead?

> The value corresponding to the sequentially last iteration of the
> associated loop(s) is assigned to the original list item.

Thanks,
Arpith

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/openmp-dev/attachments/20161121/44e1630e/attachment.html>


More information about the Openmp-dev mailing list