简体   繁体   English

/ MP在VS2012中未启用OpenMP支持

[英]/MP doesn't enable OpenMP support in VS2012

I have this code in visual c++ 2012: 我在Visual c ++ 2012中有以下代码:

void Run()
{
    #pragma omp parallel for
    for(int imageNo=0;imageNo<4;imageNo++)
    {
        RunForOneImage(imageNo, Data[imageNo],
                       width, height,
                       OutputWidth, OutputHeight);  
    }
}

All variables in RunForOneImage are local variables and it doesn't use any global or class member variables. RunForOneImage中的所有变量都是局部变量,并且不使用任何全局或类成员变量。

When run it, I can see that only one core became busy and other core are idle. 运行它时,我可以看到只有一个内核变得繁忙而其他内核处于空闲状态。

Why this is not running in parallel? 为什么这不是并行运行?

I selected multi processor option in visual studio (/MP). 我在Visual Studio(/ MP)中选择了多处理器选项。 Is there any other option that I should select? 我还有其他选择吗?

The /MP option means that the compilation will run on multiple processors, it's purpose is to "reduce the total time to compile the source files" . /MP选项意味着编译将在多个处理器上运行,其目的是“减少编译源文件的总时间”

It has nothing to do with OpenMP API . 它与OpenMP API无关。 To enable OpenMP support, there's an /openmp option (in the documentation you'll also find an example and the description of how to enable OpenMP support). 要启用OpenMP支持,有一个/openmp选项(在文档中,您还将找到一个示例以及有关如何启用OpenMP支持的说明)。

只需转到“项目属性”->“ C / C ++”->“语言”->“打开MP支持”,然后将其切换为“是”即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM