vendredi 17 septembre 2021

this_thread / chrono has not been declared

I have checked many StackOverflow posts, but no answers solve my problem.

I get 2 errors:

g++ .\main.cpp -fopenmp -o test

.\main.cpp:12:14: error: 'std::this_thread' has not been declared
  12 |         std::this_thread::sleep_for(chrono::seconds(20000) );

.\main.cpp:12:37: error: 'chrono' has not been declared
  12 |         std::this_thread::sleep_for(chrono::seconds(20000) );

My current G++ version is:

g++.exe (MinGW.org GCC Build-2) 9.2.0

The code is:

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

int main()
{
    omp_set_num_threads(4);
    #pragma omp parallel
    {
        std::this_thread::sleep_for(chrono::seconds(20000) );
        std::cout << "Number of available threads: " << omp_get_num_threads() << std::endl;
        std::cout << "Current thread number: " << omp_get_thread_num() << std::endl;
        std::cout << "Hello, World!" << std::endl;
    }
    return 0;
}

I have already tried -std=c++11 from 11 & 14 & 17.

Aucun commentaire:

Enregistrer un commentaire