X-Git-Url: http://git.euphorik.ch/?p=GPU.git;a=blobdiff_plain;f=WCudaMSE%2FStudent_OMP_Image%2Fsrc%2Fcpp%2Fcore%2F01_Rippling%2Fb_moo%2FRipplingMOO.cpp;h=18f672dd232943d6e8a9f3764422f6092c67c8f9;hp=94d1656320997a567b135b14631cbcc41e5e572e;hb=1ad82fc988adf2f8837584ec26873953a83dc7b8;hpb=00e3a81161ef7d45c0a4eb7f212cd6522afea394 diff --git a/WCudaMSE/Student_OMP_Image/src/cpp/core/01_Rippling/b_moo/RipplingMOO.cpp b/WCudaMSE/Student_OMP_Image/src/cpp/core/01_Rippling/b_moo/RipplingMOO.cpp index 94d1656..18f672d 100755 --- a/WCudaMSE/Student_OMP_Image/src/cpp/core/01_Rippling/b_moo/RipplingMOO.cpp +++ b/WCudaMSE/Student_OMP_Image/src/cpp/core/01_Rippling/b_moo/RipplingMOO.cpp @@ -1,100 +1,124 @@ -#include -#include - -#include "RipplingMOO.h" -#include "OmpTools.h" - -#include "RipplingMath.h" - -using std::cout; -using std::endl; -using std::string; - -/*----------------------------------------------------------------------*\ - |* Declaration *| - \*---------------------------------------------------------------------*/ - -/*--------------------------------------*\ - |* Public *| - \*-------------------------------------*/ - -/*--------------------------------------*\ - |* Private *| - \*-------------------------------------*/ - -/*----------------------------------------------------------------------*\ - |* Implementation *| - \*---------------------------------------------------------------------*/ - -/*--------------------------------------*\ - |* Public *| - \*-------------------------------------*/ - -RipplingMOO::RipplingMOO(unsigned int w, unsigned int h, float dt) - { - this->t=0; - this->dt=dt; - } - -RipplingMOO::~RipplingMOO(void) - { - // rien - } - - -/*--------------------------------------*\ - |* Public *| - \*-------------------------------------*/ - -void RipplingMOO::process(uchar4* ptrTabPixels, int w, int h) - { - if (isEntrelacement) - { - entrelacementOMP(ptrTabPixels); // Plus lent - } - else - { - forAutoOMP(ptrTabPixels); // Plus rapide - } - - isEntrelacement=!isEntrelacement;// Pour tester que les deux implementations fonctionnent - } - - -void RipplingMOO::animationStep() - { - t+=dt; - } - -/*--------------*\ - |* get *| - \*-------------*/ - -float RipplingMOO::getT() - { - return t; - } - -/*--------------------------------------*\ - |* Private *| - \*-------------------------------------*/ - -/** - * Code entrainement Cuda - */ -void RipplingMOO::entrelacementOMP(uchar4* ptrTabPixels) - { - // TODO - } - -/** - * Code naturel et direct OMP - */ -void RipplingMOO::forAutoOMP(uchar4* ptrTabPixels) - { - // TODO - } - -/*----------------------------------------------------------------------*\ - |* End *| - \*---------------------------------------------------------------------*/ +#include +#include + +#include "RipplingMOO.h" +#include "RipplingMath.h" + +#include "OmpTools.h" +#include "IndiceTools.h" + + +using std::cout; +using std::endl; +using std::string; + +/*----------------------------------------------------------------------*\ + |* Declaration *| + \*---------------------------------------------------------------------*/ + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +/*--------------------------------------*\ + |* Private *| + \*-------------------------------------*/ + +/*----------------------------------------------------------------------*\ + |* Implementation *| + \*---------------------------------------------------------------------*/ + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +RipplingMOO::RipplingMOO(unsigned int w, unsigned int h, float dt) + : w(w), h(h), t(0), dt(dt), isEntrelacement(false) + { + } + +RipplingMOO::~RipplingMOO(void) + { + // rien + } + + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +void RipplingMOO::process(uchar4* ptrTabPixels, int w, int h) // Pourquoi w et h ne sont pas utilisé?? + { + if (this->isEntrelacement)x + this->entrelacementOMP(ptrTabPixels); // Plus lent + else + this->forAutoOMP(ptrTabPixels); // Plus rapide + + this->isEntrelacement = ! this->isEntrelacement; // Pour tester que les deux implementations fonctionnent + } + + +void RipplingMOO::animationStep() + { + this->t += this->dt; + } + +/*--------------*\ + |* get *| + \*-------------*/ + +float RipplingMOO::getT() + { + return this->t; + } + +/*--------------------------------------*\ + |* Private *| + \*-------------------------------------*/ + +/** + * Code entrainement Cuda + */ +void RipplingMOO::entrelacementOMP(uchar4* ptrTabPixels) + { + RipplingMath ripplingMath(w,h); // ici pour preparer cuda + const int WH = w * h; + +#pragma omp parallel + { + const int NB_THREAD = OmpTools::getNbThread(); + const int TID = OmpTools::getTid(); + int s = TID; + + int i, j; + while (s < WH) + { + IndiceTools::toIJ(s, w, &i, &j); // s[0,W*H[ --> i[0,H[ j[0,W[ + ripplingMath.colorIJ(&ptrTabPixels[s], i, j,t); + s += NB_THREAD; + } + } + } + +/** + * Code naturel et direct OMP + */ +void RipplingMOO::forAutoOMP(uchar4* ptrTabPixels) + { + RipplingMath ripplingMath(w,h); // ici pour preparer cuda + +#pragma omp parallel for + for (int i = 0; i < h; i++) + { + for (int j = 0; j < w; j++) + { + // int s = i * W + j; + const int s = IndiceTools::toS(w, i, j); // i[0,H[ j[0,W[ --> s[0,W*H[ + ripplingMath.colorIJ(&ptrTabPixels[s], i, j,t); + } + } + } + +/*----------------------------------------------------------------------*\ + |* End *| + \*---------------------------------------------------------------------*/