关闭OpenMP [英] Turn off OpenMP

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

问题描述

在我的C ++程序中,我想要运行它的可执行文件,有时甚至不使用OpenMP(即多线程或单线程)。我正在考虑以下两种情况下我的代码是如何使用OpenMP的任何一种:

In my C++ program, I'd like to run its executable sometimes with and sometimes without using OpenMP (i.e. multi-threading or single-threading). I am considering any of the following two cases how my code is using OpenMP:

(1)假设我的代码只有 #include< ; omp.h> 和OpenMP指令。

(1) Assume that my code is only having #include <omp.h> and OpenMP directives.

(2)与(1)相同,我的代码进一步调用OpenMP函数,如 omp_get_thread_num()

(2) Same as (1) and my code further calls OpenMP functions like omp_get_thread_num().

为了不对不同的运行有不同的代码,是否使用一些自定义预编译器变量来防止OpenMP出现在我的代码中的唯一方法?

In order not to have different code for different running, is it the only way using some self-defined precompiler variable to guard where OpenMP appears in my code ?

感谢和问候!

推荐答案

Hi最简单的方法是

omp_set_num_threads(m_iUseableProcessors);

其中m_iUseableProcessors是要拆分计算的处理器数。我不知道如何做没有OpenMP功能。你可能可以#ifdef他们,但是这让你在编译时关闭OpenMP。

where m_iUseableProcessors is the number of processors you want to split the calculation over. I don't know how to do it without the OpenMP functions. You could probably #ifdef them out, but that makes you turn off OpenMP at compile time.

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

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