/openmp (启用 OpenMP 支持)/openmp (Enable OpenMP Support)

04/15/2019

本文内容

导致编译器处理 #pragma omp OpenMP 支持的指令。Causes the compiler to process #pragma omp directives in support of OpenMP.

语法Syntax

/openmp [:实验 性]/openmp[:experimental]

/openmp/openmp

备注Remarks

#pragma omp 用于指定 指令 和 子句。#pragma omp is used to specify Directives and Clauses. 如果编译中未指定 /openmp ,则编译器将忽略 openmp 子句和指令。If /openmp isn't specified in a compilation, the compiler ignores OpenMP clauses and directives. 即使未指定 /openmp ,编译器也会处理 OpenMP 函数调用。OpenMP Function calls are processed by the compiler even if /openmp isn't specified.

C + + 编译器当前支持 OpenMP 2.0 标准。The C++ compiler currently supports the OpenMP 2.0 standard. 但是,Visual Studio 2019 现在还提供 SIMD 功能。However, Visual Studio 2019 also now offers SIMD functionality. 若要使用 SIMD,请使用 /openmp:实验 性选项编译。To use SIMD, compile by using the /openmp:experimental option. 使用 /openmp 开关时,此选项将启用常见 openmp 功能和其他 openmp SIMD 功能,这些功能不可用。This option enables both the usual OpenMP features, and additional OpenMP SIMD features not available when using the /openmp switch.

使用 /openmp 和 /clr 编译的应用程序只能在单个应用程序域进程中运行。Applications compiled by using both /openmp and /clr can only be run in a single application domain process. 不支持多个应用程序域。Multiple application domains aren't supported. 也就是说,当模块构造函数 (.cctor) 运行时,它将检测是否使用 /openmp 编译了该进程,以及该应用程序是否已加载到非默认运行时。That is, when the module constructor (.cctor) is run, it detects if the process is compiled using /openmp, and if the app is loaded into a non-default runtime.

如果尝试将使用 /openmp 和 /clr 编译的应用加载到非默认应用程序域中,则会在 TypeInitializationException 调试器外部引发异常,并且 OpenMPWithMultipleAppdomainsException 调试器中会引发异常。If you attempt to load an app compiled using both /openmp and /clr into a non-default application domain, a TypeInitializationException exception is thrown outside the debugger, and a OpenMPWithMultipleAppdomainsException exception is thrown in the debugger.

在下列情况下,也可能会引发这些异常:These exceptions can also be raised in the following situations:

如果你的应用程序是使用 /clr 编译的,而不是使用 /openmp 编译的,并且加载到非默认应用程序域中,则该过程包含使用 /openmp 编译的应用。If your application is compiled using /clr but not /openmp, and is loaded into a non-default application domain, where the process includes an app compiled using /openmp.

如果将 /clr 应用传递到实用程序(如 regasm.exe),则会将其目标程序集加载到非默认应用程序域中。If you pass your /clr app to a utility, such as regasm.exe, which loads its target assemblies into a non-default application domain.

公共语言运行时的代码访问安全性不适用于 OpenMP 区域。The common language runtime's code access security doesn't work in OpenMP regions. 如果在并行区域外部应用 CLR 代码访问安全性属性,则该属性在并行区域中不起作用。If you apply a CLR code access security attribute outside a parallel region, it won't be in effect in the parallel region.

Microsoft 不建议你编写允许部分受信任的调用方的 /openmp 应用程序。Microsoft doesn't recommend that you write /openmp apps that allow partially trusted callers. Don't use AllowPartiallyTrustedCallersAttribute, or any CLR code access security attributes.

在 Visual Studio 开发环境中设置此编译器选项To set this compiler option in the Visual Studio development environment

打开项目的“属性页” 对话框。Open the project's Property Pages dialog box.

展开 "配置属性" " > c/c + + > 语言" 属性页。Expand the Configuration Properties > C/C++ > Language property page.

修改 OpenMP 支持 属性。Modify the OpenMP Support property.

以编程方式设置此编译器选项To set this compiler option programmatically

示例Example

下面的示例显示了在启动线程池后使用线程池的某些影响。The following sample shows some of the effects of thread pool startup versus using the thread pool after it has started. 假设有一个 x64、单核、双处理器,线程池需要大约16毫秒的时间启动。Assuming an x64, single core, dual processor, the thread pool takes about 16 ms to start up. 在此之后,线程池的开销较低。After that, there's little extra cost for the thread pool.

使用 /openmp 进行编译时,对 test2 的第二次调用的运行时间不会超过使用 /openmp- 进行编译的时间,因为没有线程池启动。When you compile using /openmp, the second call to test2 never runs any longer than if you compile using /openmp-, as there's no thread pool startup. 在一百万次迭代中, /openmp 版本比 /openmp- 版本更快,后者的第二次调用 test2。At a million iterations, the /openmp version is faster than the /openmp- version for the second call to test2. 25次迭代时, /openmp- 和 /openmp 版本都注册小于时钟粒度。At 25 iterations, both /openmp- and /openmp versions register less than the clock granularity.

如果你的应用程序中仅有一个循环,并且该循环在不到15毫秒的时间内运行 (则) 计算机上的大约系统开销进行调整, /openmp 可能不适合。If you have only one loop in your application and it runs in less than 15 ms (adjusted for the approximate overhead on your machine), /openmp may not be appropriate. 如果更高,你可能需要考虑使用 /openmp。If it's higher, you may want to consider using /openmp.

// cpp_compiler_options_openmp.cpp

#include

#include

#include

