Ajout de l'ensemble du workspace.
[GPU.git] / WCudaMSE / Student_OMP / src / cpp / core / omp / 02_pi / 03_pi_entrelacer_critique.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 |* Public *|
15 \*-------------------------------------*/
16
17 bool isPiOMPEntrelacerCritical_Ok(int n);
18
19 /*--------------------------------------*\
20 |* Private *|
21 \*-------------------------------------*/
22
23 static double piOMPEntrelacerCritical(int n);
24
25 /*----------------------------------------------------------------------*\
26 |* Implementation *|
27 \*---------------------------------------------------------------------*/
28
29 /*--------------------------------------*\
30 |* Public *|
31 \*-------------------------------------*/
32
33 bool isPiOMPEntrelacerCritical_Ok(int n)
34 {
35 return isAlgoPI_OK(piOMPEntrelacerCritical, n, "Pi OMP Entrelacer critical");
36 }
37
38 /*--------------------------------------*\
39 |* Private *|
40 \*-------------------------------------*/
41
42 double piOMPEntrelacerCritical(int n)
43 {
44 const int NB_THREAD = OmpTools::setAndGetNaturalGranularity();
45 const double DX = 1.0/(double)n;
46 double sum = 0;
47
48 #pragma omp parallel
49 {
50 double xs;
51 double sumLocalThread = 0;
52 const int TID = OmpTools::getTid();
53 int s = TID;
54
55 while (s < n)
56 {
57 xs = s * DX;
58 sumLocalThread += fpi(xs);
59 s += NB_THREAD;
60 }
61
62 #pragma omp critical(sum_fpi)
63 sum += sumLocalThread;
64
65 }
66
67 return sum * DX;
68 }
69
70 /*----------------------------------------------------------------------*\
71 |* End *|
72 \*---------------------------------------------------------------------*/
73