From 23b2d8939528bd44a40702482ef50d7b8c063254 Mon Sep 17 00:00:00 2001 From: Keuin Date: Sun, 17 Apr 2022 18:21:41 +0800 Subject: Configurable thread count. --- aa.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/aa.h b/aa.h index acdbc88..769eb31 100644 --- a/aa.h +++ b/aa.h @@ -18,9 +18,11 @@ template class aa_viewport : public viewport { unsigned samples; std::vector> *subviews; + int threads; public: - aa_viewport(double width, double height, vec3d viewport_center, unsigned samples) : samples(samples) { + aa_viewport(double width, double height, vec3d viewport_center, unsigned samples, int threads = -1) + : samples(samples), threads{(threads > 0) ? threads : (int)std::thread::hardware_concurrency()} { assert(samples >= 1); subviews = new std::vector>{samples, {width, height, viewport_center}}; } @@ -31,9 +33,9 @@ public: virtual bitmap render(const hitlist &world, vec3d viewpoint, uint16_t image_width, uint16_t image_height) { static constexpr auto seed = 123456789012345678ULL; - const unsigned thread_count = std::min(std::thread::hardware_concurrency(), samples); + const unsigned thread_count = std::min((unsigned)threads, samples); std::cerr << "Preparing tasks..." << std::endl; - std::vector> images{samples, {0,0}}; + std::vector> images{samples, {0, 0}}; std::mt19937_64 seedgen{seed}; // generates seeds for workers const struct s_render_shared { -- cgit v1.2.3