[PPL-devel] OpenMP & PPL

Enea Zaffanella zaffanella at cs.unipr.it
Thu Jan 4 14:53:37 CET 2018


On 04/01/2018 11:30, Thomas LE MÉZO wrote:
>
> I have found an issue with the use of Thread_Init object, the 
> following code does not work:
>
> /
> /
>
> /#pragma omp parallel/
> /{/
> /   PPL::Thread_Init thread_init;
> /
> /#pragma omp for
>     for(int i=0; i<1000; i++){
>         PPL::C_Polyhedron ph1(3);
>         PPL::C_Polyhedron ph2(3);
>         ph1.intersection_assign(ph2);
>     }/
> /}/
> /PPL::C_Polyhedron ph3(3); // => Segment fault/
>
> It seems that when all the thread_init variables are delete, it is 
> then impossible to instantiate or proceed to any operation with ppl.

That is the expected behavior.
Each thread willing to call the PPL (even the master thread) should 
first call the thread initialization code.

> A workaround is to instantiate a new Thread_Init variable but this is 
> a bit heavy.

I can't see why this is "heavy".
Note: you can place the thread initialization code for the master thread 
in the main function.
The thread will be initialized once at program start and finalized when 
exiting the program.

Regards,
Enea.

> /#pragma omp parallel/
> /{/
> /   PPL::Thread_Init thread_init;
> /
> /#pragma omp for
>     for(int i=0; i<1000; i++){
>         PPL::C_Polyhedron ph1(3);
>         PPL::C_Polyhedron ph2(3);
>         ph1.intersection_assign(ph2);
>     }/
> /}/
> /PPL::Thread_Init thread_init;
> /
> /PPL::C_Polyhedron ph3(3); // => OK/
>
> Any other idea?
>
> Thomas
>
> ------------------------------------------------------------------------
> *De :* Thomas LE MÉZO
> *Envoyé :* mercredi 3 janvier 2018 12:26:09
> *À :* enea.zaffanella at unipr.it
> *Cc :* The Parma Polyhedra Library developers' list
> *Objet :* RE: [PPL-devel] OpenMP & PPL
>
> It seems to work! To avoid multiple instantiation of thread_init, a 
> solution is to break down the "omp parallel for" in two lines:
>
>
> #pragma omp parallel
> {
>    PPL::Thread_Init thread_init;
> #pragma omp for
>     for(int i=0; i<1000; i++){
> PPL::C_Polyhedron ph1(3);
> PPL::C_Polyhedron ph2(3);
>         ph1.intersection_assign(ph2);
>     }
> }
>
> Thank you very much,
> Thomas
>
>
> ------------------------------------------------------------------------
> *De :* Enea Zaffanella <zaffanella.enea at gmail.com> de la part de Enea 
> Zaffanella <zaffanella at cs.unipr.it>
> *Envoyé :* mercredi 3 janvier 2018 11h17
> *À :* The Parma Polyhedra Library developers' list; Thomas LE MÉZO
> *Objet :* Re: [PPL-devel] OpenMP & PPL
>
>
>
> On 31/12/2017 17:33, Thomas LE MÉZO wrote:
>>
>> Dear Enea, Dear all,
>>
>>
>> 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 :
>>
>>
>> #include <omp.h>
>>
>> namespace PPL = Parma_Polyhedra_Library;
>>
>>
>> int main(){
>>
>> #pragma omp parallel for
>>     for(int i=0; i<1000; i++){
>> PPL::C_Polyhedron ph1(3);  // => segmentation fault at line 83 of 
>> Linear_Expression.cc
>> PPL::C_Polyhedron ph2(3);
>>         ph1.intersection_assign(ph2);
>>     }
>>     return 0;
>> }
>>
>> Would you have any idea about what is wrong?
>>
>
> Each thread should be properly initialized by creating a 
> PPL::Thread_Init object (and finalized by destroying it).
> See for instance test01() in tests/Polyhedron/threadsafe1.cc
> As an alternative, you could use the make_threadable wrapper (see 
> test02() in the same test).
>
>> Is PPL compatible with using OpenMP?
>>
>
> 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++).
>
> In you code, I would try adding
>
>   PPL::Thread_Init thread_init;
>
> as the very first line of the loop body.
> This would maybe create more init objects than needed,
> but (if I remember correctly) that should not be a problem.
>
> Let us know how it goes.
>
> Enea
>
>>
>> Thanks a lot in advance,
>>
>> Thomas
>>
>>
>>
>>
>> _______________________________________________
>> PPL-devel mailing list
>> PPL-devel at cs.unipr.it <mailto:PPL-devel at cs.unipr.it>
>> http://www.cs.unipr.it/mailman/listinfo/ppl-devel
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cs.unipr.it/pipermail/ppl-devel/attachments/20180104/27559e71/attachment.htm>


More information about the PPL-devel mailing list