<div dir="ltr">Thank you so much for this. I have studied more of the implementation and I think I now see how it performs dispatch based on the template arguments down to the backend. Everything now compiles and runs, although some of the tests are failing. I'm currently trying to understand the failing tests in order to debug them. I do appreciate your time and help!</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Sep 28, 2020 at 5:44 AM Dvorskiy, Mikhail <<a href="mailto:mikhail.dvorskiy@intel.com">mikhail.dvorskiy@intel.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">





<div lang="EN-US">
<div class="gmail-m_3376400325094852006WordSection1">
<p class="MsoNormal">Hi Cristopher,<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">1.<u></u><u></u></p>
<p class="MsoNormal">Briefly about Parallel design and execution policies  handling in particular:<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Parallel STL design  is based on <i>pattern of bricks</i> approach and has a compile-time dispatching mechanism which is based on overload resolution of a couple of type-tags –
<i>is_parallel </i>and<i> is_vectror. </i>A set  of combinations of the tags gives four execution policies –
<i>seq, par, unseq, par_unseq</i>. A parallel backend doesn’t handle a passed execution policy  - that parameter may be usefull for some special back-ends. It doesn’t matter for Open MP backend. (See include<i>/pstl/internal/parallel_backend.h</i> for more
 details about OpenMP backend dispatching).<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">In other words, an implementation of each PSTL algorithm based on two
<i>patterns</i>  - <i>parallel </i>(chosen by <i>is_parallel  </i>type-tag) and <i>
serial </i>(chosen by <i>is_vector  </i>type-tag). <u></u><u></u></p>
<p class="MsoNormal">Each <i>parallel pattern</i> may call <i>serial brick</i> or
<i>vector(unsequenced) brick</i>. It “gives” <i>par</i> and <i>par_unseq</i> policies implementations.<u></u><u></u></p>
<p class="MsoNormal">Each <i>serial pattern</i> also may call <i>serial brick</i> or
<i>vector(unsequenced) brick</i>. It “gives” <i>seq</i> and <i>unseq</i> policies implementations.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">2.<u></u><u></u></p>
<p class="MsoNormal">Yes, we missed to add a definition of “_Combiner” into this review. In that prototype It was moved to an utility file and another namespace… But it doesn’t matter. Just now you can find  “_Combiner” in
<a href="https://github.com/llvm/llvm-project/blob/master/pstl/include/pstl/internal/unseq_backend_simd.h" target="_blank">
https://github.com/llvm/llvm-project/blob/master/pstl/include/pstl/internal/unseq_backend_simd.h</a><u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">3. <u></u><u></u></p>
<p class="MsoNormal">In case of <i>omp_in_parallel</i>  to avoid oversubscription you should use a
<i>task API</i> instead of <i>sections</i>. A task doesn’t create a new thread. A task is added to a task pool and may be executed by the first “free” thread from the tread pool.<u></u><u></u></p>
<p class="MsoNormal">In <i>else</i> section, I think,  It would be prefer to use  a task API  as well, for better workload balance.<span lang="RU"><u></u><u></u></span></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">P.S. + <a id="gmail-m_3376400325094852006OWAAMF938DB7B87EE4118AA0E1DF6FC2CF9D4" href="mailto:Evgeniy.Pavlov@intel.com" target="_blank">
<span style="font-family:Calibri,sans-serif;text-decoration:none">@Pavlov, Evgeniy</span></a> who wrote OpenMP backend prototype.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Best regards,<span lang="RU"><u></u><u></u></span></p>
<p class="MsoNormal">Mikhail Dvorskiy<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><b>From:</b> Christopher Nelson <<a href="mailto:nadiasvertex@gmail.com" target="_blank">nadiasvertex@gmail.com</a>> <br>
<b>Sent:</b> Sunday, September 27, 2020 10:24 PM<br>
<b>To:</b> Kukanov, Alexey <<a href="mailto:Alexey.Kukanov@intel.com" target="_blank">Alexey.Kukanov@intel.com</a>><br>
<b>Cc:</b> Dvorskiy, Mikhail <<a href="mailto:mikhail.dvorskiy@intel.com" target="_blank">mikhail.dvorskiy@intel.com</a>>; Louis Dionne <<a href="mailto:ldionne@apple.com" target="_blank">ldionne@apple.com</a>>; Thomas Rodgers <<a href="mailto:trodgers@redhat.com" target="_blank">trodgers@redhat.com</a>>; Libc++ Dev <<a href="mailto:libcxx-dev@lists.llvm.org" target="_blank">libcxx-dev@lists.llvm.org</a>><br>
<b>Subject:</b> Re: [libcxx-dev] Parallel STL<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal">Hello,<u></u><u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">I have followed the advice about taking over the review above, and have gotten to a place where I'm working on getting the existing code to compile cleanly. A few functions were not implemented, so I have forwarded them to the serial backend
 for now. Just to get compilation working.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">I have a few questions:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">1. I notice that neither the TBB backend, nor the existing OpenMP backend code evaluates the execution policy to understand what to do. I may have misunderstood Louis Dionne, but it appears like the "sequential" mode is not handled at all
 if the user requests it. That seems wrong, so I must be missing something. I also notice that the execution modes are not enums, they are objects. However, when I try to overload on them in order to specialize for sequential, I get a compile error saying that
 the types are not fully defined. What is the design expectation for handling the different execution policies?<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">2. The existing code refers to a type: <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<pre><span style="font-size:11.5pt;color:rgb(0,51,179)">using </span><span style="font-size:11.5pt;color:rgb(8,8,8)">_CombinerType = __pstl::__internal::_Combiner<_Value, _Reduction>;<u></u><u></u></span></pre>
