Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to learn OMP library task based programming and as an example I copied and pasted the code below taken from a book and it outputs errors

 'task' : expected an OpenMP directive name  

and

 'taskwait' : expected an OpenMP directive name

I can run omp parallel for loops but not tasks. Do you know whether omp tasking needs any further adjustments in visual studio?

 #include "stdafx.h"
 #include <omp.h>

 int fib(int n)
 {
   int i, j;
   if (n<2)
    return n;
 else
 {
   #pragma omp task shared(i) firstprivate(n)
   i=fib(n-1);

   #pragma omp task shared(j) firstprivate(n)
   j=fib(n-2);

   #pragma omp taskwait
   return i+j;
 }
 }

 int main()
{
  int n = 10;

  omp_set_dynamic(0);
  omp_set_num_threads(4);

  #pragma omp parallel shared(n)
  {
     #pragma omp single
     printf ("fib(%d) = %d
", n, fib(n));
  }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.3k views
Welcome To Ask or Share your Answers For Others

1 Answer

Unfortunately, even Visual Studio 2019 still only supports OpenMP 2.0, while Tasks were an OpenMP 3.0 addition and the current standard at the time of writing is 5.0.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...