reduction of non-primitives question

General OpenMP discussion

reduction of non-primitives question

Postby chameleon » Mon Jun 11, 2012 1:41 pm

This question is a little bit off-topic for "Using OpenMP" but "Using OpenMP" is the most relative group for this question:

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];

Re: reduction of non-primitives question

Postby MarkB » Wed Jun 13, 2012 2:26 am

To be brief, the OpenMP compiler would have to make some assumptions about how to initialise the per-thread copies, and how to use the + operator to combine them at the end of the loop. The planned user-defined reduction feature for OpenMP 4.0 requires the programmer to define these things.
Posts: 746
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh

Return to Using OpenMP

Who is online

Users browsing this forum: No registered users and 3 guests