I have an array a size N with random numbers. Using OpenMP, I want to increment elements from 0 to 9 of array b size 10 for each number in A. Language - C.
#pragma omp parallel for for(i = 0; i < N; i++) b[a[i]]++;
Unfortunately, apparently, some elements of b seem to have simultaneous entries, and the result is not as expected. I tried it with setting b for firstprivate and lastprivate, but that didn't help either.
The task seems simple, but I do not know how to do this, since there is no atomic for arrays in OpenMP for arrays. I could create a new array for the number of threads and then add them together at the end, but this does not seem optimal.
What would be the fastest way to count the numbers of numbers in a in elements of an array of b ?
source share