忽略没有它的机器上的OpenMP [英] Ignore OpenMP on machine that does not have it

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

问题描述

我有一个使用OpenMP的C ++程序,它将在几台已安装或未安装OpenMP的计算机上运行.

I have a C++ program using OpenMP, which will run on several machines that may have or not have OpenMP installed.

如何让我的程序知道机器是否没有OpenMP,而忽略那些#include <omp.h>,OpenMP指令(例如#pragma omp parallel ...)和/或库函数(例如tid = omp_get_thread_num();)?

How could I make my program know if a machine has no OpenMP and ignore those #include <omp.h>, OpenMP directives (like #pragma omp parallel ...) and/or library functions (like tid = omp_get_thread_num();) ?

推荐答案

OpenMP是编译器运行时环境,而不是平台环境.

OpenMP is a compiler runtime thing and not a platform thing.

即.如果使用Visual Studio 2005或更高版本编译应用程序,则运行时始终会支持OpenMP可用. (如果最终用户没有安装Visual Studio C运行时,则您的应用程序将根本无法运行.)

ie. If you compile your app using Visual Studio 2005 or higher, then you always have OpenMP available as the runtime supports it. (and if the end-user doesn't have the Visual Studio C runtime installed, then your app won't work at all).

因此,您不必担心,如果可以使用它,它将像strcmp之类的功能一样永远存在.为了确保它们具有CRT,您可以安装Visual Studio可再发行组件.

So, you don't need to worry, if you can use it, it will always be there just like functions such as strcmp. To make sure they have the CRT, then you can install the visual studio redistributable.

好的,但是GCC 4.1将无法编译您的openMP应用程序,因此问题不是目标计算机,而是目标编译器.由于所有编译器都有提供其版本的预定义宏,因此请使用#ifdef块包装您的OpenMP调用.例如,GCC使用3个宏来标识编译器版本__GNUC__, __GNUC_MINOR__ and __GNUC_PATCHLEVEL__

ok, but GCC 4.1 will not be able to compile your openMP app, so the issue is not the target machine, but the target compiler. As all compilers have pre-defined macros giving their version, wrap your OpenMP calls with #ifdef blocks. for example, GCC uses 3 macros to identify the compiler version, __GNUC__, __GNUC_MINOR__ and __GNUC_PATCHLEVEL__

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

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