<div>
<p class="MsoNormal"><span style="font-size:11.5pt;font-family:"Courier New";color:rgb(8,8,8)">_CombinerType
</span><span style="font-size:11.5pt;font-family:"Courier New";color:black">__result</span><span style="font-size:11.5pt;font-family:"Courier New";color:rgb(8,8,8)">{__identity, &__reduction};</span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">However, this type does not exist in __pstl::__internal, at least so far as I can tell. Also, the D70530 code dump does not contain a definition of that object. Has this migrated? Should I provide my own implementation of it? <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">3. I have tried to implement a very, very simple function:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<pre><span style="font-size:11.5pt;color:rgb(0,51,179)">template </span><span style="font-size:11.5pt;color:rgb(8,8,8)"><</span><span style="font-size:11.5pt;color:rgb(0,51,179)">class </span><span style="font-size:11.5pt;color:rgb(55,31,128)">_ExecutionPolicy</span><span style="font-size:11.5pt;color:rgb(8,8,8)">, </span><span style="font-size:11.5pt;color:rgb(0,51,179)">typename </span><span style="font-size:11.5pt;color:rgb(55,31,128)">_F1</span><span style="font-size:11.5pt;color:rgb(8,8,8)">, </span><span style="font-size:11.5pt;color:rgb(0,51,179)">typename </span><span style="font-size:11.5pt;color:rgb(55,31,128)">_F2</span><span style="font-size:11.5pt;color:rgb(8,8,8)">><br></span><span style="font-size:11.5pt;color:rgb(0,51,179)">void </span><span style="font-size:11.5pt;color:rgb(0,98,122)">__parallel_invoke</span><span style="font-size:11.5pt;color:rgb(8,8,8)">(</span><span style="font-size:11.5pt;color:rgb(55,31,128)">_ExecutionPolicy </span><span style="font-size:11.5pt;color:rgb(8,8,8)">&&, </span><span style="font-size:11.5pt;color:rgb(55,31,128)">_F1 </span><span style="font-size:11.5pt;color:rgb(8,8,8)">&&__f1, </span><span style="font-size:11.5pt;color:rgb(55,31,128)">_F2 </span><span style="font-size:11.5pt;color:rgb(8,8,8)">&&__f2) {<br>    </span><span style="font-size:11.5pt;color:rgb(0,51,179)">if </span><span style="font-size:11.5pt;color:rgb(8,8,8)">(omp_in_parallel()) {<br>        _PSTL_PRAGMA(omp sections) {<br>            _PSTL_PRAGMA(omp section)<br>            </span><span style="font-size:11.5pt;color:teal">std</span><span style="font-size:11.5pt;color:rgb(8,8,8)">::forward<</span><span style="font-size:11.5pt;color:rgb(55,31,128)">_F1</span><span style="font-size:11.5pt;color:rgb(8,8,8)">>(__f1)();<br>            _PSTL_PRAGMA(omp section)<br>            </span><span style="font-size:11.5pt;color:teal">std</span><span style="font-size:11.5pt;color:rgb(8,8,8)">::forward<</span><span style="font-size:11.5pt;color:rgb(55,31,128)">_F2</span><span style="font-size:11.5pt;color:rgb(8,8,8)">>(__f2)();<br>        }<br>    } </span><span style="font-size:11.5pt;color:rgb(0,51,179)">else </span><span style="font-size:11.5pt;color:rgb(8,8,8)">{<br>        _PSTL_PRAGMA(omp parallel)<br>        _PSTL_PRAGMA(omp sections) {<br>            _PSTL_PRAGMA(omp section)<br>            </span><span style="font-size:11.5pt;color:teal">std</span><span style="font-size:11.5pt;color:rgb(8,8,8)">::forward<</span><span style="font-size:11.5pt;color:rgb(55,31,128)">_F1</span><span style="font-size:11.5pt;color:rgb(8,8,8)">>(__f1)();<br>            _PSTL_PRAGMA(omp section)<br>            </span><span style="font-size:11.5pt;color:teal">std</span><span style="font-size:11.5pt;color:rgb(8,8,8)">::forward<</span><span style="font-size:11.5pt;color:rgb(55,31,128)">_F2</span><span style="font-size:11.5pt;color:rgb(8,8,8)">>(__f2)();<br>        }<br>    }<br>}<u></u><u></u></span></pre>
<p class="MsoNormal">Does this look sane? I have just started reading through the OpenMP documentation. This looks like it could be correct, but there is also the "omp task" directive, and it's not clear which of these is superior in this case. Also, this seems
 awfully repetitive. Is this just OpenMP?<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Thanks!<u></u><u></u></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">On Wed, Sep 16, 2020 at 9:28 AM Kukanov, Alexey <<a href="mailto:Alexey.Kukanov@intel.com" target="_blank">Alexey.Kukanov@intel.com</a>> wrote:<u></u><u></u></p>
