Implémentation de RipplingMOO (entralecement + auto-for).
authorgburri <gregory.burri@master.hes-so.ch>
Wed, 1 Oct 2014 20:51:52 +0000 (22:51 +0200)
committergburri <gregory.burri@master.hes-so.ch>
Wed, 1 Oct 2014 20:51:52 +0000 (22:51 +0200)
WCudaMSE/Student_OMP_Image/src/cpp/core/01_Rippling/b_moo/RipplingMOO.cpp
WCudaMSE/Student_OMP_Image/src/cpp/core/01_Rippling/b_moo/RipplingMOO.h
WCudaMSE/Tuto_Image/src/cpp/core/01_Vague/b_moo/VagueMOO.cpp
WCudaMSE/Tuto_Image/src/cpp/core/01_Vague/b_moo/VagueMOO.h

index 94d1656..18f672d 100755 (executable)
-#include <iostream>\r
-#include <omp.h>\r
-\r
-#include "RipplingMOO.h"\r
-#include "OmpTools.h"\r
-\r
-#include "RipplingMath.h"\r
-\r
-using std::cout;\r
-using std::endl;\r
-using std::string;\r
-\r
-/*----------------------------------------------------------------------*\\r
- |*                    Declaration                                     *|\r
- \*---------------------------------------------------------------------*/\r
-\r
-/*--------------------------------------*\\r
- |*            Public                  *|\r
- \*-------------------------------------*/\r
-\r
-/*--------------------------------------*\\r
- |*            Private                 *|\r
- \*-------------------------------------*/\r
-\r
-/*----------------------------------------------------------------------*\\r
- |*                    Implementation                                  *|\r
- \*---------------------------------------------------------------------*/\r
-\r
-/*--------------------------------------*\\r
- |*            Public                  *|\r
- \*-------------------------------------*/\r
-\r
-RipplingMOO::RipplingMOO(unsigned int w, unsigned int h, float dt)\r
-    {\r
-    this->t=0;\r
-    this->dt=dt;\r
-    }\r
-\r
-RipplingMOO::~RipplingMOO(void)\r
-    {\r
-    // rien\r
-    }\r
-\r
-\r
-/*--------------------------------------*\\r
- |*            Public                  *|\r
- \*-------------------------------------*/\r
-\r
-void RipplingMOO::process(uchar4* ptrTabPixels, int w, int h)\r
-    {\r
-    if (isEntrelacement)\r
-       {\r
-       entrelacementOMP(ptrTabPixels); // Plus lent\r
-       }\r
-    else\r
-       {\r
-       forAutoOMP(ptrTabPixels);  // Plus rapide\r
-       }\r
-\r
-    isEntrelacement=!isEntrelacement;// Pour tester que les deux implementations fonctionnent\r
-    }\r
-\r
-\r
-void RipplingMOO::animationStep()\r
-    {\r
-    t+=dt;\r
-    }\r
-\r
-/*--------------*\\r
- |*    get     *|\r
- \*-------------*/\r
-\r
-float RipplingMOO::getT()\r
-    {\r
-    return t;\r
-    }\r
-\r
-/*--------------------------------------*\\r
- |*            Private                 *|\r
- \*-------------------------------------*/\r
-\r
-/**\r
- * Code entrainement Cuda\r
- */\r
-void RipplingMOO::entrelacementOMP(uchar4* ptrTabPixels)\r
-    {\r
-    // TODO\r
-    }\r
-\r
-/**\r
- * Code naturel et direct OMP\r
- */\r
-void RipplingMOO::forAutoOMP(uchar4* ptrTabPixels)\r
-    {\r
-    // TODO\r
-    }\r
-\r
-/*----------------------------------------------------------------------*\\r
- |*                    End                                             *|\r
- \*---------------------------------------------------------------------*/\r
+#include <iostream>
+#include <omp.h>
+
+#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                                             *|
+ \*---------------------------------------------------------------------*/
index 6e26b26..001faf7 100755 (executable)
@@ -1,60 +1,61 @@
-#ifndef RIPPLING_MOO_H_\r
-#define RIPPLING_MOO_H_\r
-\r
-#include "cudaType.h"\r
-\r
-/*----------------------------------------------------------------------*\\r
- |*                    Declaration                                     *|\r
- \*---------------------------------------------------------------------*/\r
-\r
-/*--------------------------------------*\\r
- |*            Public                  *|\r
- \*-------------------------------------*/\r
-\r
-class RipplingMOO\r
-    {\r
-\r
-       /*--------------------------------------*\\r
-       |*              Constructeur            *|\r
-        \*-------------------------------------*/\r
-\r
-    public:\r
-\r
-       RipplingMOO(unsigned int w, unsigned int h, float dt);\r
-       virtual ~RipplingMOO(void);\r
-\r
-       /*--------------------------------------*\\r
-       |*              Methode                 *|\r
-        \*-------------------------------------*/\r
-\r
-    public:\r
-\r
-       void process(uchar4* ptrTabPixels, int w, int h);\r
-       void animationStep();\r
-       float getT();\r
-\r
-    private:\r
-\r
-       void entrelacementOMP(uchar4* ptrTabPixels);    // Code entrainement Cuda\r
-       void forAutoOMP(uchar4* ptrTabPixels);          // Code naturel et direct OMP, plus performsnt\r
-\r
-       /*--------------------------------------*\\r
-       |*              Attribut                *|\r
-        \*-------------------------------------*/\r
-\r
-    private:\r
-\r
-       // Inputs\r
-       double dt;\r
-\r
-       // Tools\r
-       double t;\r
-       bool isEntrelacement;\r
-\r
-    };\r
-\r
-#endif\r
-\r
-/*----------------------------------------------------------------------*\\r
- |*                    End                                             *|\r
- \*---------------------------------------------------------------------*/\r
+#ifndef RIPPLING_MOO_H_
+#define RIPPLING_MOO_H_
+
+#include "cudaType.h"
+
+/*----------------------------------------------------------------------*\
+ |*                    Declaration                                     *|
+ \*---------------------------------------------------------------------*/
+
+/*--------------------------------------*\
+ |*            Public                  *|
+ \*-------------------------------------*/
+
+class RipplingMOO
+    {
+
+       /*--------------------------------------*\
+       |*              Constructeur            *|
+        \*-------------------------------------*/
+
+    public:
+
+       RipplingMOO(unsigned int w, unsigned int h, float dt);
+       virtual ~RipplingMOO(void);
+
+       /*--------------------------------------*\
+       |*              Methode                 *|
+        \*-------------------------------------*/
+
+    public:
+
+       void process(uchar4* ptrTabPixels, int w, int h);
+       void animationStep();
+       float getT();
+
+    private:
+
+       void entrelacementOMP(uchar4* ptrTabPixels);    // Code entrainement Cuda
+       void forAutoOMP(uchar4* ptrTabPixels);          // Code naturel et direct OMP, plus performsnt
+
+       /*--------------------------------------*\
+       |*              Attribut                *|
+        \*-------------------------------------*/
+
+    private:
+       const unsigned int w;
+       const unsigned int h;
+
+       // Inputs
+       const double dt;
+
+       // Tools
+       double t;
+       bool isEntrelacement;
+    };
+
+#endif
+
+/*----------------------------------------------------------------------*\
+ |*                    End                                             *|
+ \*---------------------------------------------------------------------*/
index 7a1e633..47e7198 100755 (executable)
-#include <iostream>\r
-#include <omp.h>\r
-#include <math.h>\r
-\r
-#include "VagueMOO.h"\r
-#include "VagueMath.h"\r
-\r
-#include "OmpTools.h"\r
-#include "IndiceTools.h"\r
-\r
-using std::cout;\r
-using std::endl;\r
-\r
-/*----------------------------------------------------------------------*\\r
- |*                    Declaration                                     *|\r
- \*---------------------------------------------------------------------*/\r
-\r
-/*--------------------------------------*\\r
- |*            Public                  *|\r
- \*-------------------------------------*/\r
-\r
-/*--------------------------------------*\\r
- |*            Private                 *|\r
- \*-------------------------------------*/\r
-\r
-/*----------------------------------------------------------------------*\\r
- |*                    Implementation                                  *|\r
- \*---------------------------------------------------------------------*/\r
-\r
-/*--------------------------------------*\\r
- |*            Public                  *|\r
- \*-------------------------------------*/\r
-\r
-VagueMOO::VagueMOO(unsigned int w, unsigned int h, float dt)\r
-    {\r
-    // Input\r
-    this->dt = dt;\r
-    this->w=w;\r
-\r
-\r
-    // Tools\r
-    this->t = 0;\r
-    this->isEntrelacement=true;\r
-\r
-\r
-    // OMP (facultatif)\r
-    const int NB_THREADS = OmpTools::setAndGetNaturalGranularity();\r
-    cout << "\n[VAGUE] nbThread = " << NB_THREADS << endl;\r
-    }\r
-\r
-VagueMOO::~VagueMOO(void)\r
-    {\r
-    // rien\r
-    }\r
-\r
-/*--------------------------------------*\\r
- |*            Public                  *|\r
- \*-------------------------------------*/\r
-\r
-void VagueMOO::process(uchar4* ptrTabPixels, int w, int h)\r
-    {\r
-    if (isEntrelacement)\r
-       {\r
-       entrelacementOMP(ptrTabPixels, w, h); // Plus lent\r
-       }\r
-    else\r
-       {\r
-       forAutoOMP(ptrTabPixels, w, h);  // Plus rapide\r
-       }\r
-\r
-    isEntrelacement = !isEntrelacement; // Pour tester que les deux implementations fonctionnent\r
-    }\r
-\r
-void VagueMOO::animationStep()\r
-    {\r
-    t+=dt;\r
-    }\r
-\r
-/*--------------*\\r
- |*    get     *|\r
- \*-------------*/\r
-\r
-float VagueMOO::getT()\r
-    {\r
-    return t;\r
-    }\r
-\r
-float VagueMOO::getDT()\r
-    {\r
-    return dt;\r
-    }\r
-\r
-/*--------------------------------------*\\r
- |*            Private                 *|\r
- \*-------------------------------------*/\r
-\r
-/**\r
- * Code naturel et direct OMP\r
- */\r
-void VagueMOO::forAutoOMP(uchar4* ptrTabPixels, int w, int h)\r
-    {\r
-    VagueMath vagueMath(w,h); // ici pour preparer cuda\r
-\r
-#pragma omp parallel for\r
-    for (int i = 0; i < h; i++)\r
-       {\r
-       for (int j = 0; j < w; j++)\r
-           {\r
-           // int s = i * W + j;\r
-           int s = IndiceTools::toS(w, i, j);    // i[0,H[ j[0,W[  --> s[0,W*H[\r
-\r
-           vagueMath.colorIJ(&ptrTabPixels[s], i, j,t);\r
-           }\r
-       }\r
-    }\r
-\r
-/**\r
- * Code entrainement Cuda\r
- */\r
-void VagueMOO::entrelacementOMP(uchar4* ptrTabPixels, int w, int h)\r
-    {\r
-    VagueMath vagueMath(w,h); // ici pour preparer cuda\r
-\r
-    const int WH = w * h;\r
-\r
-\r
-#pragma omp parallel\r
-       {\r
-       const int NB_THREAD = OmpTools::getNbThread();// dans region parallel\r
-       const int TID = OmpTools::getTid();\r
-       int s = TID; // in [0,...\r
-\r
-       int i;\r
-       int j;\r
-       while (s < WH)\r
-           {\r
-           IndiceTools::toIJ(s, w, &i, &j); // s[0,W*H[ --> i[0,H[ j[0,W[\r
-\r
-           vagueMath.colorIJ(&ptrTabPixels[s], i, j,t);\r
-\r
-           s += NB_THREAD;\r
-           }\r
-       }\r
-    }\r
-\r
-\r
-/*----------------------------------------------------------------------*\\r
- |*                    End                                             *|\r
- \*---------------------------------------------------------------------*/\r
-\r
+#include <iostream>
+#include <omp.h>
+#include <math.h>
+
+#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                                             *|
+ \*---------------------------------------------------------------------*/
+
index b0b862a..b13a900 100755 (executable)
@@ -1,63 +1,63 @@
-#ifndef VAGUE_MOO_H_\r
-#define VAGUE_MOO_H_\r
-\r
-#include "cudaType.h"\r
-\r
-\r
-/*----------------------------------------------------------------------*\\r
- |*                    Declaration                                     *|\r
- \*---------------------------------------------------------------------*/\r
-\r
-/*--------------------------------------*\\r
- |*            Public                  *|\r
- \*-------------------------------------*/\r
-\r
-class VagueMOO\r
-    {\r
-\r
-       /*--------------------------------------*\\r
-        |*             Constructeur            *|\r
-        \*-------------------------------------*/\r
-\r
-    public:\r
-\r
-       VagueMOO(unsigned int w, unsigned int h, float dt);\r
-       virtual ~VagueMOO(void);\r
-\r
-       /*--------------------------------------*\\r
-        |*             Methode                 *|\r
-        \*-------------------------------------*/\r
-\r
-    public:\r
-\r
-       void  process(uchar4* ptrTabPixels, int w, int h);\r
-       void animationStep();\r
-       float getT();\r
-       float getDT();\r
-\r
-    private:\r
-\r
-       // Balayage image\r
-       void entrelacementOMP(uchar4* ptrTabPixels,int w, int h);\r
-       void forAutoOMP(uchar4* ptrTabPixels,int w, int h);\r
-\r
-       /*--------------------------------------*\\r
-       |*              Attribut                *|\r
-        \*-------------------------------------*/\r
-\r
-    private:\r
-\r
-       // Inputs\r
-       double dt;\r
-       unsigned char w;\r
-\r
-       // Tools\r
-       double t;\r
-       bool isEntrelacement;\r
-    };\r
-\r
-#endif\r
-\r
-/*----------------------------------------------------------------------*\\r
- |*                    End                                             *|\r
- /*----------------------------------------------------------------------*/\r
+#ifndef VAGUE_MOO_H_
+#define VAGUE_MOO_H_
+
+#include "cudaType.h"
+
+
+/*----------------------------------------------------------------------*\
+ |*                    Declaration                                     *|
+ \*---------------------------------------------------------------------*/
+
+/*--------------------------------------*\
+ |*            Public                  *|
+ \*-------------------------------------*/
+
+class VagueMOO
+    {
+
+       /*--------------------------------------*\
+        |*             Constructeur            *|
+        \*-------------------------------------*/
+
+    public:
+
+       VagueMOO(unsigned int w, unsigned int h, float dt);
+       virtual ~VagueMOO(void);
+
+       /*--------------------------------------*\
+        |*             Methode                 *|
+        \*-------------------------------------*/
+
+    public:
+
+       void process(uchar4* ptrTabPixels, int w, int h);
+       void animationStep();
+       float getT();
+       float getDT();
+
+    private:
+
+       // Balayage image
+       void entrelacementOMP(uchar4* ptrTabPixels,int w, int h);
+       void forAutoOMP(uchar4* ptrTabPixels,int w, int h);
+
+       /*--------------------------------------*\
+       |*              Attribut                *|
+        \*-------------------------------------*/
+
+    private:
+
+       // Inputs
+       double dt;
+       unsigned char w;
+
+       // Tools
+       double t;
+       bool isEntrelacement;
+    };
+
+#endif
+
+/*----------------------------------------------------------------------*\
+ |*                    End                                             *|
+ /*----------------------------------------------------------------------*/