Loading... There are already some tutorials about how to enable OpenMP on macOS by installing a `gcc` compiler. I believe that it can work fine. With some environment manager such as anaconda or spack, we can even install different versions of compilers and make them co-exist. However, actually OpenMP can be used with `clang` that are already installed on many developers' macOS. Here's how to do it. # Enable OpenMP 1. Visit [OpenMP on macOS with Xcode tools](https://mac.r-project.org/openmp/). Follow the installation instruction, which contains just two steps like: ```sh curl -O https://mac.r-project.org/openmp/openmp-12.0.1-darwin20-Release.tar.gz sudo tar fvxz openmp-12.0.1-darwin20-Release.tar.gz -C / ``` 2. Add some extra flags to the compilation commands that work on Linux: ```sh # On Linux g++ openmp_pow.cpp -O3 -std=c++11 -fopenmp # On macOS clang++ openmp_pow.cpp -O3 -std=c++11 -Xclang -fopenmp -lomp ``` Actually it is learned through the website above. # Configure CMake in CLion We need to edit `CMakeLists.txt` to make CLion know where the OpenMP header files are and how to link the dynamic libs. Here's mine: ```cmake cmake_minimum_required(VERSION 3.21) project(parallel_playground) set(CMAKE_CXX_STANDARD 23) include_directories(/usr/local/include) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Xclang -fopenmp") find_library(OPENMP_LIB libomp.dylib /usr/local/lib) add_executable(parallel_playground main.cpp) target_link_libraries(parallel_playground LINK_PUBLIC ${OPENMP_LIB}) ``` Last modification:March 18, 2022 © Allow specification reprint Support Appreciate the author Like 0 如果觉得我的文章对你有用,请随意赞赏
2 comments
You suggested that very well.
You mentioned that exceptionally well!