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