- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I want to make a thread explicitly. Is there any OpenMP construct or way to do this.
Suppose at every loop iteration i want to make another team of threads after checking a condition in the loop body. can i do this....or it is illegal!!! how???
Suppose at every loop iteration i want to make another team of threads after checking a condition in the loop body. can i do this....or it is illegal!!! how???
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Why? Making new threads takes a lot of instructions. Doing so for every loop iteration could be really slow. And if the work the threads have to do has any duration, the number of threads will quickly explode and potentially lock up the system with oversubscription.
Perhaps you could talkmore about what it is you would like to do, and someone might be able to suggest a useful approach.
Perhaps you could talkmore about what it is you would like to do, and someone might be able to suggest a useful approach.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Here is the pseudocode that I think would do what you want:
[bash]for (int i=0; i!=n; ++i) { int my_condition = ... #pragma omp parallel num_threads(2) if(my_condition) { do_something(); } } [/bash]
When the variable my_condition is TRUE, you will get two threads executing do_something(). When my_condition is FALSE, you will get only a single thread executing do_something(). This is assuming you want all of the iterations of the loop to happen serially.
Please be aware that forking a new thread at the pragma could take up to a couple thousand cycles, so only do this if you have enough work in do_something() that this cost is small.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is nested parallelism possible using if conditions?

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page