Here is my code:
#include <stdio.h>
#include <cstdlib>
#include <locale>
#include <omp.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
ll fib(int n) {
if (n <= 1)
return 1;
ll a, b;
#pragma omp task shared(a)
a = fib(n - 1);
#pragma omp task shared(b)
b = fib(n - 2);
#pragma omp taskwait
return a + b;
}
int main(int argc, char* argv[]) {
setlocale(LC_ALL, "");
int n;
scanf_s("%d", &n);
printf("Result: %lld\n", fib(n));
system("pause");
return 0;
}
Visual Studio returns C3001 error "task: OpenMP directive name required".
If I comment all the "pragma" it works fine, so there must be a problem with OpenMP. Some other program with "#pragma omp parallel" works fine, it's just the problem with the "task" directive.
What could be the problem?