Concurrent flag for notifying if a condition is true in any work item

I’m writing a kernel for checking geometric intersections of a line and a collection of primitives. The goal is to check whether there’s an intersection or not. Each work item can tell if the line intersects a primitive or not.

Given that I’m not interested in finding the intersection point, but just if there’s an intersection or not, I was wondering if it would be correct if I initialize a single global flag to FALSE and then all work items write TRUE in that same flag if they find an intersection.

None of them are allowed to set the flag to FALSE, so, at first glance this seems correct to me, but I’m asking because I’m not 100% sure of this…


I can tell from experience (arisen from bugs mostly) this works (on the hardware I tested) but you should not do that.
Look at atomic instructions. I honestly have difficulty believing you won’t want to pull out a list of intersections in the near future!