I'm trying to understand the behaviour of the reduction clause with the following program

- Code: Select all
`#include<stdio.h>`

#include<omp.h>

int main(){

double v[100];

int i;

for(i=0;i<10;i++)v[i]=i+1;

double sum=0;

#pragma omp parallel for default(none) shared(v)\

reduction(*:sum)

for(i=0;i<10;i++) {

int crt;

crt=omp_get_thread_num();

sum=sum+v[i];

printf("thread %i - number %.1f\n",crt,v[i]);

}

printf("The result is: %f\n",sum);

}

I know i should have used reduction(+:sum) instead. I wanted to know if reduction(*:sum) computed the product of the local sums for each thread ... which does not happen - the result is 0.

Why is this happening?