<html><head></head><body>(apologies for top post)<br>
<br>
This all seems to scream &#39;disallow&#39; to me, in particular since some openmp implementations may not support it etc.<br>
<br>
At any rate I feel &#39;parallel/parallel/prange/prange&#39; is going to far; so next step could be to only allowing &#39;parallel/prange/parallel/prange&#39;.<br>
<br>
But really, my feeling is that if you really do need this then you can always write a seperate function for the inner loop (I honestly can&#39;t think of a usecase anyway...). So I&#39;d really drop it; at least until the rest of the gsoc project is completed :)<br>
<br>
DS<br>
-- <br>
Sent from my Android phone with K-9 Mail. Please excuse my brevity.<br><br><div class="gmail_quote">mark florisson &lt;markflorisson88@gmail.com&gt; wrote:<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div style="white-space: pre-wrap; word-wrap:break-word; ">On 16 April 2011 18:42, Dag Sverre Seljebotn &lt;d.s.seljebotn@astro.uio.no&gt; wrote:
&gt; (Moving discussion from <a href="http://markflorisson.wordpress.com">http://markflorisson.wordpress.com</a>/, where Mark
&gt; said:)

Ok, sure, it was just an issue I was wondering about at that moment, but it's a tricky issue, so thanks.

&gt; """
&gt; Started a new branch <a href="https://github.com/markflorisson88/cython/tree/openmp">https://github.com/markflorisson88/cython/tree/openmp</a> .
&gt;
&gt; Now the question is whether sharing attributes should be propagated
&gt; outwards. e.g. if you do
&gt;
&gt; for i in prange(m):
&gt;    for j in prange(n):
&gt;        sum += i * j
&gt;
&gt; then ‘sum’ is a reduction for the inner parallel loop, but not for the outer
&gt; one. So the user would currently have to rewrite this to
&gt;
&gt; for i in prange(m):
&gt;    for j in prange(n):
&gt;        sum += i * j
&gt;    sum += 0
&gt;
&gt; which seems a bit silly  . Of course, we could just disable nested
&gt; parallelism, or tell the users to use a prange and a ‘for from’ in such
&gt; cases.
&gt; """
&gt;
&gt; Dag: Interesting. The first one is definitely the behaviour we want, as long
&gt; as it doesn't cause unintended consequences.
&gt;
&gt; I don't really think it will -- the important thing is that that the order
&gt; of loop iteration evaluation must be unimportant. And that is still true
&gt; (for the outer loop, as well as for the inner) in your first example.
&gt;
&gt; Question: When you have nested pranges, what will happen is that two nested
&gt; OpenMP parallel blocks are used, right? And do you know if there is complete
&gt; freedom/"reentrancy" in that variables that are thread-private in an outer
&gt; parallel block and be shared in an inner one, and vice versa?

An implementation may or may not support it, and if it is supported the behaviour can be configured through omp_set_nested(). So we should consider the case where it is supported and enabled.

If you have a lastprivate or reduction, and after the loop these are
(reduced and) assigned to the original variable. So if that happens inside a parallel construct which does not declare the variable private to the construct, you actually have a race. So e.g. the nested prange currently races in the outer parallel range.

&gt; If so I'd think that this algorithm should work and feel natural:
&gt;
&gt;  - In each prange, for the purposes of variable private/shared/reduction
&gt; inference, consider all internal "prange" just as if they had been "range";
&gt; no special treatment.
&gt;
&gt;  - Recurse to children pranges.

Right, that is most natural. Algorithmically, reductions and
lastprivates (as those can have races if placed in inner parallel constructs) propagate outwards towards the outermost parallel block, or up to the first parallel with block, or up to the first construct that already determined the sharing attribute.
 e.g.
 with parallel:
     with parallel:
        for i in prange(n):
            for j in prange(n):
                sum += i * j
     # sum is well-defined here
# sum is undefined here

Here 'sum' is a reduction for the two innermost loops. 'sum' is not private for the inner parallel with block, as a prange in a parallel with block is a worksharing loop that binds to that parallel with block. However, the outermost parallel with block declares sum (and i and j) private, so after that block all those variables become undefined.

However, in the outermost parallel with block, sum will have to be initialized to 0 before anything else, or be declared firstprivate, otherwise 'sum' is undefined to begin with. Do you think declaring it
firstprivate would be the way to go, or should we make it private and issue a warning or perhaps even an error?

&gt; DS
&gt;<hr />&gt; cython-devel mailing list
&gt; cython-devel@python.org
&gt; <a href="http://mail.python.org/mailman/listinfo/cython-devel">http://mail.python.org/mailman/listinfo/cython-devel</a>
&gt;<hr />cython-devel mailing list
cython-devel@python.org
<a href="http://mail.python.org/mailman/listinfo/cython-devel">http://mail.python.org/mailman/listinfo/cython-devel</a>
</div></blockquote></div></body></html>