</div>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class="MsoNormal"><span style="font-family:Cambria,serif;color:rgb(31,73,125)">Hi Cristopher,</span><span lang="RU"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:Cambria,serif;color:rgb(31,73,125)"> </span><span lang="RU"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:Cambria,serif;color:rgb(31,73,125)">One good way to contribute, I think, is to develop an OpenMP-based parallel backend. LLVM already supports OpenMP, so it
 resolves the dependency problem Louis mentioned. While it’s arguably not the best default engine in the long term, there is certainly some demand for it. The GCC community is also interested in it. Moreover, Mikhail and the team at Intel in collaboration with
 Thomas (CC’d) from GCC already developed a basic prototype: <a href="https://reviews.llvm.org/D70530" target="_blank">
https://reviews.llvm.org/D70530</a>, but further work is postponed. If you are interested to continue, you are more than welcome, and we will help with guidance and feedback.</span><span lang="RU"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:Cambria,serif;color:rgb(31,73,125)"> </span><span lang="RU"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:Cambria,serif;color:rgb(31,73,125)">Regards,</span><span lang="RU"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:Cambria,serif;color:rgb(31,73,125)">- Alexey</span><span lang="RU"><u></u><u></u></span></p>
<p class="MsoNormal"> <span lang="RU"><u></u><u></u></span></p>
<p class="MsoNormal"><b>From:</b> libcxx-dev <<a href="mailto:libcxx-dev-bounces@lists.llvm.org" target="_blank">libcxx-dev-bounces@lists.llvm.org</a>>
<b>On Behalf Of </b>Christopher Nelson via libcxx-dev<br>
<b>Sent:</b> Wednesday, September 16, 2020 2:43 PM<br>
<b>To:</b> Louis Dionne <<a href="mailto:ldionne@apple.com" target="_blank">ldionne@apple.com</a>><br>
<b>Cc:</b> Dvorskiy, Mikhail <<a href="mailto:mikhail.dvorskiy@intel.com" target="_blank">mikhail.dvorskiy@intel.com</a>>;
<br>
<b>Subject:</b> Re: [libcxx-dev] Parallel STL<span lang="RU"><u></u><u></u></span></p>
<p class="MsoNormal"> <span lang="RU"><u></u><u></u></span></p>
<div>
<p class="MsoNormal">Fantastic. I will study the serial backend and see what I can do!<span lang="RU"><u></u><u></u></span></p>
</div>
<p class="MsoNormal"> <span lang="RU"><u></u><u></u></span></p>
<div>
<div>
<p class="MsoNormal">On Tue, Sep 15, 2020 at 5:27 PM Louis Dionne <<span lang="RU"><a href="mailto:ldionne@apple.com" target="_blank"><span lang="EN-US">ldionne@apple.com</span></a></span>> wrote:<span lang="RU"><u></u><u></u></span></p>
</div>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0in 0in 0in 6pt;margin:5pt 0in 5pt 4.8pt">
<div>
<p class="MsoNormal">+ Mikhail, who wrote most of the PSTL<span lang="RU"><u></u><u></u></span></p>
<div>
<div>
<p class="MsoNormal" style="margin-bottom:12pt"><span lang="RU"><u></u> <u></u></span></p>
<blockquote style="margin-top:5pt;margin-bottom:5pt">
<div>
<p class="MsoNormal">On Sep 15, 2020, at 15:40, Christopher Nelson <<span lang="RU"><a href="mailto:nadiasvertex@gmail.com" target="_blank"><span lang="EN-US">nadiasvertex@gmail.com</span></a></span>>
 wrote:<span lang="RU"><u></u><u></u></span></p>
