1

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?

3
  • you need to define an environment of parallel tasks e.g. started with "#pragma omp parallel" followed by "#pragma omp single nowait". Commented May 30, 2018 at 12:53
  • @Bort like this? #pragma omp parallel { #pragma omp single { %code% } } Commented May 30, 2018 at 13:03
  • E.g. yes. See your error code here. Although, I don't know about supported openmp versions in visual studio. So acraig5075 might be right and it won't work anyways. Commented May 30, 2018 at 14:18

1 Answer 1

6

Visual C++ supports the OpenMP 2.0 standard.

OpenMP introduced tasks with OpenMP 3.0

i.e. It's unsupported.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.