How can I utilize all cores of CPU In my ray tracer with std::thread? I have been working on a ray tracer and I was trying to use multiple threads to maximize the performance. I tried couple of approaches but there's no difference in performance. Here's my shot...

void ray_tracer::render()
{
    #define USE_THREADS
    #ifdef USE_THREADS
        for (int threadIndex = 0; threadIndex &lt; mMaxThreads; ++threadIndex) {
            mThreads[threadIndex] = std::thread(&amp;ray_tracer::put_pixel_with_thread, this, threadIndex);
        }
        for (int threadIndex = 0; threadIndex &lt; mMaxThreads; ++threadIndex) {
            if (mThreads[threadIndex].joinable())
                mThreads[threadIndex].join();
        }
    #else
        put_pixel(); //uses single thread
    #endif

    stbi_write_bmp("result.bmp",mImageWidth,mImageHeight,3,mFrameBuffer);
}


and here's the put_pixel_with_thread(int)...

void ray_tracer::put_pixel_with_thread(int threadIndex)
{
    for (int row = 0; row &lt;mImageHeight; ++row)
    {
        for (int col = int((threadIndex / mMaxThreads)*mImageWidth);
            col &lt; int(((threadIndex + 1) / mMaxThreads)*mImageWidth);
            ++col)
        {
            int index = ((row * mImageWidth) + col) * 3;

            mFrameBuffer[index] = 0;
            mFrameBuffer[index + 1] = 0;
            mFrameBuffer[index + 2] = 244;
        }
    }
}


As you can see in put_pixel_with_threads(int) that I tried to split the row for each thread. I don't know what am i doing wrong. I am working on intel i5 6th gen which has 2 hyper-threaded cores. Please help. 

Thanks.
This is not really a CG issue but you appear to have an integer division problem. Assuming mMaxThreads is an integer,  (threadIndex / mMaxThreads) is always 0 and ((threadIndex + 1) / mMaxThreads) is 0 for all threads but the last one, where it is 1. So one thread is doing all the work.