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