I've just started to program with openmp and I'm trying to parallelize a for loop with a variable that I need out of the loop. Something like this:
float a = 0;
for (int i = 0; i < x; i++)
{
int x = algorithm();
/* Each loop, x have a different value*/
a = a + x;
}
cout << a;
I think the variable a has to be a local variable for each thread. After those thread have ended their job, all the local variables a should be added into one final result.
How can I do that?