如何以一种很好的方式禁用OpenMP指令? [英] How to disable OpenMP directives in a nice way?

查看:47
本文介绍了如何以一种很好的方式禁用OpenMP指令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有C ++代码,其中包含OpenMP编译指示.我想同时针对多线程模式(使用OpenMP)和单线程模式(不使用OpenMP)测试此代码.

I have C++ code with OpenMP pragmas inside. I want to test this code both for multithread mode (with OpenMP) and in single thread mode (no OpenMP).

目前,要在两种模式之间切换,我需要注释#pragma omp(或至少是parallel).

For now, to switch between modes I need to comment #pragma omp (or at least parallel).

启用/禁用OpenMP的最干净的默认方法是什么?

What is the cleanest, or default, way to enable / disable OpenMP?

推荐答案

查看有关禁用OpenMP的开关的编译器手册.对于GCC,默认情况下禁用OpenMP,并使用-fopenmp选项启用.

Look into the compiler manual for the switch that disables OpenMP. For GCC, OpenMP is disabled by default and enabled with the -fopenmp option.

另一种选择是在OMP_NUM_THREADS环境变量设置为1的情况下运行代码,尽管这与首先没有使用OpenMP进行编译并不完全相同.

Another option would be to run the code with the OMP_NUM_THREADS environment variable set to 1, though that is not exactly the same as compiling without OpenMP in the first place.

这篇关于如何以一种很好的方式禁用OpenMP指令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