【问题标题】:Visual C++ has only one thread working (OpenMP)Visual C++ 只有一个线程工作 (OpenMP)
【发布时间】:2015-10-17 08:41:34
【问题描述】:

我有一个用于多线程应用程序的简单代码,但无论我传递多少线程,它都只使用一个线程执行。最初,我认为这是我的计算机的问题,但我尝试了另一台,它也没有工作。我有什么不对吗?如果有帮助,我正在使用 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';
    }
}

【问题讨论】:

    标签: c++ multithreading visual-c++ openmp


    【解决方案1】:

    您是否在项目属性对话框中激活了 OpenMP 支持? 您可以在“配置属性 -> C/C++ -> 语言”下找到它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-28
      • 1970-01-01
      • 2023-04-01
      相关资源
      最近更新 更多