Atomic Fetch-Add
The atomic Fetch-Add is nice for parallelizing the following code:
for (i = 0; i < nkeys ; i++) { count [ key[i] ] ++; }
‘key[]’ is an array of integers, the values of key[] are used to index into the ‘count’ array. We are counting how many values of key[] have a particular integer value.
By having an atomic fetch-add, do not have to worry about two threads fetching the same location of count[] simultaneously.