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

Cownie, James H via Openmp-dev openmp-dev at lists.llvm.org
Mon Nov 21 02:57:11 PST 2016


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.

-- Jim

James Cownie <james.h.cownie at intel.com>
SSG/DPD/TCAR (Technical Computing, Analyzers and Runtimes)
Tel: +44 117 9071438

From: Openmp-dev [mailto:openmp-dev-bounces at lists.llvm.org] On Behalf Of Alexey Bataev via Openmp-dev
Sent: Monday, November 21, 2016 9:16 AM
To: Arpith C Jacob <acjacob at us.ibm.com>; openmp-dev at lists.llvm.org
Cc: Hyojin Sung <hsung at us.ibm.com>
Subject: Re: [Openmp-dev] Behavior of linear clause on omp simd


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

---------------------------------------------------------------------
Intel Corporation (UK) Limited
Registered No. 1134945 (England)
Registered Office: Pipers Way, Swindon SN3 1RJ
VAT No: 860 2173 47

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/openmp-dev/attachments/20161121/1d6fbf2d/attachment-0001.html>


More information about the Openmp-dev mailing list