openMP不在Visual Studio中创建线程 [英] openMP is not creating threads in visual studio
问题描述
我的openMP版本没有任何速度提升.我有一台双核计算机,CPU使用率始终为50%.因此,我尝试了Wiki中给出的示例程序.看起来openMP编译器(Visual Studio 2008)不会创建多个线程.
My openMP version did not give any speed boost. I have a dual core machine and the CPU usage is always 50%. So I tried the sample program given in Wiki. Looks like the openMP compiler (Visual Studio 2008) is not creating more than one thread.
这是程序:
#include <omp.h>
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char *argv[]) {
int th_id, nthreads;
#pragma omp parallel private(th_id)
{
th_id = omp_get_thread_num();
printf("Hello World from thread %d\n", th_id);
#pragma omp barrier
if ( th_id == 0 ) {
nthreads = omp_get_num_threads();
printf("There are %d threads\n",nthreads);
}
}
return EXIT_SUCCESS;
}
这是我得到的输出:
Hello World from thread 0
There are 1 threads
Press any key to continue . . .
推荐答案
该程序没有任何问题-因此,大概是如何编译或运行该程序.这是VS2008 Pro吗?快速浏览一下,表明OpenMP未在Standard中启用.是否在属性"->"C/C ++"->语言"->"OpenMP"中启用了OpenMP? (例如,您使用/openmp进行编译)吗?运行此命令时,环境变量OMP_NUM_THREADS是否设置为1?
There's nothing wrong with the program - so presumably there's some issue with how it's being compiled or run. Is this VS2008 Pro? A quick google around suggests OpenMP is not enabled in Standard. Is OpenMP enabled in Properties -> C/C++ -> Language -> OpenMP? (Eg, are you compiling with /openmp)? Is the environment variable OMP_NUM_THREADS being set to 1 somewhere when you run this?
这篇关于openMP不在Visual Studio中创建线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!