In this blog I will write about how I went about speeding up the rendering of an image using multi threading.

When I first ran the program, it took my system 58 seconds to render the image.

So I decided to do the rendering using spacial partitioning and enabled the use of multiple cores using OpenMP API. Using “#pragma omp parallel for” we can multi threading.

Instead of looping through every pixel, I decided to loop through every 3rd pixel to save time. The difference is render is minimal, but it saves up a lot of time. Then I created 4 different output values. 2 of them retrieved the color of the specified pixel and converted the pixel co-ordinates into camera co-ordinates.

The 3rd one averaged the RGB values of the first two output values and the 4th one averaged the RGB values with the first and the third.

After that, I just clamped the values into a 0–1 range, saturated the output values, and wrote the color to the image by scaling up by 255.

The final result was about 22 seconds faster than the original time taken to render the image.