X-Git-Url: http://git.euphorik.ch/?p=GPU.git;a=blobdiff_plain;f=WCudaMSE%2FTuto_Image%2Fsrc%2Fcpp%2Fcore%2F01_Vague%2Fb_moo%2FVagueMOO.cpp;h=47e7198e4fe4676f012f29dcbf684886f5839b23;hp=7a1e633495d558cb9f78b310913d8e56d50d24d7;hb=1ad82fc988adf2f8837584ec26873953a83dc7b8;hpb=00e3a81161ef7d45c0a4eb7f212cd6522afea394 diff --git a/WCudaMSE/Tuto_Image/src/cpp/core/01_Vague/b_moo/VagueMOO.cpp b/WCudaMSE/Tuto_Image/src/cpp/core/01_Vague/b_moo/VagueMOO.cpp index 7a1e633..47e7198 100755 --- a/WCudaMSE/Tuto_Image/src/cpp/core/01_Vague/b_moo/VagueMOO.cpp +++ b/WCudaMSE/Tuto_Image/src/cpp/core/01_Vague/b_moo/VagueMOO.cpp @@ -1,150 +1,148 @@ -#include -#include -#include - -#include "VagueMOO.h" -#include "VagueMath.h" - -#include "OmpTools.h" -#include "IndiceTools.h" - -using std::cout; -using std::endl; - -/*----------------------------------------------------------------------*\ - |* Declaration *| - \*---------------------------------------------------------------------*/ - -/*--------------------------------------*\ - |* Public *| - \*-------------------------------------*/ - -/*--------------------------------------*\ - |* Private *| - \*-------------------------------------*/ - -/*----------------------------------------------------------------------*\ - |* Implementation *| - \*---------------------------------------------------------------------*/ - -/*--------------------------------------*\ - |* Public *| - \*-------------------------------------*/ - -VagueMOO::VagueMOO(unsigned int w, unsigned int h, float dt) - { - // Input - this->dt = dt; - this->w=w; - - - // Tools - this->t = 0; - this->isEntrelacement=true; - - - // OMP (facultatif) - const int NB_THREADS = OmpTools::setAndGetNaturalGranularity(); - cout << "\n[VAGUE] nbThread = " << NB_THREADS << endl; - } - -VagueMOO::~VagueMOO(void) - { - // rien - } - -/*--------------------------------------*\ - |* Public *| - \*-------------------------------------*/ - -void VagueMOO::process(uchar4* ptrTabPixels, int w, int h) - { - if (isEntrelacement) - { - entrelacementOMP(ptrTabPixels, w, h); // Plus lent - } - else - { - forAutoOMP(ptrTabPixels, w, h); // Plus rapide - } - - isEntrelacement = !isEntrelacement; // Pour tester que les deux implementations fonctionnent - } - -void VagueMOO::animationStep() - { - t+=dt; - } - -/*--------------*\ - |* get *| - \*-------------*/ - -float VagueMOO::getT() - { - return t; - } - -float VagueMOO::getDT() - { - return dt; - } - -/*--------------------------------------*\ - |* Private *| - \*-------------------------------------*/ - -/** - * Code naturel et direct OMP - */ -void VagueMOO::forAutoOMP(uchar4* ptrTabPixels, int w, int h) - { - VagueMath vagueMath(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; - int s = IndiceTools::toS(w, i, j); // i[0,H[ j[0,W[ --> s[0,W*H[ - - vagueMath.colorIJ(&ptrTabPixels[s], i, j,t); - } - } - } - -/** - * Code entrainement Cuda - */ -void VagueMOO::entrelacementOMP(uchar4* ptrTabPixels, int w, int h) - { - VagueMath vagueMath(w,h); // ici pour preparer cuda - - const int WH = w * h; - - -#pragma omp parallel - { - const int NB_THREAD = OmpTools::getNbThread();// dans region parallel - const int TID = OmpTools::getTid(); - int s = TID; // in [0,... - - int i; - int j; - while (s < WH) - { - IndiceTools::toIJ(s, w, &i, &j); // s[0,W*H[ --> i[0,H[ j[0,W[ - - vagueMath.colorIJ(&ptrTabPixels[s], i, j,t); - - s += NB_THREAD; - } - } - } - - -/*----------------------------------------------------------------------*\ - |* End *| - \*---------------------------------------------------------------------*/ - +#include +#include +#include + +#include "VagueMOO.h" +#include "VagueMath.h" + +#include "OmpTools.h" +#include "IndiceTools.h" + +using std::cout; +using std::endl; + +/*----------------------------------------------------------------------*\ + |* Declaration *| + \*---------------------------------------------------------------------*/ + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +/*--------------------------------------*\ + |* Private *| + \*-------------------------------------*/ + +/*----------------------------------------------------------------------*\ + |* Implementation *| + \*---------------------------------------------------------------------*/ + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +VagueMOO::VagueMOO(unsigned int w, unsigned int h, float dt) + { + // Input + this->dt = dt; + this->w=w; + + + // Tools + this->t = 0; + this->isEntrelacement=true; + + + // OMP (facultatif) + const int NB_THREADS = OmpTools::setAndGetNaturalGranularity(); + cout << "\n[VAGUE] nbThread = " << NB_THREADS << endl; + } + +VagueMOO::~VagueMOO(void) + { + // rien + } + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +void VagueMOO::process(uchar4* ptrTabPixels, int w, int h) + { + if (isEntrelacement) + { + entrelacementOMP(ptrTabPixels, w, h); // Plus lent + } + else + { + forAutoOMP(ptrTabPixels, w, h); // Plus rapide + } + + isEntrelacement = !isEntrelacement; // Pour tester que les deux implementations fonctionnent + } + +void VagueMOO::animationStep() + { + t+=dt; + } + +/*--------------*\ + |* get *| + \*-------------*/ + +float VagueMOO::getT() + { + return t; + } + +float VagueMOO::getDT() + { + return dt; + } + +/*--------------------------------------*\ + |* Private *| + \*-------------------------------------*/ + + +/** + * Code entrainement Cuda + */ +void VagueMOO::entrelacementOMP(uchar4* ptrTabPixels, int w, int h) + { + VagueMath vagueMath(w,h); // ici pour preparer cuda + + const int WH = w * h; + +#pragma omp parallel + { + const int NB_THREAD = OmpTools::getNbThread();// dans region parallel + const int TID = OmpTools::getTid(); + int s = TID; // in [0,... + + int i; + int j; + while (s < WH) + { + IndiceTools::toIJ(s, w, &i, &j); // s[0,W*H[ --> i[0,H[ j[0,W[ + + vagueMath.colorIJ(&ptrTabPixels[s], i, j,t); + + s += NB_THREAD; + } + } + } + +/** + * Code naturel et direct OMP + */ +void VagueMOO::forAutoOMP(uchar4* ptrTabPixels, int w, int h) + { + VagueMath vagueMath(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; + int s = IndiceTools::toS(w, i, j); // i[0,H[ j[0,W[ --> s[0,W*H[ + + vagueMath.colorIJ(&ptrTabPixels[s], i, j,t); + } + } + } +/*----------------------------------------------------------------------*\ + |* End *| + \*---------------------------------------------------------------------*/ +