Ajout de l'ensemble du workspace.
[GPU.git] / WCudaMSE / Student_OMP / src / cpp / core / omp / 02_pi / 02_pi_entrelacer_promotionTab.cpp
1 #include <omp.h>
2 #include "00_pi_tools.h"
3 #include "OmpTools.h"
4
5 /*----------------------------------------------------------------------*\
6 |* Declaration *|
7 \*---------------------------------------------------------------------*/
8
9 /*--------------------------------------*\
10 |* Imported *|
11 \*-------------------------------------*/
12
13
14 /*--------------------------------------*\
15 |* Public *|
16 \*-------------------------------------*/
17
18 bool isPiOMPEntrelacerPromotionTab_Ok(int n);
19
20 /*--------------------------------------*\
21 |* Private *|
22 \*-------------------------------------*/
23
24 static double piOMPEntrelacerPromotionTab(int n);
25
26 /*----------------------------------------------------------------------*\
27 |* Implementation *|
28 \*---------------------------------------------------------------------*/
29
30 /*--------------------------------------*\
31 |* Public *|
32 \*-------------------------------------*/
33
34 bool isPiOMPEntrelacerPromotionTab_Ok(int n)
35 {
36 return isAlgoPI_OK(piOMPEntrelacerPromotionTab, n, "Pi OMP Entrelacer promotionTab");
37 }
38
39 /*--------------------------------------*\
40 |* Private *|
41 \*-------------------------------------*/
42
43 /**
44 * pattern cuda : excellent!
45 */
46 double piOMPEntrelacerPromotionTab(int n)
47 {
48 const int NB_THREAD = OmpTools::setAndGetNaturalGranularity();
49
50 double* tabSums = new double[NB_THREAD];
51
52 const double DX = 1.0/(double)n;
53
54 #pragma omp parallel
55 {
56 double xs;
57 const int TID = OmpTools::getTid();
58 int s = TID;
59
60 while (s < n)
61 {
62 xs = s * DX;
63 tabSums[TID] += fpi(xs);
64
65 s += NB_THREAD;
66 }
67 }
68
69 double sum = 0;
70 for (int i = 0; i < NB_THREAD; i++)
71 sum += tabSums[i];
72
73 delete[] tabSums;
74
75 return sum * DX;
76 }
77
78 /*----------------------------------------------------------------------*\
79 |* End *|
80 \*---------------------------------------------------------------------*/
81