Multithreading openmp在我的mac上运行单线程
我试图在Mac上使用openmp并行化一个程序,但我无法使它成为多线程的。 我尝试过从源代码构建llvm/clang/openmp 3.7.1(在svn co之后),因为我也尝试过使用。 在每种情况下,生成的编译器都可以使用-fopenmp标志正常工作,并生成链接到openmp运行时的可执行文件 我使用以下openmp“hello world”程序:Multithreading openmp在我的mac上运行单线程,multithreading,macos,openmp,llvm-clang,Multithreading,Macos,Openmp,Llvm Clang,我试图在Mac上使用openmp并行化一个程序,但我无法使它成为多线程的。 我尝试过从源代码构建llvm/clang/openmp 3.7.1(在svn co之后),因为我也尝试过使用。 在每种情况下,生成的编译器都可以使用-fopenmp标志正常工作,并生成链接到openmp运行时的可执行文件 我使用以下openmp“hello world”程序: #include <omp.h> #include <stdio.h> #include <stdlib.h>
#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 */
}
然后使用以下命令运行生成的程序:
env OMP_NUM_THREADS=2 ./hello
其中:
Hello World from thread = 0
Number of threads = 1
有什么想法吗?clang<3.8.0要求-fopenmp=libomp生成OpenMP代码。clang>=3.8.0还支持-fopenmp(-fopenmp=libomp也可以使用)。Hm,请尝试
num\u threads
或omp\u set\u num\u threads
设置线程数。这个问题还存在吗?(我想会:()我尝试了这两种方法,但运气都不好。但是omp_get_num_procs和omp_get_max_线程都返回4。尝试并行而不使用私有:尽可能简化。如果没有帮助,可能是叮当声bug-openmp
支持仅在2015年5月才添加,我认为还有很多问题。另外,尝试导出
>而不是env
(尽管我认为没有帮助)。我尝试了你的建议,但没有成功(至于export而不是env,我使用的是tcsh)。然后尝试以下两个命令:setenv OMP_NUM_THREADS 2,后跟。/hello
Hello World from thread = 0
Number of threads = 1