X-Git-Url: http://git.euphorik.ch/index.cgi?a=blobdiff_plain;f=WCudaMSE%2FStudent_OMP%2Fsrc%2Fcpp%2Fcore%2Fomp%2F02_pi%2F02_pi_entrelacer_promotionTab.cpp;fp=WCudaMSE%2FStudent_OMP%2Fsrc%2Fcpp%2Fcore%2Fomp%2F02_pi%2F02_pi_entrelacer_promotionTab.cpp;h=db48e25d37dde32af6363cc81ce057f03b3c484a;hb=8d08c12b29c2a14684f35c023ee39e694bb80d25;hp=0000000000000000000000000000000000000000;hpb=226de81f7e1f1fbf4ac79d0d089e8a05ec7159a0;p=GPU.git diff --git a/WCudaMSE/Student_OMP/src/cpp/core/omp/02_pi/02_pi_entrelacer_promotionTab.cpp b/WCudaMSE/Student_OMP/src/cpp/core/omp/02_pi/02_pi_entrelacer_promotionTab.cpp new file mode 100755 index 0000000..db48e25 --- /dev/null +++ b/WCudaMSE/Student_OMP/src/cpp/core/omp/02_pi/02_pi_entrelacer_promotionTab.cpp @@ -0,0 +1,81 @@ +#include +#include "00_pi_tools.h" +#include "OmpTools.h" + +/*----------------------------------------------------------------------*\ + |* Declaration *| + \*---------------------------------------------------------------------*/ + +/*--------------------------------------*\ + |* Imported *| + \*-------------------------------------*/ + + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +bool isPiOMPEntrelacerPromotionTab_Ok(int n); + +/*--------------------------------------*\ + |* Private *| + \*-------------------------------------*/ + +static double piOMPEntrelacerPromotionTab(int n); + +/*----------------------------------------------------------------------*\ + |* Implementation *| + \*---------------------------------------------------------------------*/ + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +bool isPiOMPEntrelacerPromotionTab_Ok(int n) + { + return isAlgoPI_OK(piOMPEntrelacerPromotionTab, n, "Pi OMP Entrelacer promotionTab"); + } + +/*--------------------------------------*\ + |* Private *| + \*-------------------------------------*/ + +/** + * pattern cuda : excellent! + */ +double piOMPEntrelacerPromotionTab(int n) + { + const int NB_THREAD = OmpTools::setAndGetNaturalGranularity(); + + double* tabSums = new double[NB_THREAD]; + + const double DX = 1.0/(double)n; + + #pragma omp parallel + { + double xs; + const int TID = OmpTools::getTid(); + int s = TID; + + while (s < n) + { + xs = s * DX; + tabSums[TID] += fpi(xs); + + s += NB_THREAD; + } + } + + double sum = 0; + for (int i = 0; i < NB_THREAD; i++) + sum += tabSums[i]; + + delete[] tabSums; + + return sum * DX; + } + +/*----------------------------------------------------------------------*\ + |* End *| + \*---------------------------------------------------------------------*/ +