From a4ddfddbf3d2aca369a6ba0e844f1d5ae12df2c9 Mon Sep 17 00:00:00 2001 From: Godzil Date: Wed, 26 Feb 2020 16:09:28 +0000 Subject: [PATCH] Found the problem with openmp. X here need to be declared as private, else each thread are sharing the same variable which... well.... don't work well .. :/ --- source/camera.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/source/camera.cpp b/source/camera.cpp index 7630d14..4bfa1b2 100644 --- a/source/camera.cpp +++ b/source/camera.cpp @@ -62,14 +62,17 @@ Canvas Camera::render(World world, uint32_t depth) uint32_t x, y; Canvas image = Canvas(this->horizontalSize, this->verticalSize); - for(y = 0; y < this->verticalSize; y++) +#pragma omp parallel private(x, y) shared(image) { - #pragma omp parallel for - for(x = 0; x < this->horizontalSize; x++) +#pragma omp for + for (y = 0 ; y < this->verticalSize ; y++) { - Ray r = this->rayForPixel(x, y); - Tuple colour = world.colourAt(r, depth); - image.putPixel(x, y, colour); + for (x = 0 ; x < this->horizontalSize ; x++) + { + Ray r = this->rayForPixel(x, y); + Tuple colour = world.colourAt(r, depth); + image.putPixel(x, y, colour); + } } }