有条件的“pragma omp" [英] Conditional "pragma omp"

查看:29
本文介绍了有条件的“pragma omp"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 OpenMP 进行不同类型的并行化.结果,我的代码中有几行 #pragma omp parallel for 我(取消)交替注释.有没有办法让这些行有条件地使用类似下面的东西,而不是工作代码?

I am trying different kinds of parallelization using OpenMP. As a result I have several lines of #pragma omp parallel for in my code which I (un-)comment alternating. Is there a way to make these lines conditional with something like the following, not working code?

   define OMPflag 1 
   #if OMPFlag pragma omp parallel for
   for ...

推荐答案

OpenMP 并行构造可以指定 if 子句.在 Fortran 中,我会这样写:

An OpenMP parallel construct can have an if clause specified. In Fortran I'd write something like this:

!$omp parallel if(n>25) ... 

当问题可能太小而无法并行化时,我有时会使用它.我想您可以使用相同的方法在运行时检查调试标志.我会让你自己弄清楚 C++ 语法,但它可能完全相同.

I sometimes use this when a problem might be too small to bother parallelising. I guess you could use the same approach to check a debug flag at run time. I'll leave it up to you to figure out the C++ syntax but it's probably exactly the same.

这篇关于有条件的“pragma omp"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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