haiJW08
haiJW08

Reputation: 11

error: expected '#pragma omp' clause before 'num_thread'

new to openmp. My environment as follows:

ubuntu 16.04TLS
gcc 7.3.0

My code as follows:

#include <omp.h>
#include <iostream>

int main()
{
    #pragma omp parallel num_thread(2)
    {
        std::cout << "Hello World!\n";
    }

    return 0;
}

and the command:

gcc -fopenmp main.cpp -o main

the error shows:

error: expected ‘#pragma omp’ clause before ‘num_thread’

#pragma omp parallel num_thread(2)

what should i do to solve this problem? Thx!

Upvotes: 0

Views: 3167

Answers (1)

asendjasni
asendjasni

Reputation: 1074

If you want to explicitly specify the number of threads in OpenMP you have to use num_threads() with an s:

#include <omp.h>
#include <iostream>

int main()
{
    #pragma omp parallel num_threads(2)
    {
        std::cout << "Hello World!\n";
    }

    return 0;
}

Upvotes: 3

Related Questions