Ajout de l'ensemble du workspace.
[GPU.git] / WCudaMSE / Student_OMP / src / cpp / core / omp / 02_pi / 08_pi_for_reduction.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 /*--------------------------------------*\
16 |* Public *|
17 \*-------------------------------------*/
18
19 bool isPiOMPforReduction_Ok(int n);
20
21 /*--------------------------------------*\
22 |* Private *|
23 \*-------------------------------------*/
24
25 static double piOMPforReduction(int n);
26
27 /*----------------------------------------------------------------------*\
28 |* Implementation *|
29 \*---------------------------------------------------------------------*/
30
31 /*--------------------------------------*\
32 |* Public *|
33 \*-------------------------------------*/
34
35 bool isPiOMPforReduction_Ok(int n)
36 {
37 return isAlgoPI_OK(piOMPforReduction, n, "Pi OMP for reduction-integrer");
38 }
39
40 /*--------------------------------------*\
41 |* Private *|
42 \*-------------------------------------*/
43
44 /**
45 * pattern omp usefull : idem desyncronisation-promotionTab ,mais avec syntaxe plus courte!
46 * Si on enleve le pragma, le code est le meme que le sequentiel!
47 */
48 double piOMPforReduction(int n)
49 {
50 double sum = 0;
51 double xi;
52 const double DX = 1.0/(double)n;
53
54 #pragma omp parallel for private(xi) reduction(+:sum)
55 for (int i = 0; i < n; i++)
56 {
57 xi = i*DX;
58 sum += fpi(xi);
59 }
60
61 return sum * DX;
62 }
63
64
65
66
67 /*----------------------------------------------------------------------*\
68 |* End *|
69 \*---------------------------------------------------------------------*/
70