views:

258

answers:

1

Hi, I have this function which i want to parallelize using openmp sections. I broke the function into various sections and applied #pragma omp sections but it gives segmentation fault. Can somebody please explain why and a solution to it. Should i use some clause with sections. Which one and how please.

 /*!
***********************************************************************
* \brief
*    calculation of SAD for larger blocks on the basis of 4x4        blocks    // function 4
***********************************************************************
*/
void SetupLargerBlocks (int list, int refindex, int max_pos)
{
 #define ADD_UP_BLOCKS()   _o=*_bo; _i=*_bi; _j=*_bj; for(pos=0;pos<max_pos;pos++)  _o[pos] = _i[pos] + _j[pos];
 #define INCREMENT(inc)    _bo+=inc; _bi+=inc; _bj+=inc;

int    pos, **_bo, **_bi, **_bj;
register int *_o,   *_i,   *_j;

//#pragma omp parallel
#pragma omp sections
{
#pragma omp section
{//--- blocktype 6 ---
_bo = BlockSAD[list][refindex][6];
_bi = BlockSAD[list][refindex][7];
_bj = _bi + 4;
ADD_UP_BLOCKS(); INCREMENT(1);
ADD_UP_BLOCKS(); INCREMENT(1);
ADD_UP_BLOCKS(); INCREMENT(1);
ADD_UP_BLOCKS(); INCREMENT(5);
ADD_UP_BLOCKS(); INCREMENT(1);
ADD_UP_BLOCKS(); INCREMENT(1);
ADD_UP_BLOCKS(); INCREMENT(1);
ADD_UP_BLOCKS();
}

#pragma omp section
{
 //--- blocktype 5 ---
_bo = BlockSAD[list][refindex][5];
_bi = BlockSAD[list][refindex][7];
_bj = _bi + 1;
ADD_UP_BLOCKS(); INCREMENT(2);
ADD_UP_BLOCKS(); INCREMENT(2);
ADD_UP_BLOCKS(); INCREMENT(2);
ADD_UP_BLOCKS(); INCREMENT(2);
ADD_UP_BLOCKS(); INCREMENT(2);
ADD_UP_BLOCKS(); INCREMENT(2);
ADD_UP_BLOCKS(); INCREMENT(2);
ADD_UP_BLOCKS();
}

#pragma omp section
{
//--- blocktype 4 ---
_bo = BlockSAD[list][refindex][4];
_bi = BlockSAD[list][refindex][6];
_bj = _bi + 1;
ADD_UP_BLOCKS(); INCREMENT(2);
ADD_UP_BLOCKS(); INCREMENT(6);
ADD_UP_BLOCKS(); INCREMENT(2);
ADD_UP_BLOCKS();
 } 

#pragma omp section
{  
//--- blocktype 3 ---
_bo = BlockSAD[list][refindex][3];
_bi = BlockSAD[list][refindex][4];
_bj = _bi + 8;
ADD_UP_BLOCKS(); INCREMENT(2);
ADD_UP_BLOCKS();
}

#pragma omp section
{
//--- blocktype 2 ---
_bo = BlockSAD[list][refindex][2];
_bi = BlockSAD[list][refindex][4];
_bj = _bi + 2;
ADD_UP_BLOCKS(); INCREMENT(8);
ADD_UP_BLOCKS();
}

#pragma omp section
{
//--- blocktype 1 ---
_bo = BlockSAD[list][refindex][1];
_bi = BlockSAD[list][refindex][3];
_bj = _bi + 2;
ADD_UP_BLOCKS();
}
}
}
+1  A: 

**_bo, **_bi, **_bj, *_o, *_i, *_j seem to be shared between sections. This will result in nodeterministic behavior as different threads modify and read their contents. I think you need to add a private clause to make them local to the section.

I've not tried this but that's what reading your code would suggest.

Ade Miller

related questions