Bonjour tout le monde,
Alors voici mon problème, je suis entrain d'écrire une classe pour faire du traitement d'image, et je me suis lancé dans l'utilisation d'openMP pour la première fois. J'ai l'impression que les directives OpenMP que je donne dans ma classe ne sont pas prise en compte.
Code Image.h : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 class ImageGray { protected: PixelGray *_pixels; Int32 _height; Int32 _width; public: [...] void SetPixel(Int32 k, PixelGray value) { _pixels[k] = value; } void Negate(ImageGray & destination); };
Code Image.cpp : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 void ImageGray::Negate(ImageGray & destination) { destination.SetDimension(_width, _height); int size = _width * _height; #pragma omp parallel for for (int k = 0; k < size; k++) destination.SetPixel( k, ~_pixels[k] ); }
Code main.cpp : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 void Negate(ImageGray & source, ImageGray & destination) { double width = source.GetWidth(); double height = source.GetHeight(); destination.SetDimension(width, height); int size = width * height; #pragma omp parallel for for (int k = 0; k < size; k++) destination.SetPixel( k, ~source.GetPixel(k) ); } int main() { [...] // déclaration des variables if (LoadBitmapFile(image, "aletsch.bmp")) { /////////////////////////////////////////////////////// image.Negate(image2); // process time: 7.35ms SaveBitmapFile(image2, "test1.bmp"); /////////////////////////////////////////////////////// Negate(image, image2); // process time: 0.95ms SaveBitmapFile(image2, "test2.bmp"); } return 0; }
Si je place la fonction dans le main.cpp, la parallélisation est bien réalisée (8 thread =~ 8x plus rapide), je ne vois donc pas trop ce qu'il manque pour faire marcher la parallélisation dans ma classe...
Si quelqu'un a une idée pour m'aider à résoudre mon problème, c'est avec plaisir :p
A+
Faff
Partager