8240aa347fd08c151cd11eb3c7392faad0989bd9
[GPU.git] / WCudaMSE / Student_OMP / src / cpp / core / omp / 02_pi / 07_pi_for_promotionTab.cpp
1 #include <omp.h>
2 #include "00_pi_tools.h"
3 #include "MathTools.h"
4 #include "OmpTools.h"
5
6
7 /*----------------------------------------------------------------------*\
8 |* Declaration *|
9 \*---------------------------------------------------------------------*/
10
11 /*--------------------------------------*\
12 |* Imported *|
13 \*-------------------------------------*/
14
15
16
17 /*--------------------------------------*\
18 |* Public *|
19 \*-------------------------------------*/
20
21 bool isPiOMPforPromotionTab_Ok(int n);
22
23 /*--------------------------------------*\
24 |* Private *|
25 \*-------------------------------------*/
26
27 static double piOMPforPromotionTab(int n);
28 static void syntaxeSimplifier(double* tabSumThread,int n);
29 static void syntaxeFull(double* tabSumThread,int n);
30
31 /*----------------------------------------------------------------------*\
32 |* Implementation *|
33 \*---------------------------------------------------------------------*/
34
35 /*--------------------------------------*\
36 |* Public *|
37 \*-------------------------------------*/
38
39 bool isPiOMPforPromotionTab_Ok(int n)
40 {
41 return isAlgoPI_OK(piOMPforPromotionTab, n, "Pi OMP for promotion tab");
42 }
43
44 /*--------------------------------------*\
45 |* Private *|
46 \*-------------------------------------*/
47
48 /**
49 * De-synchronisation avec PromotionTab
50 */
51 double piOMPforPromotionTab(int n)
52 {
53 double xi;
54 const int NB_THREAD = OmpTools::setAndGetNaturalGranularity();
55 const double DX = 1.0/(double)n;
56
57 double sums[NB_THREAD];
58 memset(sums, 0, sizeof(sums)); // TODO
59
60 #pragma omp parallel for private(xi)
61 for (int i = 0; i < n; i++)
62 {
63 const int TID = OmpTools::getTid();
64 xi = i * DX;
65 sums[TID] += fpi(xi);
66 }
67
68 double sum = 0;
69 for (int i = 0; i < NB_THREAD; i++)
70 sum += sums[i];
71
72 return sum * DX;
73 }
74
75
76
77 /*----------------------------------------------------------------------*\
78 |* End *|
79 \*---------------------------------------------------------------------*/
80