I am a beginner of CUDA, and I am writing a global function using atomic functions in if(), like:
printf(“x %d, y %d, px %d\n”,x,y,p);
and, it sometimes prints on the screen, like:
x 1, y 2, px 2
How could it happened!?
I guess you mean that with that output, you would have expected the if statement to take the then path, not the else path.
But the read of p in the printf statement is not guaranteed to be the same value of p observed by the atomic, or set by the atomic. It depends on what else is happening in your program. Presumably you are using an atomic to resolve simultaneous access. Such things can usually not be explained by inspecting such a small portion of your code, but actually require understanding of your entire program.