本文介绍了openMP入门.在Windows上安装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用OpenMP用C ++编写并行程序,因此我开始使用OpenMP.换句话说,我是一个初学者,我需要很好的OpenMP指南来告诉您如何安装它.有人知道如何在Windows上安装OpenMP,然后编译并运行该程序吗?

I want to write parallel program in C++ using OpenMP, so I am getting started with OpenMP.On the other words I am a beginner and I need good OpenMP guide telling how to install it.Does someone know how to install OpenMP on Windows, then compile and run the program?

推荐答案

OpenMP不是您要安装的东西.它与您的编译器一起提供.您只需要一个支持OpenMP的体面的编译器,并且需要知道如何启用OpenMP支持,因为通常默认情况下它是禁用的.

OpenMP is not something that you install. It comes with your compiler. You just need a decent compiler that supports OpenMP and you need to know how to enable OpenMP support since it is usually disabled by default.

Windows的标准编译器来自Microsoft,它是Visual Studio的Microsoft Visual C/C ++编译器.不幸的是,它对OpenMP的支持有些过时了-即使最新,最强大的Visual Studio也仅支持OpenMP 2.0(2002年过时的标准版本).有关更多信息,请参见此处如何在Visual Studio中使用OpenMP.还有其他可用的编译器-英特尔C/C ++编译器(需要商业许可)和GCC(免费提供)都支持较新的OpenMP版本,并且还提供其他编译器.

The standard compiler for Windows comes from Microsoft and it is the Microsoft Visual C/C++ compiler from Visual Studio. Unfortunately its OpenMP support is a bit outdated - even the latest and greatest Visual Studio only supports OpenMP 2.0 (an outdated standard version from 2002). See here for more information on how to use OpenMP in Visual Studio. There are other compilers available as well - both Intel C/C++ Compiler (commercial license required) and GCC (freely available) support newer OpenMP versions and other compilers are available too.

您可以通过访问OpenMP网站此处开始学习OpenMP.此外,此处上有劳伦斯·利弗莫尔国家实验室(Lawrence Livermore National Laboratory)提供的有关OpenMP的出色教程.

You can start learning OpenMP by visiting the OpenMP web site here. Also there is a great tutorial on OpenMP from Lawrence Livermore National Laboratory available here.

2020更新: Microsoft现在随Visual Studio一起发布了Windows版Clang.尽管有些麻烦,但是可以(滥用)使用Clang-cl工具集来生成有效的 32位 OpenMP程序.必须执行许多步骤:

2020 Update: Microsoft now ships Clang for Windows with Visual Studio. Although it is a bit convoluted, one can (ab)use the Clang-cl toolset to produce working 32-bit OpenMP programs. A number of steps are necessary:

  1. 如果尚未安装,请使用Visual Studio 2019安装程序添加Clang和Clang-cl.
  2. 将项目的平台工具集(项目 Properties-> General-> Platform Toolset )设置为"LLVM(clang-cl)".
  3. 通过在项目 Properties-> C/C ++-> All Options-> Additional Options 中的编译器选项中添加-Xclang -fopenmp来启用Clang OpenMP支持.
    重要提示:确保在切换平台工具集之前 已禁用OpenMP支持(这是新的C ++项目的默认设置).似乎VS会记住该设置,并且即使Clang的语言配置没有OpenMP选项,VS仍会通过/openmp.如果在构建过程中clang-cl.exe抛出错误MSB8055(不受支持的/openmp选项),请将平台工具集设置回"Visual Studio 2019(vXXX)",并禁用 Properties-> C/C ++-> Language-中的OpenMP支持. >打开MP支持,然后将平台工具集再次切换到"LLVM(Clang-cl)".
  4. libomp.lib添加到项目 Properties-> Linker-> Input-> Additional Dependencies 中的其他库中.
  5. 通过在项目 Properties-> Linker-> General-> Additional Library Directories 中添加值为$(LLVMInstallDir)\lib的新条目,将链接到libomp.lib的路径添加到链接器搜索路径.
  6. >
  7. 添加将LLVM的libomp.dll复制到项目输出目录的生成后操作(如果没有此步骤,除非DLL搜索路径中没有libomp.dll,否则运行可执行文件将会失败).在项目属性->生成事件->生成后事件->命令行中:

  1. If not already installed, add Clang and Clang-cl using the Visual Studio 2019 Installer.
  2. Set the project's platform toolset (project Properties -> General -> Platform Toolset) to "LLVM (clang-cl)".
  3. Enable Clang OpenMP support by adding -Xclang -fopenmp to the compiler options in project Properties -> C/C++ -> All Options -> Additional Options.
    Important: make sure that OpenMP support is disabled before switching the platform toolset (this is the default for new C++ projects). It seems that VS remembers the setting and still passes /openmp even though the language configuration for Clang has no option for OpenMP. If clang-cl.exe throws error MSB8055 (unsupported /openmp option) during build, set the platform toolset back to "Visual Studio 2019 (vXXX)" and disable the OpenMP support in Properties -> C/C++ -> Language -> Open MP Support, then switch the platform toolset again to "LLVM (Clang-cl)".
  4. Add libomp.lib to the additional libraries in project Properties -> Linker -> Input -> Additional Dependencies.
  5. Add the path to libomp.lib to the linker search path by adding a new entry with value $(LLVMInstallDir)\lib in project Properties -> Linker -> General -> Additional Library Directories.
  6. Add a post-build action that copies LLVM's libomp.dll to the project output directory (without this step, running the executable will fail unless libomp.dll is in the DLL search path). In project Properties -> Build Events -> Post-Build Event -> Command Line:

xcopy /y "$(LLVMInstallDir)\bin\libomp.dll" "$(SolutionDir)$(Configuration)"

构建并运行项目.

注意:这很可能仍不受Microsoft支持,并且仅适用于x86项目,因为VS附带的LLVM库仅为32位.

Note: this is very much likely still unsupported by Microsoft and it only works for x86 projects since the LLVM libraries shipped with VS are 32-bit only.

这篇关于openMP入门.在Windows上安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 04:04