无法让OpenMP生成多个线程

时间:2010-08-31 06:01:06

标签: visual-studio-2010 openmp

#include <omp.h>
#include <stdio.h>


int main(int argc, char* argv[])
{
 omp_set_num_threads(4);
 printf("numThreads = %d\n", omp_get_num_threads());
}

此代码打印:

numThreads = 1

这是在Visual Studio 2010 Ultimate中编译的。我已经改变了项目配置属性(所有配置) - &gt; C / C ++ - &gt;语言 - &gt;打开MP支持为是(/ openmp)

我很茫然。我已经从一个更大的项目中解决了这个问题,我想使用多个线程。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

omp_get_num_threads - 活跃团队的大小

返回当前团队中的线程数。 在程序的连续部分中,omp_get_num_threads返回1.

http://gcc.gnu.org/onlinedocs/libgomp/omp_005fget_005fnum_005fthreads.html#omp_005fget_005fnum_005fthreads

这意味着,在并行循环中使用此函数来了解OMP使用的线程数。