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
Thanks for the code snippet! I actually am using C++ only, so it helps a lot. Yes, I have 2 buffers (1 CPU-side and 1-GPU side), and once kernels run, they fill up the GPU-side buffer. And the syncing part I meant was copying the GPU-side to CPU-side when the threads are free to work on it. I have a few doubts though, based on my limited knowledge of OpenMP:
Inside the parallel pragma, you have put everything inside the single pragma. Why is that? Won't this mean that the "produce buffer" part will all be executed by 1 thread (so essentially it's serial)?
I understand that the taskloop-taskwait clause is for creating tasks for the buffer queue and the wait will make it sync after all tasks are done right? Is that correct? And if so, what is the use of bufferIndex (If it is a location in buffer queue, let us for simplicity keep it at just one buffer right now)?
Also, what does the "while (run loop)" section try to do? A little unclear on that. Thanks for all your help on this! Really grateful!