<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html;
      charset=windows-1252">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <br>
    <div class="moz-cite-prefix">On 04/01/2018 11:30, Thomas LE MÉZO
      wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:AM4PR0501MB285071C45C4600D2E5D45F5A8B1F0@AM4PR0501MB2850.eurprd05.prod.outlook.com">
      <meta http-equiv="Content-Type" content="text/html;
        charset=windows-1252">
      <style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
      <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">I have found an issue
          with the use of Thread_Init object, the following code does
          not work:<br>
        </p>
        <p style="margin-top:0;margin-bottom:0"><i><br>
          </i></p>
        <p style="margin-top:0;margin-bottom:0"><span
            style="font-size:12pt;" id="divtagdefaultwrapper"></span></p>
        <div><i>#pragma omp parallel</i></div>
        <div><i>{</i></div>
        <div><i>   PPL::Thread_Init thread_init;<br>
          </i></div>
        <div><i>#pragma omp for<br>
                for(int i=0; i<1000; i++){<br>
                    PPL::C_Polyhedron ph1(3); <br>
                    PPL::C_Polyhedron ph2(3);<br>
                    ph1.intersection_assign(ph2);<br>
                }</i></div>
        <div><i>}</i></div>
        <div><span style="font-size:12pt;" id="divtagdefaultwrapper"><i>PPL::C_Polyhedron
              ph3(3); // => Segment fault</i></span></div>
        <div><span style="font-size:12pt;" id="divtagdefaultwrapper"><br>
          </span></div>
        <div><span style="font-size:12pt;" id="divtagdefaultwrapper">It
            seems that when all the thread_init variables are delete, it
            is then impossible to instantiate or proceed to any
            operation with ppl.</span></div>
      </div>
    </blockquote>
    <br>
    That is the expected behavior.<br>
    Each thread willing to call the PPL (even the master thread) should
    first call the thread initialization code.<br>
    <br>
    <blockquote type="cite"
cite="mid:AM4PR0501MB285071C45C4600D2E5D45F5A8B1F0@AM4PR0501MB2850.eurprd05.prod.outlook.com">
      <div id="divtagdefaultwrapper"
style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;"
        dir="ltr">
        <div><span style="font-size:12pt;" id="divtagdefaultwrapper">A
            workaround is to instantiate a new Thread_Init variable but
            this is a bit heavy.</span></div>
      </div>
    </blockquote>
    <br>
    I can't see why this is "heavy".<br>
    Note: you can place the thread initialization code for the master
    thread in the main function.<br>
    The thread will be initialized once at program start and finalized
    when exiting the program.<br>
    <br>
    Regards,<br>
    Enea.<br>
    <br>
    <blockquote type="cite"
cite="mid:AM4PR0501MB285071C45C4600D2E5D45F5A8B1F0@AM4PR0501MB2850.eurprd05.prod.outlook.com">
      <div id="divtagdefaultwrapper"
style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;"
        dir="ltr">
        <div><span style="font-size:12pt;" id="divtagdefaultwrapper">
          </span></div>
        <div><span style="font-size:12pt;" id="divtagdefaultwrapper"><span
              style="font-size:12pt;" id="divtagdefaultwrapper">
              <div><i>#pragma omp parallel</i></div>
              <div><i>{</i></div>
              <div><i>   PPL::Thread_Init thread_init;<br>
                </i></div>
              <div><i>#pragma omp for<br>
                      for(int i=0; i<1000; i++){<br>
                          PPL::C_Polyhedron ph1(3); <br>
                          PPL::C_Polyhedron ph2(3);<br>
                          ph1.intersection_assign(ph2);<br>
                      }</i></div>
              <div><i>}</i></div>
              <div><i><span style="font-size:12pt;"
                    id="divtagdefaultwrapper"><span
                      style="font-size:12pt;" id="divtagdefaultwrapper"><span
                        style="font-size:12pt;"
                        id="divtagdefaultwrapper">PPL::Thread_Init
                        thread_init;</span></span></span><br>
                </i></div>
              <div><span style="font-size:12pt;"
                  id="divtagdefaultwrapper"><i>PPL::C_Polyhedron ph3(3);
                    // => OK</i></span></div>
              <div><span style="font-size:12pt;"
                  id="divtagdefaultwrapper"><br>
                </span></div>
              <div><span style="font-size:12pt;"
                  id="divtagdefaultwrapper">Any other idea?</span></div>
              <div><span style="font-size:12pt;"
                  id="divtagdefaultwrapper"><br>
                </span></div>
              <div><span style="font-size:12pt;"
                  id="divtagdefaultwrapper">Thomas</span><span
                  style="font-size:12pt;" id="divtagdefaultwrapper"></span><br>
                <span style="font-size:12pt;" id="divtagdefaultwrapper"></span></div>
            </span></span></div>
        <br>
      </div>
      <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> Thomas
          LE MÉZO<br>
          <b>Envoyé :</b> mercredi 3 janvier 2018 12:26:09<br>
          <b>À :</b> <a class="moz-txt-link-abbreviated" href="mailto:enea.zaffanella@unipr.it">enea.zaffanella@unipr.it</a><br>
          <b>Cc :</b> The Parma Polyhedra Library developers' list<br>
          <b>Objet :</b> RE: [PPL-devel] OpenMP & PPL</font>
        <div> </div>
      </div>
      <style type="text/css" style="display:none">
<!--
p
        {margin-top:0;
        margin-bottom:0}
-->
</style>
      <div dir="ltr">
        <div id="x_divtagdefaultwrapper" dir="ltr"
          style="font-size:12pt; color:#000000;
          font-family:Calibri,Helvetica,sans-serif">
          <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>
          <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>
          <div id="x_divtagdefaultwrapper" dir="ltr"
            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">
            Thank you very much,</div>
          <div dir="ltr" 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">
            Thomas<br>
            <br>
            <br>
            <div style="color:rgb(0,0,0)">
              <hr tabindex="-1" style="display:inline-block; width:98%">
              <div id="x_divRplyFwdMsg" dir="ltr"><font
                  style="font-size:11pt" color="#000000" face="Calibri,
                  sans-serif"><b>De :</b> Enea Zaffanella
                  <a class="moz-txt-link-rfc2396E" href="mailto:zaffanella.enea@gmail.com"><zaffanella.enea@gmail.com></a> de la part de Enea
                  Zaffanella <a class="moz-txt-link-rfc2396E" href="mailto:zaffanella@cs.unipr.it"><zaffanella@cs.unipr.it></a><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_x_moz-cite-prefix">On 31/12/2017 17:33,
                  Thomas LE MÉZO wrote:<br>
                </div>
                <blockquote type="cite">
                  <div id="x_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_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_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_x_mimeAttachmentHeader"></fieldset>
                  <br>
                  <pre>_______________________________________________
PPL-devel mailing list
<a class="x_x_moz-txt-link-abbreviated" href="mailto:PPL-devel@cs.unipr.it" moz-do-not-send="true">PPL-devel@cs.unipr.it</a>
<a class="x_x_moz-txt-link-freetext" href="http://www.cs.unipr.it/mailman/listinfo/ppl-devel" moz-do-not-send="true">http://www.cs.unipr.it/mailman/listinfo/ppl-devel</a>
</pre>
                </blockquote>
                <br>
              </div>
            </div>
          </div>
        </div>
      </div>
    </blockquote>
    <br>
  </body>
</html>