私の光線追跡器は現在マルチスレッド化されています。基本的には、画像をシステムと同じ数のチャンクに分割し、それらを平行にレンダリングします。ただし、すべてのチャンクが同じレンダリング時間を持つわけではないため、ほとんどの場合、実行時間の半分は50%のCPU使用率です。私は16×16チャンクまたは類似した何かに画像を分割し、paralellyそれらをレンダリングするので、各チャンクがレンダリングされる後に、その次とのスレッド切り替えたい16x16チャンクでの平行光線追跡
std::shared_ptr<bitmap_image> image = std::make_shared<bitmap_image>(WIDTH, HEIGHT);
auto nThreads = std::thread::hardware_concurrency();
std::cout << "Resolution: " << WIDTH << "x" << HEIGHT << std::endl;
std::cout << "Supersampling: " << SUPERSAMPLING << std::endl;
std::cout << "Ray depth: " << DEPTH << std::endl;
std::cout << "Threads: " << nThreads << std::endl;
std::vector<RenderThread> renderThreads(nThreads);
std::vector<std::thread> tt;
auto size = WIDTH*HEIGHT;
auto chunk = size/nThreads;
auto rem = size % nThreads;
//launch threads
for (unsigned i = 0; i < nThreads - 1; i++)
{
tt.emplace_back(std::thread(&RenderThread::LaunchThread, &renderThreads[i], i * chunk, (i + 1) * chunk, image));
}
tt.emplace_back(std::thread(&RenderThread::LaunchThread, &renderThreads[nThreads-1], (nThreads - 1)*chunk, nThreads*chunk + rem, image));
for (auto& t : tt)
t.join();
...これcpuの使用量と実行時間が大幅に増加します。
レイ・トレーサは、これらの16x16チャンクをマルチスレッド方式でレンダリングするように設定するにはどうすればよいですか?
何が問題なのですか? –
私の質問は、16x16チャンクに分割してスレッドにキューする方法です。 –