【发布时间】:2015-01-14 20:20:14
【问题描述】:
我有以下程序:
#include <omp.h>
#include <stdio.h>
int main() {
omp_set_num_threads(4);
#pragma omp parallel
printf("Hello from thread %d, nthreads %d\n", omp_get_thread_num(), omp_get_num_threads());
}
我用clang -fopenmp 编译它并得到输出
Hello from thread 0, nthreads 1
显然没有调用设置线程数函数。有没有人知道为什么会发生这种情况?
clang 版本(使用 apt-get 安装):
Ubuntu clang version 3.5.0-4ubuntu2 (tags/RELEASE_350/final) (based on LLVM 3.5.0)
Target: x86_64-pc-linux-gnu
Thread model: posix
编辑:我还尝试将环境变量 OMP_NUM_THREADS 设置为 4。
EDIT2:我还为 OpenMP 安装了 Intel 运行时。
【问题讨论】:
-
你在使用 gcc 吗?如果是这样,你传递了什么标志,必须传递
-fopenmp才能使用 OpemMP。 -
您是否导出了此处使用部分中指定的环境变量? clang-omp.github.io
标签: c multithreading clang openmp