我正在尝试在 Mac 上使用 openmp 并行化程序,但我无法使其成为多线程。
我尝试从源代码(在 svn co 之后)构建 llvm/clang/openmp 3.7.1 作为有记录的,我也尝试过使用llvm 项目提供的 clang 和 OpenMP 3.7.0 的预构建版本。
在每种情况下,生成的编译器都可以与 -fopenmp 标志一起正常工作,并生成链接到 openmp 运行时的可执行文件。
我使用以下 openmp 'hello world' 程序:
#include <omp.h>
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char *argv[]) {
int nthreads, tid;
/* Fork a team of threads giving them their own copies of variables */
#pragma omp parallel private(nthreads, tid)
{
/* Obtain thread number */
tid = omp_get_thread_num();
printf("Hello World from thread = %d\n", tid);
/* Only master thread does this */
if (tid == 0)
{
nthreads = omp_get_num_threads();
printf("Number of threads = %d\n", nthreads);
}
} /* All threads join master thread and disband */
}
我编译使用:
clang -fopenmp hello.c -o hello
然后运行生成的程序:
env OMP_NUM_THREADS=2 ./hello
这使:
Hello World from thread = 0
Number of threads = 1
任何想法?
clang = 3.8.0 还支持 -fopenmp (也可以使用 -fopenmp=libomp)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)