【发布时间】:2021-06-07 00:32:36
【问题描述】:
我在 Linux 终端上使用 OpenMP。我用标志-fopenmp 编译我的程序。我使用的环境确实支持多线程。
#pragma omp parallel num_threads(3)
{
#pragma omp task
R11Inverted = compute_inverse(r11, half);
#pragma omp task
printf("5 I am thread # %d\n", omp_get_thread_num());
R22Inverted = compute_inverse(r22, half);
}
作为一个简单且最少的测试,我要做的就是获取printf("5 I am thread # %d\n", omp_get_thread_num()); 以显示程序正在以三个线程运行。基本上omp_get_thread_num() 应该返回值 0、1 或 2。
The Output 上面的代码块被重复调用了很多次。然而,每次的结果都显示线程不工作,程序只使用一个线程(线程 0)。
【问题讨论】:
标签: c++ c multithreading parallel-processing openmp