I have a bunch of “jobs” represented by a simple list of integers 0-200000 that threads work on and finish. The jobs all take a different amount of time to do, so I use an array to track which jobs have been finished… the thread just writes a boolean “1” into an array slot to mark that job as being done.
If I have a thread write a value to an array index, do I have to worry about that thread’s write being lost because of a collision with another thread’s write of a neighbor index? They are UNIQUE indexes but I am not sure about the size of the memory “update quantum”.
I doubt CUDA gives bit-level updates, but does it give char level? Only 32 bit int level?
So you could have some kind of writes like:
char C; // 8 bit variables
short S; // 16 bit variables
int I; // 32 bit variables
long long L; // 64 bit variables
Which of these cases are guaranteed to work without any writes being lost?
All of the tid (thread ID) values are unique but assume that they come in any order.
I’d like to know the same answer for the CPU, too! With multithreading, can you write bytes without interference from other threads? Shorts? Ints? Does it matter if you are running the CPU in 32 or 64 bit mode?
Sorry if my question isn’t clear… this is so subtle, but has been causing me huge headaches. I worry that I need to waste a fill 32 bit integer for every boolean I need to store. And even worse, I worry I need to fill a 64 bit integer on the CPU.
I could add a critical section to make it thread safe but the overhead would be too large.
Actual Testing does NOT prove much because multithreading is always so subtle it’s hard to get the right test cases to prove success or failure.