help race conditions

Please, can someone explain me in a simple manner when race conditions occurs?

if I do this:

if(a[threadIdx.x+off1]<tex1Dfetch(tex,threadIdx.x+off1))
a[threadIdx.x+off1]=tex1Dfetch(tex,threadIdx.x+off1);

if(a[threadIdx.x+off2]<tex1Dfetch(tex,threadIdx.x+off2))
a[threadIdx.x+off2]=tex1Dfetch(tex,threadIdx.x+off2);

are there race conditions?

thanks in advance for any help.

Please, can someone explain me in a simple manner when race conditions occurs?

if I do this:

if(a[threadIdx.x+off1]<tex1Dfetch(tex,threadIdx.x+off1))
a[threadIdx.x+off1]=tex1Dfetch(tex,threadIdx.x+off1);

if(a[threadIdx.x+off2]<tex1Dfetch(tex,threadIdx.x+off2))
a[threadIdx.x+off2]=tex1Dfetch(tex,threadIdx.x+off2);

are there race conditions?

thanks in advance for any help.

Yes if more than one thread accesses the same element of [font=“Courier New”]a[/font].

Yes if more than one thread accesses the same element of [font=“Courier New”]a[/font].

Hi, thank you for your reply. Can you explain me how i can remove it in a simple way? where is exactly the race conditions?

thank in advance

Hi, thank you for your reply. Can you explain me how i can remove it in a simple way? where is exactly the race conditions?

thank in advance

My apologies. In this little snippet there is no race condition because the textures are always read at the same index where [font=“Courier New”]a[/font] is written (and textures are read-only), so if any two threads access the same index they will also write the same value (if they write at all), and order doesn’t matter.

My apologies. In this little snippet there is no race condition because the textures are always read at the same index where [font=“Courier New”]a[/font] is written (and textures are read-only), so if any two threads access the same index they will also write the same value (if they write at all), and order doesn’t matter.

Hi,

no problem, and thank you very much for your help. I have another question :what happens if I don’t use the texture memory? and I do something like that:

float p=-3;

 if( label[index+1]>=level && p<phi[index+1])

     p= phi[index+1];

  if( &label[index-1]>=level && p<phi[index-1])

      p=phi[index-1];

  if  (  label[index+im_r]>=level && p<phi[index+im_r])

     p=phi[index+im_r];

 if(label[index-im_r]>=level && p<phi[index-im_r]) 

    p=phi[index-im_r];

if (label[index+(im_rim_c)]>=level && p<phi[index+(im_rim_c)])

     p=phi[index+(im_r*im_c)];

if(label[index-(im_rim_c)]>=level && p<phi[index-(im_rim_c)])

    p=phi[index-(im_r*im_c)];

I think that I’m serializing the access to the same memory location, therefor I would not have race conditions. Is it correct?

I really appreciate your help.

Thanks in advance.

Hi,

no problem, and thank you very much for your help. I have another question :what happens if I don’t use the texture memory? and I do something like that:

float p=-3;

 if( label[index+1]>=level && p<phi[index+1])

     p= phi[index+1];

  if( &label[index-1]>=level && p<phi[index-1])

      p=phi[index-1];

  if  (  label[index+im_r]>=level && p<phi[index+im_r])

     p=phi[index+im_r];

 if(label[index-im_r]>=level && p<phi[index-im_r]) 

    p=phi[index-im_r];

if (label[index+(im_rim_c)]>=level && p<phi[index+(im_rim_c)])

     p=phi[index+(im_r*im_c)];

if(label[index-(im_rim_c)]>=level && p<phi[index-(im_rim_c)])

    p=phi[index-(im_r*im_c)];

I think that I’m serializing the access to the same memory location, therefor I would not have race conditions. Is it correct?

I really appreciate your help.

Thanks in advance.