openMP and audio callback

General OpenMP discussion

openMP and audio callback

Postby yann » Sat Feb 23, 2008 11:22 pm

How to use efficiently openMP in an audio callback ?

Many audio applications are based on callbacks (Jack applications for example). I am trying to parallelize the inside of such callback but the result is very inefficient. Here is a very simplified example of what I am doing :
Code: Select all
   void compute (int fullcount, float** input, float** output) {
      for (int index = 0; index < fullcount; index += 1024 {
         int count = min (1024, fullcount-index);
         float* input0 = &input[0][index];
         float* input1 = &input[1][index];
         float* output0 = &output[0][index];
         float* output1 = &output[1][index];
         #pragma omp parallel
         {
            #pragma omp sections
            {
               #pragma omp section
               for (int i=0; i<count; i++) {
                  output0[i] = (0.200000f * input0[i]);
               }
               #pragma omp section
               for (int i=0; i<count; i++) {
                  output1[i] = (0.800000f * input1[i]);
               }
            }
         }
      }
   }



My understanding of the unefficiency (but I am new to openMP) is that threads are created every time the callback is called.

How can I avoid that ?

Thanks
yann
 
Posts: 2
Joined: Sat Feb 23, 2008 10:53 pm

Re: openMP and audio callback

Postby ejd » Sun Feb 24, 2008 9:58 am

Most implementations now assume that if a user is going to use OpenMP, they are going to use it for more than one parallel region. As such, once the threads are created, they are generally not released, but kept around and re-used. That saves on the overhead of re-creating them for each region. So the original creation of the threads has the highest overhead and can be done by the implementation either during program initialization or during the first parallel region. After that, it is usually just the overhead of taking the threads off of a queue and assigning them work.

That said, there is obviously still some overhead each time a parallel region is entered and exited. Even the best implementations I have seen so far, have enough overhead, that the work done in the region has to be pretty "large" to overcome the expense of the overhead. In your example, the work is fairly small - one multiplication and assignment done a maximum of 1024 times. I am afraid that with that amount of work you are never going to see it as being very "efficient".
ejd
 
Posts: 1025
Joined: Wed Jan 16, 2008 7:21 am

Re: openMP and audio callback

Postby yann » Sun Feb 24, 2008 9:44 pm

Thanks for your reply. The example was very simplified to be short enough to fit the post. Real life audio applications can be enough demanding to be parallelized with profit.

But, as you confirm it, the creation of the threads should be made once, outside the callback. It is still unclear to me how to do that with OpenMP. How can I preallocate the threads outside the callback to minimize the overhead inside the callback ? Do I have a possibility to specify at the begin of the callback to use an existing pool of preallocated threads ? Or OpenMP inside a callback his just a bad idea and I should look for another design ?
yann
 
Posts: 2
Joined: Sat Feb 23, 2008 10:53 pm

Re: openMP and audio callback

Postby ejd » Mon Feb 25, 2008 5:15 am

I am sorry that my answer wasn't clear enough. There is no way in OpenMP to control when the threads are created or whether they are reused or destroyed and recreated for each parallel region. This is all implementation controlled and as such you need to talk to whomever wrote the compiler and runtime you are using. If you post that information here, you might get an answer, but there is no guarantee. The forums are for user discussion and are not monitored by the OpenMP ARB members.
ejd
 
Posts: 1025
Joined: Wed Jan 16, 2008 7:21 am


Return to Using OpenMP

Who is online

Users browsing this forum: Exabot [Bot], Majestic-12 [Bot] and 4 guests

cron