Integer Compare And Swap In Openacc

Hi Dear
I have a problem with this code
This is my code

/*#pragma acc data region copyin(i , intlocalResult[0:Nsize], boolFlags[0:Nsize] ) , copy( intEndResult[0:Nsize]) ,  present_or_copyin( offset[0:Nsize+1]  ,  node[0:Msize] , weightArray[0:Msize])/*
#pragma acc  kernels
{
#pragma acc for independent
for ( int index = 0; index < Nsize; index++ )
{
if ( boolFlags[index] )
{
	boolFlags[index] = false;
#pragma acc for independent
	for (i = offset[index]; i <offset[index + 1]; i++)
	{
		if (intlocalResult[node[i]] > intEndResult[index] + weightArray[i])
			intlocalResult[node[i]] = intEndResult[index] + weightArray[i];
		
	}
}/*End Kernel1*/

//... Other Kernels
#pragma acc for independent
fo()
{
}

I need an int CAS for this piece of My code , But i don’t know how to implement it’s efficient or I don’t know how use compare and swap in openacc or c++ ?
Or i don’t know witch c or c++ library can help me

if (intlocalResult[node[i]] > intEndResult[index] + weightArray[i])
			intlocalResult[node[i]] = intEndResult[index] + weightArray[i];

Please Help me?

I Google it but i could not found Solution.

I have another Question , If i use Compare and swap , so this for is serial? and have bad effort on my run time?
What is best way to handle this situation?

Hi simoliok,

You can use an “atomic” directive to write the result, but there’s no way to put a critical section around the if statement so there would still be a potential race condition.

if (intlocalResult[node> ] > intEndResult[index] + weightArray> )
#pragma acc atomic write
intlocalResult[node> ] = intEndResult[index] + weightArray> ;
>



If i use Compare and swap , so this for is serial? and have bad effort on my run time? >

Yes, atomics do have an impact on performance.

What is best way to handle this situation?

_I’m thinking that given there’s very little compute here and if Nsize is relatively small, you might just run this bit of code sequentially on the device.
\

  • Mat_