</div>
<p class="MsoNormal"> <span lang="RU"><u></u><u></u></span></p>
<div>
<div>
<p class="MsoNormal">Okay, that makes sense. I can see how you might want to use Grand Central Dispatch on macOS, and the Windows system thread pool on Windows. I'm not really sure what that means for
 Linux, though. Other than maybe pthreads, which is not great.<span lang="RU"><u></u><u></u></span></p>
<div>
<p class="MsoNormal"> <span lang="RU"><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal">Is there any documentation on what is needed to create a backend? Or are there perhaps already plans in motion? I don't want to step on any toes, but I would love to have a usable
 pstl on macOS and Linux for the next LLVM release.<span lang="RU"><u></u><u></u></span></p>
</div>
</div>
</div>
</blockquote>
<blockquote style="margin-top:5pt;margin-bottom:5pt">
<div>
<div>
<div>
<p class="MsoNormal">We use libc++ on Linux as well as macOS. Depending on what's involved, I might be able to contribute a backend for those two platforms.<span lang="RU"><u></u><u></u></span></p>
</div>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal"> <span lang="RU"><u></u><u></u></span></p>
</div>
<p class="MsoNormal">You're not stepping on any toes, far from that. If we have backends with satisfactory performance and we're confident about ABI stability, I don't see a reason why we wouldn't ship
 the PSTL as soon as we have those. One big issue to shipping it so far has been that the only backends are serial (not great to ship that), and the other one relies on an external dependency (TBB).<span lang="RU"><u></u><u></u></span></p>
