<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<p style="margin-top:0;margin-bottom:0">It seems to work! To avoid multiple instantiation of
<span>thread_init</span>, a solution is to break down the "omp parallel for" in two lines:<br>
</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0"></p>
<div>#pragma omp parallel</div>
<div>{</div>
<div><span>   PPL::Thread_Init thread_init;</span><br>
</div>
<div>#pragma omp for<br>
    for(int i=0; i<1000; i++){<br>
        <span><span>PPL</span></span>::C_Polyhedron ph1(3); <span></span><br>
        <span><span>PPL</span></span>::C_Polyhedron ph2(3);<br>
        ph1.intersection_assign(ph2);<br>
    }</div>
<div>}<br>
</div>
<br>
<p></p>
<div id="divtagdefaultwrapper" style="font-size: 12pt; color: rgb(0, 0, 0); font-family: Calibri, Helvetica, sans-serif, "EmojiFont", "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;" dir="ltr">
Thank you very much,</div>
<div style="font-size: 12pt; color: rgb(0, 0, 0); font-family: Calibri, Helvetica, sans-serif, "EmojiFont", "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;" dir="ltr">
Thomas<br>
<div id="Signature"></div>
<br>
<br>
<div style="color: rgb(0, 0, 0);">
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font style="font-size:11pt" color="#000000" face="Calibri, sans-serif"><b>De :</b> Enea Zaffanella <zaffanella.enea@gmail.com> de la part de Enea Zaffanella <zaffanella@cs.unipr.it><br>
<b>Envoyé :</b> mercredi 3 janvier 2018 11h17<br>
<b>À :</b> The Parma Polyhedra Library developers' list; Thomas LE MÉZO<br>
<b>Objet :</b> Re: [PPL-devel] OpenMP & PPL</font>
<div> </div>
</div>
<div style="background-color:#FFFFFF">
<p><br>
</p>
<br>
<div class="x_moz-cite-prefix">On 31/12/2017 17:33, Thomas LE MÉZO wrote:<br>
</div>
<blockquote type="cite">
<div id="x_divtagdefaultwrapper" dir="ltr" style="">
<p style="margin-top:0; margin-bottom:0">Dear <span>Enea, Dear all,</span></p>
<p style="margin-top:0; margin-bottom:0"><span><br>
</span></p>
<p style="margin-top:0; margin-bottom:0"><span>I tried recently to implement a multi-thread version of my thesis code using PPL library. I used OpenMP and the last version of ppl on devel git branch as I read you have been working on a thread-safe implementation
 (thread-safe option with configure). I didn't succeed in writing a correct program; see for instance this simple code that return a segmentation fault :</span></p>
<p style="margin-top:0; margin-bottom:0"><span><br>
</span></p>
<p style="margin-top:0; margin-bottom:0"><span><span>#include <omp.h></span><br>
</span></p>
<p style="margin-top:0; margin-bottom:0"><span><span>namespace PPL = Parma_Polyhedra_Library;</span><br>
</span></p>
<p style="margin-top:0; margin-bottom:0"><span><br>
</span></p>
<p style="margin-top:0; margin-bottom:0"><span><span>int main(){</span><br>
</span></p>
<p style="margin-top:0; margin-bottom:0"><span></span></p>
<div>#pragma omp parallel for<br>
    for(int i=0; i<1000; i++){<br>
        <span><span>PPL</span></span>::C_Polyhedron ph1(3);  // => segmentation fault
<span>at line 83 of Linear_Expression.cc</span><br>
        <span><span>PPL</span></span>::C_Polyhedron ph2(3);<br>
        ph1.intersection_assign(ph2);<br>
    }</div>
<div>    return 0;</div>
<div>}<br>
</div>
<br>
<p style="margin-top:0; margin-bottom:0">Would you have any idea about what is wrong?</p>
</div>
</blockquote>
<br>
Each thread should be properly initialized by creating a PPL::Thread_Init object (and finalized by destroying it).<br>
See for instance test01() in tests/Polyhedron/threadsafe1.cc<br>
As an alternative, you could use the make_threadable wrapper (see test02() in the same test).<br>
<br>
<blockquote type="cite">
<div id="x_divtagdefaultwrapper" dir="ltr" style="">
<p style="margin-top:0; margin-bottom:0">Is PPL compatible with using OpenMP?</p>
</div>
</blockquote>
<br>
I never tried using it with OpenMP ... however, as long as thread initializations (and finalizations) are performed as suggested above, things should be working (there is also a library initialization part, but that is automatically done when working in C++).<br>
<br>
In you code, I would try adding<br>
<br>
  PPL::Thread_Init thread_init;<br>
<br>
as the very first line of the loop body.<br>
This would maybe create more init objects than needed,<br>
but (if I remember correctly) that should not be a problem.<br>
<br>
Let us know how it goes.<br>
<br>
Enea<br>
<br>
<blockquote type="cite">
<div id="x_divtagdefaultwrapper" dir="ltr" style="">
<p style="margin-top:0; margin-bottom:0"><br>
</p>
<p style="margin-top:0; margin-bottom:0">Thanks a lot in advance,</p>
<p style="margin-top:0; margin-bottom:0">Thomas<br>
</p>
<br>
</div>
<br>
<fieldset class="x_mimeAttachmentHeader"></fieldset> <br>
<pre>_______________________________________________
PPL-devel mailing list
<a class="x_moz-txt-link-abbreviated" href="mailto:PPL-devel@cs.unipr.it">PPL-devel@cs.unipr.it</a>
<a class="x_moz-txt-link-freetext" href="http://www.cs.unipr.it/mailman/listinfo/ppl-devel">http://www.cs.unipr.it/mailman/listinfo/ppl-devel</a>
</pre>
</blockquote>
<br>
</div>
</div>
</div>
</div>
</body>
</html>