Segfault caused by data race

General OpenMP discussion

Segfault caused by data race

Postby Gophys » Fri Jun 14, 2013 8:49 am

Hello,

I'm new using openMP and I try to parrallelise a Loop, but I always have a seg fault with the same portion of code. I analyse it with walgrind and I get a strange data race. Here is the error by valgrind:

==25622== Possible data race during read of size 8 at 0xD5FF08 by thread #1
==25622== Locks held: none
==25622== at 0x43E7AA: Matrice4x4::glueTM(Point*, int, Point*, int, int, int) (Matrice4x4.cpp:513)
==25622== by 0x44381F: Modele::CACTermAdd(int, bool, int, int) (Modele.cpp:661)
==25622== by 0x4424BA: Modele::Add(int, Word*, int, int, int, int) (Modele.cpp:400)
==25622== by 0x4045EF: Greedy::Run(int) (Greedy.cpp:194)
==25622== by 0x4701D5: main._omp_fn.0 (main.cpp:251)
==25622== by 0x46E38E: main (main.cpp:236)
==25622==
==25622== This conflicts with a previous write of size 8 by thread #2
==25622== Locks held: none
==25622== at 0x43E5CB: Matrice4x4::glueTM(Point*, int, Point*, int, int, int) (Matrice4x4.cpp:473)
==25622== by 0x444BE8: Modele::CANTermAdd(int, int, int) (Modele.cpp:876)
==25622== by 0x442506: Modele::Add(int, Word*, int, int, int, int) (Modele.cpp:405)
==25622== by 0x4045EF: Greedy::Run(int) (Greedy.cpp:194)
==25622== by 0x4701D5: main._omp_fn.0 (main.cpp:251)
==25622== by 0x543C829: gomp_thread_start (team.c:116)
==25622== by 0x4C2A69B: mythread_wrapper (hg_intercepts.c:219)
==25622== by 0x5860D14: start_thread (pthread_create.c:308)


witch means tha the Matrice4x4 object seems to be shared between my two thread. But it's not. Both are seperate object instanced by the "Modele" object rigth before.

And there is the code for my loop:


#define USEOMP
#pragma omp parallel for private(sim)
for (int i = 0; i < nbrTurn; i++) {
#pragma omp critical
sim = params->SetGreedy();
sim->GetTrj()->ImposeTrajectory(impTrj[i]);

// Run the Greedy algorithm
sim->Run(0);
}

The sim object is the Greedys that are separatly instance wich create each their own Modele objects wich instance their own Matrice4x4 object. How can it be a data race in this case?

Thank you for your help.
Gophys
 
Posts: 3
Joined: Fri Jun 14, 2013 5:55 am

Re: Segfault caused by data race

Postby MarkB » Tue Jun 18, 2013 6:11 am

It is entirely possible for valgrind to generate false positives in its race detection.
Does the code seg fault when run using OpenMP one thread?
MarkB
 
Posts: 450
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh

Re: Segfault caused by data race

Postby Gophys » Thu Jun 20, 2013 1:24 am

Using one thread or not using OpenMP leads to no seg fault and no memory leak (checked with valgrind).
Using valgrind with multi-thread leads to the data race error, but the segfault desapear...

When I use gdb to see where the segfault is, it lead to the same conclusions: a variable in the Matrice4x4 class has been freed but it shouldn't have. Then the variable read and the segfault occur.
Gophys
 
Posts: 3
Joined: Fri Jun 14, 2013 5:55 am

Re: Segfault caused by data race

Postby MarkB » Thu Jun 20, 2013 1:58 am

Do you have the option of trying a different compiler?
MarkB
 
Posts: 450
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh

Re: Segfault caused by data race

Postby Gophys » Thu Jun 20, 2013 12:21 pm

I use Gcc with the option -fopenmp, but if you can advice me another compiler I can use it (I use Fedora, so a linux compatible compiler is required)

Thank you for trying to help me
Gophys
 
Posts: 3
Joined: Fri Jun 14, 2013 5:55 am

Re: Segfault caused by data race

Postby MarkB » Fri Jun 21, 2013 3:10 am

You can get free evaluation licences for Intel and PGI compilers, for example.

There are really two possibilities: either you have a bug in your code, but the tools are not detecting it correctly, or else there is a bug in the compiler!
Trying other compilers can help figure out which it is....
MarkB
 
Posts: 450
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh


Return to Using OpenMP

Who is online

Users browsing this forum: Google [Bot] and 7 guests