忽略没有它的机器上的OpenMP [英] Ignore OpenMP on Machine that doesn't have it

查看:515
本文介绍了忽略没有它的机器上的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,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 ", 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.

ie。如果你使用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。

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__和__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天全站免登陆