[SCore-users] race condition in reduction clause in a function call

arpiruk at yahoo.com arpiruk at yahoo.com
Thu Jul 10 20:52:59 JST 2003


I have problem of race condition in subfunction. The
code is shown below.


main.c
------------------------------------------
	        
	#pragma omp parallel private(it)
	{ 
	for (it=1;it<iter-1 ;it++){
	jacobi_relax(omega, f, u, uhelp, size,iter);}
	rnorm0=rnorm;
	rnorm=jacobi_residuum(f, u, res, size);
	} 
------------------------------------------

jacobi_residuum.c is look like this
------------------------------------------
#pragma omp for  reduction(+:rnorm)
	
for( i=1; i<size-1; i++ )
{
	for( j=1; j<size-1; j++ )
	{
	res[i][j] = f[i][j] - 4*u[i][j] + u[i-1][j] +
u[i+1][j] + u[i][j-1] + u[i][j+1];
	rnorm =rnorm + res[i][j]*res[i][j];
	}
}

return( sqrt(rnorm) );
------------------------------------------

it seems alright if it's not under the parallel region
in the main function. So now we have race condition
here. I know that the desired value is kept in
masterthread so I add condition as follow


if (omp_get_thread_num()==0){
return( sqrt(rnorm) );}

also, I think

#pragma omp master
return(sqrt(rnorm));

should be fine too.But some how those 2 methods is
seemed awkward to me.

Somehow this program and its module are simple and can
put into the main program without difficulty,but if
program is more complex and there are many more work
sharing and other clauses under that parallel region;
it would be bad for efficiency sake, if the threads
must be terminated at reduction clause and then
created again right after that.

Please suggest me how can I do it right...


Thank you so much

Hokpunna

__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com



More information about the SCore-users mailing list