C++ visualc&x2B+;只有一个线程工作(OpenMP)
我有一个多线程应用程序的简单代码,但不管我传递了多少线程,它都只使用一个线程执行。起初,我以为这是我的电脑出了问题,但我试了另一台,它也不起作用。我做错什么了吗?如果有帮助的话,我正在使用Visual Studio 2015C++ visualc&x2B+;只有一个线程工作(OpenMP),c++,multithreading,visual-c++,openmp,C++,Multithreading,Visual C++,Openmp,我有一个多线程应用程序的简单代码,但不管我传递了多少线程,它都只使用一个线程执行。起初,我以为这是我的电脑出了问题,但我试了另一台,它也不起作用。我做错什么了吗?如果有帮助的话,我正在使用Visual Studio 2015 int th_id, nthreads; #pragma omp parallel private(th_id) shared(nthreads) num_threads(3) { th_id = omp_get_thread_num(); #pragma
int th_id, nthreads;
#pragma omp parallel private(th_id) shared(nthreads) num_threads(3)
{
th_id = omp_get_thread_num();
#pragma omp critical
{
cout << "Hello World from thread " << th_id << '\n';
}
#pragma omp barrier
#pragma omp master
{
nthreads = omp_get_num_threads();
cout << "There are " << nthreads << " threads" << '\n';
}
}
int th_id,n个字符;
#pragma omp并行专用(th_id)共享(nthreads)num_线程(3)
{
th_id=omp_get_thread_num();
#pragma-omp-critical
{
您是否在“项目属性”对话框中激活了OpenMP支持?
您可以在“配置属性->C/C++->语言”下找到它