如何使用OPENMP部分对此进行细化

时间:2009-10-22 05:23:40

标签: openmp parallel-processing

我有这个函数,我想使用openmp部分并行化。我将函数分解为各个部分并应用#pragma omp部分,但它给出了分段错误。有人可以解释为什么和解决方案。我应该使用一些条款与部分。哪一个以及如何请。

 /*!
***********************************************************************
* \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 个答案:

答案 0 :(得分:2)

**_bo, **_bi, **_bj, *_o, *_i, *_j似乎在各个部分之间共享。当不同的线程修改和读取其内容时,这将导致nodeterministic行为。我认为你需要添加一个private子句,使它们在该部分的本地。

我没试过这个,但这就是阅读你的代码所暗示的内容。