I have an input array that is given to a kernel. Each thread works with one value of the array and either changes the value or doesn't change it at all according to a rule.
I would like to find out very quickly afterwards if there was any change inside the input memory and, in case there was, I would want to find very quickly where this change occurred (index of the input array).
I thought of using something like an array of bits. The total amount of bits would be equal to the total amount of threads. Each thread would manipulate only one bit, so initially the bits would be set to false, if a thread changes the corresponding input value the bit will become true.
In order to make it more clear, let's suppose we have this input array called A
1 9 3 9 4 5
The array of bits would be the following
0 0 0 0 0 0
So we would have 6 threads working on the input array. Let's suppose that the final input array will be
1 9 3 9 2 5
So the final array of bits would be:
0 0 0 0 1 0
I don't want to use an array of bool
because each of the values will take 1 byte of memory which is quite a lot since I want to work only using bits.
Is it possible to achieve something like this?
I thought of creating a char
array where each value of the array will have 8 bits. However, what if two threads would like to change different bits of the first character of the array? They would have to do the operation atomically even though the change inside the bit will be on different locations. So using atomic operations will probably disrupt the parallelism, and in this case using atomic operations is not needed, it doesn't make any sense, but would have to be used because of the constraints of using an array of chars instead of something more specialized like an std::bitset
Thank you in advance.