#include

volatile DWORD dwStart;

volatile int global = 0;

double test2(int num_steps) {

int i;

global++;

double x, pi, sum = 0.0, step;

step = 1.0 / (double) num_steps;

#pragma omp parallel for reduction(+:sum) private(x)

for (i = 1; i <= num_steps; i++) {

x = (i - 0.5) * step;

sum = sum + 4.0 / (1.0 + x*x);

}

pi = step * sum;

return pi;

}

int main(int argc, char* argv[]) {

double d;

int n = 1000000;

if (argc > 1)

n = atoi(argv[1]);

dwStart = GetTickCount();

d = test2(n);

printf_s("For %d steps, pi = %.15f, %d milliseconds\n", n, d, GetTickCount() - dwStart);

dwStart = GetTickCount();

d = test2(n);

printf_s("For %d steps, pi = %.15f, %d milliseconds\n", n, d, GetTickCount() - dwStart);

}

请参阅See also

openmp配置指南_/openmp (启用 OpenMP 支持)相关推荐

  1. openmp配置指南_[z]OpenMP编程指南

    进入多核时代后,必须使用多线程编写程序才能让各个CPU核得到利用.在单核时代,通常使用操作系统提供的API来创建线程,然而,在多核系统中,情况发生了很大的变化, 如果仍然使用操作系统API来创建线程会 ...

  2. 易语言支持库配置闪退丨支持库配置崩溃_易语言打开支持库配置就闪退怎么办?

    易语言支持库配置闪退打不开怎么办? 易语言支持库配置闪退解决方法丨支持库配置崩溃_易语言打开支持 易语言支持库配置闪退丨支持库配置崩溃_易语言打开支持库配置就闪退怎么办? 很多人都遇到过 打开易语言支 ...

  3. openmp配置指南_openmp开发环境配置

    语句绑定和嵌套规则.库函数和环境变量设置 12. OpenMP计算实例 13. OpenMP应用程序设计的性能分析 2013-8-18 3 6.9 OpenMP线程同步与线程数据语句 ?数据竞争问题. ...

  4. 手把手带你入门深度学习(一):保姆级Anaconda和PyTorch环境配置指南

    手把手带你入门深度学习(一):保姆级Anaconda和PyTorch环境配置指南 一. 前言和准备工作 1.1 python.anaconda和pytorch的关系 二. Anconda安装 2.1 ...

  5. CK-GW06-E03与欧姆龙PLC配置指南

    CK-GW06-E03与欧姆龙PLC配置指南 CK-GW06-E03是一款支持标准工业EtherCAT协议的网关控制器,方便用户集成到PLC等控制系统中.本控制器提供了网络 POE 供电和直流电源供电 ...

  6. OpenMP: OpenMP编程指南

    from: OpenMP: OpenMP编程指南 进入多核时代后,必须使用多线程编写程序才能让各个CPU核得到利用.在单核时代,通常使用操作系统提供的API来创建线程,然而,在多核系统中,情况发生了很 ...

  7. OpenMP编程指南

    OpenMP编程指南 进入多核时代后,必须使用多线程编写程序才能让各个CPU核得到利用.在单核时代,通常使用操作系统提供的API来创建线程,然而,在多核系统中,情况发生了很大的变化, 如果仍然使用操作 ...

  8. Ubuntu下安装配置TAU分析mpich和openmp程序性能

    目录 1. 安装MPICH 2. 安装JAVA环境 3. 下载TAU(及PDT) 4. 提取并配置安装 4.1 使用图形化界面安装 4.2 使用终端直接配置 5. 配置Vs Code或直接使用终端编译 ...

  9. Project Server 2003配置部署指南_百度文库

    Project Server 2003配置部署指南_百度文库 Project server 2003配置部署指南 - 网管地带 - IT博客

最新文章

  1. 产品推广系统推荐乐云seo_优化推广公司红利产品推荐“爱采购cpc竞价版”
  2. boost::container实现多态双端队列的测试程序
  3. DLL内线程同步主线程研究(子线程代码放到主线程执行)
  4. echarts 柱状图 ,颜色和显示设置
  5. input中的disabled 和 readonly的区别
  6. 重写RadGrid及其注意事项
  7. 全屏使用swiper.js过程中遇到的坑
  8. LTE网络测试仪器和监控系统
  9. 这也许是Android一句话权限适配的更优解决方案
  10. 本地计算机无法启动,winxp系统下本地计算机无法启动Windows Time服务怎么办
  11. iterator接口
  12. 第一章 空间解析几何与向量代数(1)
  13. 生活,平淡,些许沉思,些许感概
  14. 使用函数求最大公约数 pta_13个数学函数应用技巧解读,易学易懂,远离数学计算困扰...
  15. 盘点:怀一胎和怀二胎的4点不同
  16. remote: Repository not found. fatal: repository ‘xxxxxxx‘ not found
  17. 五点三次平滑+python实现
  18. 机器视觉系统硬件选型
  19. rop和rop2的题目的wp
  20. Postman(七): postman应用实战

热门文章

  1. GLU(Gated Linear Units)
  2. Outlook如何修复.pst数据文件?
  3. 爬取TIOBE的编程语言排行榜
  4. 【gflags 】google gflags 使用方法
  5. 计算机说话技巧,随机应变的说话技巧
  6. 静态存储区与动态存储区
  7. html网络流量监控,NetLimiter 4 网络流量控制监控工具
  8. AcWing 748. 数组的右下半部分
  9. MAC Boook打印长图
  10. 微信小程序插件下发优惠券踩坑