| Thread Tools | Search this thread |
|---|
dipaktc
| July 6, 2009 4:08 AM PDT Parallel Studio Inspect reports data race where there is none | ||||
Hello I have a piece of code which I tried to parallelize using OpenMP. And then used parallel studio to check for data race. It reported one. But I cannot understand why this instance is reported as data race. Can some please help me understand this instance. Below is the piece of code. typedef int int32; typedef char int8; void** Alloc ( int32 nRowNum, int32 nColumnNum, int32 sItemSize ) { void** ppvBuffer = 0; int8* pvBuffer = 0; int32 lIndex; int32 nStep = nColumnNum * sItemSize ; if ( !nRowNum || !nColumnNum ) return NULL; ppvBuffer = (void**)new void* [ nRowNum ]; memset(ppvBuffer, 0, sizeof(void*) * nRowNum); pvBuffer = (int8*)new int8 [ nRowNum*nColumnNum*sItemSize ]; memset(pvBuffer, 0, sizeof(int8) * nRowNum*nColumnNum*sItemSize); for ( lIndex = 0; lIndex < nRowNum; lIndex++, pvBuffer += nStep ) ppvBuffer[ lIndex ] = pvBuffer; return ppvBuffer; } void Free ( void** ppvBuffer) { if ( ppvBuffer ) { if ( ppvBuffer[0] ) delete [] ppvBuffer[0]; delete [] ppvBuffer; } ppvBuffer = NULL; } void function1(int8 **ppBuffer) { int x, y; #pragma omp parallel for private(x,y) shared(ppBuffer) for(x = 0; x < 10; x++) for(y = 0; y< 10; y++) ppBuffer[x][y] = 10; return; } void function2(int8 **ppBuffer1, int8 **ppBuffer2) { int x, y, i, j; #pragma omp parallel for private(x,y, i, j)shared(ppBuffer2, ppBuffer1) for(x = 0; x < 10; x++) { i = x + 1; for(y = 0; y< 10; y++) { j = y + 1; ppBuffer2[x][y] = ppBuffer1[i][j]; } } return; } int main(void) { int8 ** ppBuffer1 = NULL; int8 ** ppBuffer2 = NULL; ppBuffer1 = (int8 **)Alloc(11, 11, sizeof(char)); ppBuffer2 = (int8 **)Alloc(11, 11, sizeof(char)); function1(ppBuffer1); function2(ppBuffer1, ppBuffer2); Free((void **)ppBuffer1); Free((void **)ppBuffer2); return 0; } I have used Visuall Studio 2005 Compiler. Intel parallel studio reports that there is a data race between read in function2 and a write in function 1.( which are highlighted). Surprisingly, if I use the Intel C++ compiler, the data race is gone. Also in the above implementation if I separate the pragma for "parallel" and "for" as shown below in both functions data race is gone. #pragma omp parallel private(x,y) shared(ppBuffer) { #pragma omp for for(x = 0; x < 10; x++) for(y = 0; y< 10; y++) ppBuffer[x][y] = 10; return; } Any help in this regard is highly appreciated. Thanks in advance. | |||||
|
|||||||||||||
|
|||||||||||||
|
|||||||||||||
|
|||||||||||||
| 8445 users have contributed to 31553 threads and 100398 posts to date. |
|---|
| In the past 24 hours, we have 10 new thread(s) 30 new posts(s), and 43 new user(s). In the past 3 days, the most popular thread for everyone has been Lost in MKL The most posts were made to TBB on linux segfaulting The post with the most views is Hi,if you were using imsl yo Please welcome our newest member nonamez |