Where is the problem for OpenMP to do this?
- Code: Select all
SparseVector sum;
#pragma omp parallel for reduction(+: sum)
for (size_t z = 0; z < SIZE; z++)
sum += .....
I create it manually with the following code, but I cannot understand where is the problem to implement something like this in reduction.
- Code: Select all
int n = omp_get_max_threads();
SparseVector sum[n];
#pragma omp parallel for
for (size_t z = 0; z < SIZE; z++)
sum[omp_get_thread_num()] += .....;
// parallel reduction of n sum vectors to one.
for (int diff = 1; diff < n; diff <<= 1)
// parallel reduction of m sum vectors to m/2.
#pragma omp parallel for
for(int z = 0; z < n; z += 2 * diff)
if (z + diff < n)
sum[z] += sum[z + diff];
