kidoman / rays

Ray tracing based language benchmarks
https://kidoman.com/programming/go-getter.html
95 stars 23 forks source link

Add multi-threading for C++ #2

Closed t-mat closed 10 years ago

t-mat commented 10 years ago

If you use g++, please add -std=c++11 -pthread to your command line option.

g++ -std=c++11 -pthread -O3 rays.cpp
./a.out > rays.ppm
kidoman commented 10 years ago

Thanks for the PR... nice to learn this feature of C++ :)

kidoman commented 10 years ago

Is it possible to have this use 1 vs N cores programmatically?

t-mat commented 10 years ago

Yes, and no.

1 thread : yes

You can achieve 'single thread mode' by the following change :

-   wg.push_back(std::async(std::launch::async, [&, y](unsigned int seed) {
+   wg.push_back(std::async(std::launch::deferred, [&, y](unsigned int seed) {

see also

N threads : no

But for now there is no convenient and standard way to limit the maximum amount of threads.

You can achive the feature by thread pool or std::condition_variable, but I think it is too much complicated for this kind of simple project.

kidoman commented 10 years ago

Oh alright