X-Git-Url: http://git.euphorik.ch/index.cgi?a=blobdiff_plain;f=WCudaMSE%2FStudent_OMP%2Fsrc%2Fcpp%2Fcore%2Fomp%2F02_pi%2F03_pi_entrelacer_critique.cpp;fp=WCudaMSE%2FStudent_OMP%2Fsrc%2Fcpp%2Fcore%2Fomp%2F02_pi%2F03_pi_entrelacer_critique.cpp;h=4304325306293793a58ee81e8971f4424b649bf5;hb=8d08c12b29c2a14684f35c023ee39e694bb80d25;hp=0000000000000000000000000000000000000000;hpb=226de81f7e1f1fbf4ac79d0d089e8a05ec7159a0;p=GPU.git diff --git a/WCudaMSE/Student_OMP/src/cpp/core/omp/02_pi/03_pi_entrelacer_critique.cpp b/WCudaMSE/Student_OMP/src/cpp/core/omp/02_pi/03_pi_entrelacer_critique.cpp new file mode 100755 index 0000000..4304325 --- /dev/null +++ b/WCudaMSE/Student_OMP/src/cpp/core/omp/02_pi/03_pi_entrelacer_critique.cpp @@ -0,0 +1,73 @@ +#include +#include "00_pi_tools.h" +#include "OmpTools.h" + +/*----------------------------------------------------------------------*\ + |* Declaration *| + \*---------------------------------------------------------------------*/ + +/*--------------------------------------*\ + |* Imported *| + \*-------------------------------------*/ + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +bool isPiOMPEntrelacerCritical_Ok(int n); + +/*--------------------------------------*\ + |* Private *| + \*-------------------------------------*/ + +static double piOMPEntrelacerCritical(int n); + +/*----------------------------------------------------------------------*\ + |* Implementation *| + \*---------------------------------------------------------------------*/ + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +bool isPiOMPEntrelacerCritical_Ok(int n) + { + return isAlgoPI_OK(piOMPEntrelacerCritical, n, "Pi OMP Entrelacer critical"); + } + +/*--------------------------------------*\ + |* Private *| + \*-------------------------------------*/ + +double piOMPEntrelacerCritical(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 critical(sum_fpi) + sum += sumLocalThread; + + } + + return sum * DX; + } + +/*----------------------------------------------------------------------*\ + |* End *| + \*---------------------------------------------------------------------*/ +