Website for this extension: http://clang-omp.github.io/
Install clang-omp using homebrew:
brew install clang-omp
Create a new Xcode project.
Under click 'the name of the project' —> Build Settings
Editor --> Add Build Setting --> Add User-Defined Setting (Press ‘delete’ on the keyboard to delete the user-defined setting when you do not want it)
set the setting name as CC
set its value as /usr/local/bin/clang-omp
Add -fopenmp to Other C Flags
Add /usr/local/include to Header Search Paths
Set Enable Modules (C and Objective-C) to No.
Under Build Phases
Add /usr/local/lib/libiomp5.dylib to Link Binary With Libraries
Done. You can now #include <libiomp/omp.h> and start using #pragma omp ... in your source code.
测试编译器和环境配置是否成功的代码如下:
#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());
}
/* OUTPUT:
Hello from thread 0, nthreads 4
Hello from thread 3, nthreads 4
Hello from thread 2, nthreads 4
Hello from thread 1, nthreads 4
Program ended with exit code: 0
*/
You should see more than one "Hello" line with different thread numbers. Note that the lines may be mixed together. If you see only one, try setting the environment variable OMP_NUM_THREADS to some number (say 4) and try again.