<div>
<p class="MsoNormal"> <span lang="RU"><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal">Mikhail might be able to provide documentation. We should check it into the PSTL repository. I meant to write such documentation when I wrote the serial backend, but never got around
 to writing something that was enough to check in. You can see the minimal API needed to implement a backend here: pstl/include/pstl/internal/parallel_backend_serial.h. It's the serial backend, which tries to be as trivial as possible.<span lang="RU"><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"> <span lang="RU"><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal">Are you familiar with libc++ contribution? If so, contributing to PSTL works basically the same -- just send a Phabricator review and I'll review it. We can also chat on Slack in
 the Cpplang workspace and I can give some guidance -- look for "ldionne".<span lang="RU"><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"> <span lang="RU"><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal">Cheers,<span lang="RU"><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal">Louis<span lang="RU"><u></u><u></u></span></p>
</div>
<p class="MsoNormal" style="margin-bottom:12pt"><span lang="RU"><u></u> <u></u></span></p>
<blockquote style="margin-top:5pt;margin-bottom:5pt">
<div>
<p class="MsoNormal"> <span lang="RU"><u></u><u></u></span></p>
<div>
<div>
<p class="MsoNormal">On Tue, Sep 15, 2020 at 2:50 PM Louis Dionne <<span lang="RU"><a href="mailto:ldionne@apple.com" target="_blank"><span lang="EN-US">ldionne@apple.com</span></a></span>> wrote:<span lang="RU"><u></u><u></u></span></p>
</div>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0in 0in 0in 6pt;margin:5pt 0in 5pt 4.8pt">
<p class="MsoNormal" style="margin-bottom:12pt">Hi,<br>
<br>
Long story short, the PSTL is pretty much ready to be shipped with LLVM. I did the integration between it and libc++, and it all worked last time I checked. I think the next step would be to change whatever LLVM scripts are used to create releases to also install
 the PSTL, which is the part I haven't had time to look into yet.<br>
<br>
That being said, the PSTL will then default to using the Serial backend, which isn't very useful. We could decide to ship a different backend if we wanted, however I think what makes sense is to use a backend specific to the platform we're running on instead
 of adding a dependency to LLVM.<br>
<br>
Louis<br>
<br>
> On Sep 8, 2020, at 08:25, Christopher Nelson via libcxx-dev <<span lang="RU"><a href="mailto:libcxx-dev@lists.llvm.org" target="_blank"><span lang="EN-US">libcxx-dev@lists.llvm.org</span></a></span>> wrote:<br>
> <br>
> Hello friends,<br>
> <br>
> I have spent some time looking at the mailing archives and git logs for the parallel STL. I'm not clear what state it is in, since the oneAPI/tbb seems to be production ready and comes with the parallel STL. Also, it appears the GCC has shipped a PSTL based
 on the same code that clang is using.<br>
> <br>
> I was wondering if someone could clarify for me what state the PSTL is in, and if there is some work needed to help get it over the finish line I may be able to help. I'm very interested in using it in our production software, so I'm a motivated helper. :-)<br>
> <br>
> Thank you for your time,<br>
> -={C}=-<br>
> _______________________________________________<br>
> libcxx-dev mailing list<br>
> <span lang="RU"><a href="mailto:libcxx-dev@lists.llvm.org" target="_blank"><span lang="EN-US">libcxx-dev@lists.llvm.org</span></a></span><br>
> <span lang="RU"><a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/libcxx-dev" target="_blank"><span lang="EN-US">https://lists.llvm.org/cgi-bin/mailman/listinfo/libcxx-dev</span></a><u></u><u></u></span></p>
</blockquote>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal"> <span lang="RU"><u></u><u></u></span></p>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</div>

</blockquote></div>