在 Mac OS X 10.11 上安装 OpenMP [英] Installing OpenMP on Mac OS X 10.11

查看:85
本文介绍了在 Mac OS X 10.11 上安装 OpenMP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何让 OpenMP 在 Mac OSX 10.11 上运行,以便我可以通过终端执行脚本?

我已经安装了 OpenMP:brew install clang-omp.

当我运行时,例如:gcc -fopenmp -o Parallel.b Parallel.c 以下表达式返回:fatal error: 'omp.h' file not found

我也试过:brew install gcc --without-multilib 但不幸的是这最终返回了以下内容(在第一次安装一些依赖项之后):

请求的 URL 返回错误:404 Not Found错误:无法下载资源mpfr--patch"

有什么推荐的解决方法吗?

解决方案

在 Mac 上,命令 gcc 是 Clang 的符号链接.所以通过调用

gcc -fopenmp -o your_program your_program.c

您实际上正在使用 Clang,它直到现在还没有内置对 OpenMP 的支持.

根据 this 帖子(您还可以在其中找到有关如何设置的说明).

另一方面,如果您仍想使用 gcc,我可以指导您完成对我有用的步骤.

  1. 使用 brew 安装 gcc.您使用的命令应该可以工作:

    brew install gcc --without-multilib

    或者,如果 brew 说你已经安装了 gcc,你可以试试

    brew 重新安装 gcc --without-multilib

    正如您可能已经注意到的,如果您没有指定 --without-multilib brew 会警告您 OpenMP 可能无法工作.

  2. 找到新安装的 gcc 的位置.

    Brew 将版本号附加到 gcc 以便它不会与命令行工具安装的版本号冲突.您将在 usr/local/bin 中找到符号链接.

    就我而言

    usr/local/bin/gcc-5

    如果您右键单击并选择显示原件"它应该显示 /usr/local/Cellar/gcc/5.3.0/bin/gcc-5 中的 gcc-5 可执行文件(版本号可能不同).

  3. 现在你需要告诉你的系统:

    当调用编译器时,你的 bash 默认会查看 /usr/bin 而不是 /usr/local/bin.您需要将此目录添加到您的 $PATH.

    这可以通过以下命令轻松完成:

    PATH=/usr/local/bin:$PATH

  4. 现在您应该能够使用以下方法在启用 OpenMP 的情况下进行编译:

    gcc-5 -fopenmp -o your_program your_program.c

备注: gcc-5 是我安装的版本,你的可能不同.

How can I get OpenMP to run on Mac OSX 10.11, so that I can execute scripts via terminal?

I have installed OpenMP: brew install clang-omp.

When I run, for example: gcc -fopenmp -o Parallel.b Parallel.c the following expression returns: fatal error: 'omp.h' file not found

I have also tried: brew install gcc --without-multilib but unfortunately this eventually returned the following (after first installing some dependencies):

The requested URL returned error: 404 Not Found
Error: Failed to download resource "mpfr--patch"

Any recommended work arounds?

解决方案

On a Mac, the command gcc is a symlink to Clang. So by calling

gcc -fopenmp -o your_program your_program.c

you are in fact using Clang, which until now has not had built-in support for OpenMP.

The newer versions of Clang do have support for OpenMP according to this post (where you can also find instructions on how to set it up).

On the other hand, if you still want to use gcc I can guide you through the steps that worked for me.

  1. Install gcc with brew. The command you used should work:

    brew install gcc --without-multilib
    

    Alternatively, if brew says that you already have gcc installed you can try

    brew reinstall gcc --without-multilib
    

    As you may have noted, if you don't specify --without-multilib brew warns you that OpenMP may not work.

  2. Find the location of the newly installed gcc.

    Brew appends the version number to gcc so that it does not conflict with the one installed by Command Line Tools. You will find the symlink in usr/local/bin.

    In my case it's

    usr/local/bin/gcc-5
    

    If you right-click and chose "Show original" it should show the gcc-5 executable in /usr/local/Cellar/gcc/5.3.0/bin/gcc-5 (version numbers may differ).

  3. Now you need to tell your system about it:

    When calling a compiler your bash will look into /usr/bin by default and not in /usr/local/bin. You need to add this directory to your $PATH.

    This can be easily done with the command:

    PATH=/usr/local/bin:$PATH
    

  4. Now you should be able to compile with OpenMP enabled using:

    gcc-5 -fopenmp -o your_program your_program.c
    

Remark: gcc-5 is the version I have installed, yours might differ.

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

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