Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ visualc&x2B+;只有一个线程工作(OpenMP)_C++_Multithreading_Visual C++_Openmp - Fatal编程技术网

C++ visualc&x2B+;只有一个线程工作(OpenMP)

C++ 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

我有一个多线程应用程序的简单代码,但不管我传递了多少线程,它都只使用一个线程执行。起初,我以为这是我的电脑出了问题,但我试了另一台,它也不起作用。我做错什么了吗?如果有帮助的话,我正在使用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 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++->语言”下找到它