Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
586 views
in Technique[技术] by (71.8m points)

c - Installing OpenMP on Mac OS X 10.11

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...