在运行时本地启用/禁用OpenMP
Enable/disable OpenMP locally at runtime
是否可以在运行时启用或禁用OpenMP并行化?我有一些代码应该在某些情况下并行运行,而不是在其他情况下并行运行。同时,其他线程中的其他计算也使用OpenMP,并且应该始终并行运行。有没有办法告诉OpenMP不要在当前线程并行?我知道omp_set_num_threads
,但我假设全局设置OpenMP使用的线程数。
您可以使用的另一种选择是在#pragma omp
结构中添加if
条件。当条件为false时,将跳过对从pragmas派生的OpenMP运行时调用的调用。
考虑以下基于变量t
和f
(分别为真和假)使用条件的程序:
#include <omp.h>
#include <stdio.h>
int main (void)
{
int t = (0 == 0); // true value
int f = (1 == 0); // false value
#pragma omp parallel if (f)
{ printf ("FALSE: I am thread %dn", omp_get_thread_num()); }
#pragma omp parallel if (t)
{ printf ("TRUE : I am thread %dn", omp_get_thread_num()); }
return 0;
}
输出为:
$ OMP_NUM_THREADS=4 ./test
FALSE: I am thread 0
TRUE : I am thread 0
TRUE : I am thread 1
TRUE : I am thread 3
TRUE : I am thread 2
相关文章:
- 嵌入方指针压缩已禁用
- OpenMP阵列性能较差
- OpenMP卸载说'fatal error: could not find accel/nvptx-none/mkoffload'
- 使用 GCC 卸载的 OpenMP 卸载失败,并出现"Ptx assembly aborted due to errors"
- clang格式:禁用排序包含
- 如何在C++中找到active directory中禁用和锁定的窗口帐户
- 如何在C++生成器中禁用"使用调试.dcus"
- OpenMP:并行更新数组总是需要减少数组吗
- 如何在GTK程序运行时禁用屏幕保护程序/电源管理/屏幕消隐
- 如何使用OpenMP并行这两个循环
- 从python调用openMP共享库时,未定义opnMP函数
- 如何使用OpenMP并行化此矩阵时间矢量运算
- 如何使用OpenMP使这个循环并行
- 如何通过替换顺序代码的while循环来添加OpenMP for循环
- 查找最近配对时的OpenMP竞赛条件
- 为 OpenMP 函数创建别名 ||部分禁用 openMP
- RcppArmadillo:使用autoconf禁用OpenMP
- 在我的c++项目中禁用OpenMP pragma语句
- 如何以一种很好的方式禁用OpenMP指令
- 在运行时本地启用/禁用OpenMP