我查看了许多StackOverflow帖子,但没有答案解决我的问题。
我有两个错误:
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) );
我现在的G++版本是:
g++.exe (MinGW.org GCC Buil-2) 9.2.0
守则是:
#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;
}
我已经试过了11 & 14和17的-std=c++11
。
发布于 2021-09-17 20:45:07
我不确定它是对的,但是关于你的第二个错误,你能用
std::this_thread::sleep_for(chrono::seconds(20000) );
至
std::this_thread::sleep_for(std::chrono::seconds(20000));
我认为第一个错误取决于第二个错误,但我不确定。
https://stackoverflow.com/questions/69227735
复制相似问题