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@gmail.com> de la part de Enea Zaffanella <zaffanella@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@cs.unipr.it
http://www.cs.unipr.it/mailman/listinfo/ppl-devel