samedi 3 mars 2018

OpenMP reduction clause

I have a loop which I am trying to parallelize with OpenMP. The construct I have in code is this,

for(int x = 0; x < <condition>; x++) 
{
    aggregate += <return value from very costly function(param1)>;
}

I am trying to parallelize it as follows,

#pragma omp parallel for
for(int x = 0; x < <condition>; x++) 
{
    #pragma omp parallel private(param1)
    aggregate += <return value from very costly function(param1)>;
}

It crashes if I dont make param1 private since all threads use the same memory. But also I always get aggregate's value as 0. I understand that this is because I have not reduced it to sum each thread's local calculated value of aggregate. I am confused at this, how do I do that to sum all the values from the threads?

This is in Visual Studio 13 C++.

Aucun commentaire:

Enregistrer un commentaire