New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multi-threading for C++ #2

Merged
merged 1 commit into from Oct 3, 2013

Conversation

Projects
None yet
2 participants
@t-mat
Contributor

t-mat commented Oct 3, 2013

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 added a commit that referenced this pull request Oct 3, 2013

Merge pull request #2 from t-mat/cpp-multithread
add multi-threading for c++

@kidoman kidoman merged commit 570c750 into kidoman:master Oct 3, 2013

@kidoman

This comment has been minimized.

Show comment
Hide comment
@kidoman

kidoman Oct 3, 2013

Owner

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

Owner

kidoman commented Oct 3, 2013

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

@kidoman

This comment has been minimized.

Show comment
Hide comment
@kidoman

kidoman Oct 3, 2013

Owner

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

Owner

kidoman commented Oct 3, 2013

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

@t-mat

This comment has been minimized.

Show comment
Hide comment
@t-mat

t-mat Oct 3, 2013

Contributor

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.

Contributor

t-mat commented Oct 3, 2013

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

This comment has been minimized.

Show comment
Hide comment
@kidoman

kidoman Oct 4, 2013

Owner

Oh alright

Owner

kidoman commented Oct 4, 2013

Oh alright

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment