X-Git-Url: http://git.euphorik.ch/index.cgi?a=blobdiff_plain;f=WCudaMSE%2FStudent_OMP%2Fsrc%2Fcpp%2Fcore%2Fomp%2F02_pi%2F07_pi_for_promotionTab.cpp;fp=WCudaMSE%2FStudent_OMP%2Fsrc%2Fcpp%2Fcore%2Fomp%2F02_pi%2F07_pi_for_promotionTab.cpp;h=8240aa347fd08c151cd11eb3c7392faad0989bd9;hb=8d08c12b29c2a14684f35c023ee39e694bb80d25;hp=0000000000000000000000000000000000000000;hpb=226de81f7e1f1fbf4ac79d0d089e8a05ec7159a0;p=GPU.git diff --git a/WCudaMSE/Student_OMP/src/cpp/core/omp/02_pi/07_pi_for_promotionTab.cpp b/WCudaMSE/Student_OMP/src/cpp/core/omp/02_pi/07_pi_for_promotionTab.cpp new file mode 100755 index 0000000..8240aa3 --- /dev/null +++ b/WCudaMSE/Student_OMP/src/cpp/core/omp/02_pi/07_pi_for_promotionTab.cpp @@ -0,0 +1,80 @@ +#include +#include "00_pi_tools.h" +#include "MathTools.h" +#include "OmpTools.h" + + +/*----------------------------------------------------------------------*\ + |* Declaration *| + \*---------------------------------------------------------------------*/ + +/*--------------------------------------*\ + |* Imported *| + \*-------------------------------------*/ + + + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +bool isPiOMPforPromotionTab_Ok(int n); + +/*--------------------------------------*\ + |* Private *| + \*-------------------------------------*/ + +static double piOMPforPromotionTab(int n); +static void syntaxeSimplifier(double* tabSumThread,int n); +static void syntaxeFull(double* tabSumThread,int n); + +/*----------------------------------------------------------------------*\ + |* Implementation *| + \*---------------------------------------------------------------------*/ + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +bool isPiOMPforPromotionTab_Ok(int n) + { + return isAlgoPI_OK(piOMPforPromotionTab, n, "Pi OMP for promotion tab"); + } + +/*--------------------------------------*\ + |* Private *| + \*-------------------------------------*/ + +/** + * De-synchronisation avec PromotionTab + */ +double piOMPforPromotionTab(int n) + { + double xi; + const int NB_THREAD = OmpTools::setAndGetNaturalGranularity(); + const double DX = 1.0/(double)n; + + double sums[NB_THREAD]; + memset(sums, 0, sizeof(sums)); // TODO + + #pragma omp parallel for private(xi) + for (int i = 0; i < n; i++) + { + const int TID = OmpTools::getTid(); + xi = i * DX; + sums[TID] += fpi(xi); + } + + double sum = 0; + for (int i = 0; i < NB_THREAD; i++) + sum += sums[i]; + + return sum * DX; + } + + + +/*----------------------------------------------------------------------*\ + |* End *| + \*---------------------------------------------------------------------*/ +