Skip to content

Instantly share code, notes, and snippets.

@metacollin
Last active July 2, 2016 02:22
Show Gist options
  • Save metacollin/891097a6767e677f3cf5e266ff4c2e2d to your computer and use it in GitHub Desktop.
Save metacollin/891097a6767e677f3cf5e266ff4c2e2d to your computer and use it in GitHub Desktop.
clang and openmp in Mac OS X

Refer to https://clang-omp.github.io/ .

We need to install something:

brew install libiomp
brew install clang-omp

Then we need to set the environment:

export C_INCLUDE_PATH=/usr/local/Cellar/libiomp/20150701/include/libiomp:$C_INCLUDE_PATH
export CPLUS_INCLUDE_PATH=/usr/local/Cellar/libiomp/20150701/include/libiomp:$CPLUS_INCLUDE_PATH
export LIBRARY_PATH=/usr/local/Cellar/libiomp/20150701/lib:$LIBRARY_PATH

We create a file for testing:

/* hello.c */
#include <omp.h>
#include <stdio.h>
int main() {
    #pragma omp parallel
    printf("Hello from thread %d, nthreads %d\n", omp_get_thread_num(), omp_get_num_threads());
}

Then compile it using clang-omp or clang-omp++:

clang-omp -fopenmp hello.c -o hello
./hello
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment