0

I'm beginning in openMP and I try to use openMP in my code source. I have four functions and I would like to give for each thread one function. Here is my code:

  int a,b,c,d;
  omp_set_num_threads(4);
  #pragma omp parallel
  {
     a=SetHist1(int (Convert_Mask0(mask)),1);

     b=SetHist2(int (Convert_Mask45(mask)),1);

     c=SetHist3(int (Convert_Mask90(mask)),1);

     d=SetHist4(int (Convert_Mask135(mask)),1);
    }

but this does not work for me.

coincoin
  • 4,595
  • 3
  • 23
  • 47
amine
  • 651
  • 1
  • 7
  • 9

1 Answers1

2

You can use SECTIONS directives to make each SetHistX on different threads. You could also use TASK directives depending of your needs.

Differences of use between sections and tasks are available here.

Using sections directives, your code would look like something like this :

#pragma omp parallel sections
{
   #pragma omp section
   {
   a=SetHist1(int (Convert_Mask0(mask)),1);
   }
   #pragma omp section
   {
   b=SetHist2(int (Convert_Mask45(mask)),1);
   }
   #pragma omp section
   {
   c=SetHist3(int (Convert_Mask90(mask)),1);
   }
   #pragma omp section
   {
   d=SetHist4(int (Convert_Mask135(mask)),1);
   }
}
Community
  • 1
  • 1
coincoin
  • 4,595
  • 3
  • 23
  • 47