X-Git-Url: http://git.euphorik.ch/index.cgi?a=blobdiff_plain;f=WCudaMSE%2FStudent_OMP%2Fsrc%2Fcpp%2Fcore%2Fomp%2F02_pi%2F04_pi_entrelacer_atomic.cpp;fp=WCudaMSE%2FStudent_OMP%2Fsrc%2Fcpp%2Fcore%2Fomp%2F02_pi%2F04_pi_entrelacer_atomic.cpp;h=00df8bd941f9bb1d6de54282aeac5309c654bfcd;hb=8d08c12b29c2a14684f35c023ee39e694bb80d25;hp=0000000000000000000000000000000000000000;hpb=226de81f7e1f1fbf4ac79d0d089e8a05ec7159a0;p=GPU.git diff --git a/WCudaMSE/Student_OMP/src/cpp/core/omp/02_pi/04_pi_entrelacer_atomic.cpp b/WCudaMSE/Student_OMP/src/cpp/core/omp/02_pi/04_pi_entrelacer_atomic.cpp new file mode 100755 index 0000000..00df8bd --- /dev/null +++ b/WCudaMSE/Student_OMP/src/cpp/core/omp/02_pi/04_pi_entrelacer_atomic.cpp @@ -0,0 +1,77 @@ +#include +#include "00_pi_tools.h" +#include "OmpTools.h" + +/*----------------------------------------------------------------------*\ + |* Declaration *| + \*---------------------------------------------------------------------*/ + +/*--------------------------------------*\ + |* Imported *| + \*-------------------------------------*/ + + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +bool isPiOMPEntrelacerAtomic_Ok(int n); + +/*--------------------------------------*\ + |* Private *| + \*-------------------------------------*/ + +static double piOMPEntrelacerAtomic(int n); + +/*----------------------------------------------------------------------*\ + |* Implementation *| + \*---------------------------------------------------------------------*/ + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +bool isPiOMPEntrelacerAtomic_Ok(int n) + { + return isAlgoPI_OK(piOMPEntrelacerAtomic, n, "Pi OMP Entrelacer atomic"); + } + +/*--------------------------------------*\ + |* Private *| + \*-------------------------------------*/ + +/** + * Bonne performance, si! + */ +double piOMPEntrelacerAtomic(int n) + { + const int NB_THREAD = OmpTools::setAndGetNaturalGranularity(); + const double DX = 1.0/(double)n; + double sum = 0; + + #pragma omp parallel + { + double xs; + double sumLocalThread = 0; + const int TID = OmpTools::getTid(); + int s = TID; + + while (s < n) + { + xs = s * DX; + sumLocalThread += fpi(xs); + s += NB_THREAD; + } + + #pragma omp atomic + sum += sumLocalThread; + + } + + return sum * DX; + } + +/*----------------------------------------------------------------------*\ + |* End *| + \*---------------------------------------------------------------------*/ +