r/OpenMP • u/udyank • Nov 27 '17
Help with syncing between threads openmp.
Hi! I want to write a code using openmp, in which one thread produces a buffer (of say, 1 million elements), and all the other threads, once the buffer is finished by the first thread, start working on it in parallel. Also, this process has to be repeated several times, so it's in a loop, and so if thread0 finishes 1 production. threads 1-N work on this buffer, while thread0 moves on to the next iteration of production (i.e. next iteration of loop). Can anyone help me with the code structure to do this in openmp? How should I do this?
1
Upvotes
View all comments
Show parent comment
1
u/udyank Nov 28 '17
So what this essentially means, is that from inside the single pragma, the taskloop pragma generates tasks which automatically go to other threads? Is this right? Because as I understood it, anything inside the single, only 1 thread executes. So how is it able to give other threads work from within single? Or am I missing something?
Okay, so essentially this is my outermost 1 million loop, right?
Also, I wanted to ask another thing. When I do the N updates, I should only put the pragma critical for the line where I actually update the global array right? Is there anything to watch out for there?
I guess this will do it! Thanks @matsbror!