<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p>Hi Arpith,</p>
<p>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.</p>
<p>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?<br>
</p>
<pre class="moz-signature" cols="72">Best regards,
Alexey Bataev</pre>
<div class="moz-cite-prefix">On 11/18/2016 11:02 PM, Arpith C Jacob wrote:<br>
</div>
<blockquote cite="mid:OF716A15F6.044C6D9E-ON0025806F.006D5955-8525806F.006E1ABF@notes.na.collabserv.com" type="cite">
<p>Hi,<br>
<br>
I wanted to understand if the linear clause on a simd directive is behaving according to spec. Consider the following program:<br>
<br>
---<br>
<font color="#E000E0" face="Menlo-Regular">#include </font><font color="#A11F12" face="Menlo-Regular"><stdio.h></font><br>
<br>
<font color="#00C200" face="Menlo-Regular">int</font><font face="Menlo-Regular"> main() {</font><br>
<font face="Menlo-Regular"></font><font color="#00C200" face="Menlo-Regular">int</font><font face="Menlo-Regular"> a[</font><font color="#A11F12" face="Menlo-Regular">11</font><font face="Menlo-Regular">];</font><br>
<font face="Menlo-Regular"></font><font color="#00C200" face="Menlo-Regular">int</font><font face="Menlo-Regular"> lin =
</font><font color="#A11F12" face="Menlo-Regular">1</font><font face="Menlo-Regular">;</font><br>
<br>
<font color="#E000E0" face="Menlo-Regular">#pragma omp simd linear(lin:</font><font color="#A11F12" face="Menlo-Regular">2</font><font color="#E000E0" face="Menlo-Regular">)</font><br>
<font face="Menlo-Regular"></font><font color="#E26200" face="Menlo-Regular">for</font><font face="Menlo-Regular"> (</font><font color="#00C200" face="Menlo-Regular">int</font><font face="Menlo-Regular"> i=</font><font color="#A11F12" face="Menlo-Regular">1</font><font face="Menlo-Regular">;
 i<=</font><font color="#A11F12" face="Menlo-Regular">10</font><font face="Menlo-Regular">; i++) {</font><br>
<font face="Menlo-Regular">a[i] = lin;</font><br>
<font face="Menlo-Regular">}</font><br>
<br>
<font face="Menlo-Regular">printf(</font><font color="#A11F12" face="Menlo-Regular">"linear=
</font><font color="#E000E0" face="Menlo-Regular">%d\n</font><font color="#A11F12" face="Menlo-Regular">"</font><font face="Menlo-Regular">, lin);</font><br>
<font face="Menlo-Regular">printf(</font><font color="#A11F12" face="Menlo-Regular">"A =
</font><font color="#E000E0" face="Menlo-Regular">\n</font><font color="#A11F12" face="Menlo-Regular">"</font><font face="Menlo-Regular">);</font><br>
<font face="Menlo-Regular"></font><font color="#E26200" face="Menlo-Regular">for</font><font face="Menlo-Regular"> (</font><font color="#00C200" face="Menlo-Regular">int</font><font face="Menlo-Regular"> i=</font><font color="#A11F12" face="Menlo-Regular">1</font><font face="Menlo-Regular">;
 i<=</font><font color="#A11F12" face="Menlo-Regular">10</font><font face="Menlo-Regular">; i++) {</font><br>
<font face="Menlo-Regular">printf(</font><font color="#A11F12" face="Menlo-Regular">"</font><font color="#E000E0" face="Menlo-Regular">%d</font><font color="#A11F12" face="Menlo-Regular"> "</font><font face="Menlo-Regular">, a[i]);</font><br>
<font face="Menlo-Regular">}</font><br>
<br>
<font face="Menlo-Regular">printf(</font><font color="#A11F12" face="Menlo-Regular">"</font><font color="#E000E0" face="Menlo-Regular">\n</font><font color="#A11F12" face="Menlo-Regular">"</font><font face="Menlo-Regular">);</font><br>
<br>
<font face="Menlo-Regular"></font><font color="#E26200" face="Menlo-Regular">return</font><font face="Menlo-Regular">
</font><font color="#A11F12" face="Menlo-Regular">0</font><font face="Menlo-Regular">;</font><br>
<br>
<font face="Menlo-Regular">}</font><br>
---<br>
<br>
Output:<br>
<br>
<font face="Menlo-Regular">linear= 21</font><br>
<font face="Menlo-Regular">A = </font><br>
<font face="Menlo-Regular">1 3 5 7 9 11 13 15 17 19 </font><br>
<br>
The variable 'lin' has a value of '21' after the simd loop. According to the spec, should it have a value of '19' instead?<br>
<br>
<font face="Helvetica">> The value corresponding to the sequentially last iteration of the</font><br>
<font face="Helvetica">> associated loop(s) is assigned to the original list item.</font><br>
<br>
Thanks,<br>
Arpith<br>
</p>
</blockquote>
<br>
</body>
</html>