2012-04-23 2 views
1

다음 코드를 사용하여 valgrind에 따른 경쟁 조건이있는 이유는 무엇입니까?#pragma omp critical 인 경우에도 tr1 :: randgen()의 레이스 조건

g++ -O3 -g -Wall -c -fmessage-length=0 -fopenmp -MMD -MP -MF"main.d" -MT"main.d" -o "main.o" "../main.cpp" 
g++ -o "test" ./main.o -lgomp 

Valgrind의 내가 사용의 #pragma는 주어진 함수를 호출 할 수 있습니다 한 번에 중요한 단 하나의 스레드를 OMP 생각

valgrind --tool=drd --check-stack-var=yes --read-var-info=yes ./test 
==19561== drd, a thread error detector 
==19561== Copyright (C) 2006-2010, and GNU GPL'd, by Bart Van Assche. 
==19561== Using Valgrind-3.6.1-Debian and LibVEX; rerun with -h for copyright info 
==19561== Command: ./test 
==19561== 
==19561== Thread 3: 
==19561== Conflicting load by thread 3 at 0x00603420 size 4 
==19561== at 0x400A10:  _ZNSt3tr116mersenne_twisterImLi32ELi624ELi397ELi31ELm2567483615ELi11ELi7ELm2636928640ELi15E Lm4022730752ELi18EEclEv.constprop.2 (random.tcc:323) 
==19561== by 0x400BB9: main._omp_fn.0 (main.cpp:16) 
==19561== by 0x4E3FEC9: ??? (in /usr/lib/x86_64-linux-gnu/libgomp.so.1.0.0) 
==19561== by 0x4C2A803: vgDrd_thread_wrapper (drd_pthread_intercepts.c:281) 
==19561== by 0x58FDEFB: start_thread (pthread_create.c:304) 
==19561== by 0x543059C: clone (clone.S:112) 
==19561== Location 0x603420 is 0 bytes inside randgen._M_p, 
==19561== a global variable declared at main.cpp:8 
==19561== Other segment start (thread 1) 
==19561== at 0x4C2AE7D: [email protected]* (drd_pthread_intercepts.c:440) 
==19561== by 0x4E402FB: ??? (in /usr/lib/x86_64-linux-gnu/libgomp.so.1.0.0) 
==19561== by 0x400898: main (main.cpp:27) 
==19561== Other segment end (thread 1) 
==19561== at 0x4E41550: ??? (in /usr/lib/x86_64-linux-gnu/libgomp.so.1.0.0) 
==19561== by 0x4E406CD: ??? (in /usr/lib/x86_64-linux-gnu/libgomp.so.1.0.0) 
==19561== by 0x4008A4: main (main.cpp:27) 

결과로

#include <iostream> 
#include <ctime> 
#include <tr1/random> 
#include <omp.h> 

using namespace std; 

tr1::mt19937 randgen; 

int random(int min, int max) 
{ 
    int number; 
    if (min!=max) 
    { 
     #pragma omp critical(randgen) 
     number = ((randgen() % (max - min)) + min); 
     return number; 

    } else 
     return min; 
} 

int main(int argc, char *argv[]) 
{ 
    omp_set_num_threads(4); 
    randgen.seed(time(NULL)); 
    #pragma omp parallel for 
    for (int i = 0; i < 10; i++) 
    { 
     random(10,100); 
    } 

    return 0; 
} 

은 컴파일? 나는 혼란스러워.

+0

여기서 스레딩 문제는 볼 수 없습니다. 'random','min'과'max'는 지역 변수이고 critical 지시어는'randgen' 순차적 호출을 호출해야합니다. – Tudor

+0

@ Tudor, 그래서 나는 혼란 스럽다. valgrind에서 버그입니까? – Mario

답변

1

당신은 Valgrind manual에서 답을 찾을 수 있습니다

DRD는 이 옵션 [--disable-리눅스 퓨 텍스]하고있는 심볼 정보가 존재로 구성된 libgomp 라이브러리를 지원합니다. 대부분의 리눅스 배포판의 경우 이것은 GCC를 다시 컴파일해야 함을 의미합니다.

+0

--disable-linux-futex로 gcc를 다시 컴파일하면 문제가 해결되었습니다. 유일한 부작용은 valgrind의 이상한 메시지입니다. chase_cuOff : 0x0905e에 대한 항목이 없습니다. chase_cuOff : 0x0b661 이상 항목이 없습니다. 그게 뭔데? – Mario

+0

의견이 없습니다. 죄송합니다. – user1202136