Home > Back-end >  Arrays are summed up using openmp
Arrays are summed up using openmp

Time:09-30

Know about the openmp, recently wrote a summation of the program of array elements, but found that after running more slowly than serial sum, a lot of Internet, a variety of don't know the root cause, I'm quad-core CPU

 
Void parallel_sum ()
{
STD: : vector Nums (1000);
For (int I=1; I & lt;=1000; + + I)
Nums [I - 1]=I;

Int sum=0;

# pragma omp parallel for reduction (+ : sum)
For (int I=0; I & lt; 1000; + + I)
Sum=sum + nums [I];
}

Consult!

CodePudding user response:

Don't Shared memory address,

CodePudding user response:

reference 1st floor GKatHere response:
don't Shared memory address,
mean sum, why
  • Related