Implémentation de RipplingMOO (entralecement + auto-for).
[GPU.git] / WCudaMSE / Student_OMP_Image / src / cpp / core / 01_Rippling / b_moo / RipplingMOO.cpp
1 #include <iostream>
2 #include <omp.h>
3
4 #include "RipplingMOO.h"
5 #include "RipplingMath.h"
6
7 #include "OmpTools.h"
8 #include "IndiceTools.h"
9
10
11 using std::cout;
12 using std::endl;
13 using std::string;
14
15 /*----------------------------------------------------------------------*\
16 |* Declaration *|
17 \*---------------------------------------------------------------------*/
18
19 /*--------------------------------------*\
20 |* Public *|
21 \*-------------------------------------*/
22
23 /*--------------------------------------*\
24 |* Private *|
25 \*-------------------------------------*/
26
27 /*----------------------------------------------------------------------*\
28 |* Implementation *|
29 \*---------------------------------------------------------------------*/
30
31 /*--------------------------------------*\
32 |* Public *|
33 \*-------------------------------------*/
34
35 RipplingMOO::RipplingMOO(unsigned int w, unsigned int h, float dt)
36 : w(w), h(h), t(0), dt(dt), isEntrelacement(false)
37 {
38 }
39
40 RipplingMOO::~RipplingMOO(void)
41 {
42 // rien
43 }
44
45
46 /*--------------------------------------*\
47 |* Public *|
48 \*-------------------------------------*/
49
50 void RipplingMOO::process(uchar4* ptrTabPixels, int w, int h) // Pourquoi w et h ne sont pas utilisé??
51 {
52 if (this->isEntrelacement)x
53 this->entrelacementOMP(ptrTabPixels); // Plus lent
54 else
55 this->forAutoOMP(ptrTabPixels); // Plus rapide
56
57 this->isEntrelacement = ! this->isEntrelacement; // Pour tester que les deux implementations fonctionnent
58 }
59
60
61 void RipplingMOO::animationStep()
62 {
63 this->t += this->dt;
64 }
65
66 /*--------------*\
67 |* get *|
68 \*-------------*/
69
70 float RipplingMOO::getT()
71 {
72 return this->t;
73 }
74
75 /*--------------------------------------*\
76 |* Private *|
77 \*-------------------------------------*/
78
79 /**
80 * Code entrainement Cuda
81 */
82 void RipplingMOO::entrelacementOMP(uchar4* ptrTabPixels)
83 {
84 RipplingMath ripplingMath(w,h); // ici pour preparer cuda
85 const int WH = w * h;
86
87 #pragma omp parallel
88 {
89 const int NB_THREAD = OmpTools::getNbThread();
90 const int TID = OmpTools::getTid();
91 int s = TID;
92
93 int i, j;
94 while (s < WH)
95 {
96 IndiceTools::toIJ(s, w, &i, &j); // s[0,W*H[ --> i[0,H[ j[0,W[
97 ripplingMath.colorIJ(&ptrTabPixels[s], i, j,t);
98 s += NB_THREAD;
99 }
100 }
101 }
102
103 /**
104 * Code naturel et direct OMP
105 */
106 void RipplingMOO::forAutoOMP(uchar4* ptrTabPixels)
107 {
108 RipplingMath ripplingMath(w,h); // ici pour preparer cuda
109
110 #pragma omp parallel for
111 for (int i = 0; i < h; i++)
112 {
113 for (int j = 0; j < w; j++)
114 {
115 // int s = i * W + j;
116 const int s = IndiceTools::toS(w, i, j); // i[0,H[ j[0,W[ --> s[0,W*H[
117 ripplingMath.colorIJ(&ptrTabPixels[s], i, j,t);
118 }
119 }
120 }
121
122 /*----------------------------------------------------------------------*\
123 |* End *|
124 \*---------------------------------------------------------------------*/