Ajout de l'ensemble du workspace.
[GPU.git] / WCudaMSE / Student_OMP / src / cpp / core / omp / 02_pi / 02_pi_entrelacer_promotionTab.cpp
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 (executable)
index 0000000..db48e25
--- /dev/null
@@ -0,0 +1,81 @@
+#include <omp.h>\r
+#include "00_pi_tools.h"\r
+#include "OmpTools.h"\r
+\r
+/*----------------------------------------------------------------------*\\r
+ |*                    Declaration                                     *|\r
+ \*---------------------------------------------------------------------*/\r
+\r
+/*--------------------------------------*\\r
+ |*            Imported                *|\r
+ \*-------------------------------------*/\r
+\r
+\r
+/*--------------------------------------*\\r
+ |*            Public                  *|\r
+ \*-------------------------------------*/\r
+\r
+bool isPiOMPEntrelacerPromotionTab_Ok(int n);\r
+\r
+/*--------------------------------------*\\r
+ |*            Private                 *|\r
+ \*-------------------------------------*/\r
+\r
+static double piOMPEntrelacerPromotionTab(int n);\r
+\r
+/*----------------------------------------------------------------------*\\r
+ |*                    Implementation                                  *|\r
+ \*---------------------------------------------------------------------*/\r
+\r
+/*--------------------------------------*\\r
+ |*            Public                  *|\r
+ \*-------------------------------------*/\r
+\r
+bool isPiOMPEntrelacerPromotionTab_Ok(int n)\r
+    {\r
+    return isAlgoPI_OK(piOMPEntrelacerPromotionTab,  n, "Pi OMP Entrelacer promotionTab");\r
+    }\r
+\r
+/*--------------------------------------*\\r
+ |*            Private                 *|\r
+ \*-------------------------------------*/\r
+\r
+/**\r
+ * pattern cuda : excellent!\r
+ */\r
+double piOMPEntrelacerPromotionTab(int n)\r
+    {\r
+    const int NB_THREAD = OmpTools::setAndGetNaturalGranularity();\r
+\r
+    double* tabSums = new double[NB_THREAD];\r
+\r
+    const double DX = 1.0/(double)n;\r
+\r
+    #pragma omp parallel\r
+       {\r
+       double xs;\r
+       const int TID = OmpTools::getTid();\r
+       int s = TID;\r
+\r
+       while (s < n)\r
+           {\r
+           xs = s * DX;\r
+           tabSums[TID] += fpi(xs);\r
+\r
+           s += NB_THREAD;\r
+           }\r
+       }\r
+\r
+    double sum = 0;\r
+    for (int i = 0; i < NB_THREAD; i++)\r
+       sum += tabSums[i];\r
+\r
+    delete[] tabSums;\r
+\r
+    return sum * DX;\r
+    }\r
+\r
+/*----------------------------------------------------------------------*\\r
+ |*                    End                                             *|\r
+ \*---------------------------------------------------------------------*/\r
+\r