如何在 VS2008下使用Openmp编程

如何在 VS2008下使用Openmp编程

如何建立Openmp编程环境
    OpenMP在Windows环境下比较容易实现,只要打开VS2008中的编译选项/openmp,设置一下环境变量
OMP_NUM_THREADS就可以了.一般是新建一个c++项目,以次选择项目->(*)属性->配置属性 ->c"c++->语言,打开OpenMP支持;设置环境变量,我的电脑->属性->高级->环境变量,新建一个 OMP_NUM_THREADS变量,值设为2,即为程序执行的线程数.
    至于其它环境变量,在使用的时候我们再设置就可以了,所以暂时不考虑.
    这样,就可以进行OpenMP程序设计了.

比如我们可以用下面的程序来测试一下:

 1 #include  < stdio.h >
 2 #include  < omp.h >
 3
 4 int  main()
 5 {
 6         omp_set_num_threads( 2 );
 7      #pragma  omp parallel
 8         printf( " Hello from Thread NO.%d/n " ,omp_get_thread_num());
 9          return   0 ;
10     }

 

程序运行结果为:
    Hello from Thread NO.0
    Hello from Thread NO.1

 

 

==============================================================================

OpenMP on Visual Studio

You can create C++ application in Visual Studio that use OpenMP. When you run an application created with OpenMP and VS.NET, however, you may get this annoying error message: “This application has failed to start because vcompd.dll was not found. Re-installing the application may fix this problem.”:

omp-error

When we tried this, we were puzzled by this error message, especially since it works with the Intel Compiler flawlessly. Well, it turns out that you need to include omp.h in your files ALWAYS when you use OpenMP from Visual Studio. This is not required on other compilers if you’re only using the OpenMP pragmas, but it is an issue with Visual Studio.

Thanks to Kang Su for pointing this out in his blog – I was going crazy trying to figure out what was wrong.

Also remember to enable OpenMP support in the C++ Project properties. This setting is in Configuration Properties->C/C++->Language->OpenMP Support .

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值