# OpenMP on Mac fails -- SUCCESS

**URL:** <https://openmc.discourse.group/t/openmp-on-mac-fails-success/2070>\
**Category:** User Support\
**Created:** [May 23, 2022, 11:21pm UTC](https://openmc.discourse.group/t/openmp-on-mac-fails-success/2070 "2022-05-23T23:21:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tjrob](https://avatars.discourse-cdn.com/v4/letter/t/5f8ce5/32.png) [@tjrob](https://openmc.discourse.group/u/tjrob)\
**Post date:** [May 23, 2022, 11:21pm UTC](https://openmc.discourse.group/t/openmp-on-mac-fails-success/2070/1 "2022-05-23T23:21:30Z")

</div>

Has anybody gotten OpenMP to work on a Mac?

I installed OpenMP: brew install libomp  
But it has no openmp.cmake file, so cmake cannot find it.

I see /usr/local/include/omp.h and /usr/local/lib/libomp.{a,dylib}.  
So how do I build an openmp.cmake file?  
Can someone display a working one?

This is macOS Catalina (10.15.7) on an 8-core Mac Pro. I really want to use its 16 threads!

---

<div class="post-metadata">

**Author:** ![paulromano](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/paulromano/32/486_2.png) [@paulromano](https://openmc.discourse.group/u/paulromano)\
**Post date:** [May 24, 2022, 11:45am UTC](https://openmc.discourse.group/t/openmp-on-mac-fails-success/2070/2 "2022-05-24T11:45:16Z")

</div>

OpenMP is enabled by default in our cmake configuration and should be picked up with the line `find_package(OpenMP)`. What do you see when you run `cmake`?

---

<div class="post-metadata">

**Author:** ![tjrob](https://avatars.discourse-cdn.com/v4/letter/t/5f8ce5/32.png) [@tjrob](https://openmc.discourse.group/u/tjrob)\
**Post date:** [May 24, 2022, 3:58pm UTC](https://openmc.discourse.group/t/openmp-on-mac-fails-success/2070/3 "2022-05-24T15:58:00Z")

</div>

This is macOS Catalina (10.15.7) on a Mac Pro with 8 cores / 16 threads, using HomeBrew.

The relevant output lines from cmake are:

> – Could NOT find OpenMP\_C (missing: OpenMP\_C\_FLAGS OpenMP\_C\_LIB\_NAMES)  
> – Could NOT find OpenMP\_CXX (missing: OpenMP\_CXX\_FLAGS OpenMP\_CXX\_LIB\_NAMES)  
> – Could NOT find OpenMP (missing: OpenMP\_C\_FOUND OpenMP\_CXX\_FOUND)

There are two basic problems here:

1. “brew install libomp” does not install OpenMP-config.cmake. It does install omp.h, libomp.a, and libomp.dyllib into /usr/local. So the code is there, but cmake cannot find it.
2. Apple’s clang does not support OpenMP, and does not recognize “-fopenmp”

I got it to work by:

1. brew install llvm
2. edit CMakeLists.txt to replace the find\_package:  
#TJR find\_package(OpenMP)  
set(OPENMP\_FOUND TRUE)  
set(OpenMP\_CXX\_FLAGS “-fopenmp”)  
#TJR end edits
3. use this command in the empty build directory:  
` CC=/usr/local/opt/llvm/bin/clang CXX=/usr/local/opt/llvm/bin/clang++ LDFLAGS=-L/usr/local/lib cmake -DCMAKE_INSTALL_PREFIX=$HOME/openmc ..`
4. Note the brew-installed `g++-11` did not work (some missing libraries). But the brew-installed clang++ (in package ‘llvm’) does work.

This is clearly very Mac and HomeBrew specific, and required a level of software expertise not often found in physicists. I do not know why neither Apple nor HomeBrew got it right.

---

<div class="post-metadata">

**Author:** ![paulromano](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/paulromano/32/486_2.png) [@paulromano](https://openmc.discourse.group/u/paulromano)\
**Post date:** [May 24, 2022, 4:13pm UTC](https://openmc.discourse.group/t/openmp-on-mac-fails-success/2070/4 "2022-05-24T16:13:44Z")

</div>

@tjrob Glad you were able to figure out a workaround. Out of curiousity what version of CMake are you using? I’m wondering if perhaps they have fixed the OpenMP module to work out of the box in recent releases – ideally the `find_package(OpenMP)` call should just work!

---

<div class="post-metadata">

**Author:** ![tjrob](https://avatars.discourse-cdn.com/v4/letter/t/5f8ce5/32.png) [@tjrob](https://openmc.discourse.group/u/tjrob)\
**Post date:** [May 24, 2022, 4:47pm UTC](https://openmc.discourse.group/t/openmp-on-mac-fails-success/2070/5 "2022-05-24T16:47:25Z")

</div>

$ cmake --version  
cmake version 3.12.3

That’s quite old – apparently I installed it manually some time ago. So I removed it and did “brew install cmake” and got cmake version 3.23.1.

I removed my edits to CMakeLists.txt, removed and recreated the build directory, and now cmake finds OpenMP. The Apple clang++ compiler still cannot use it, but HomeBrew’s clang++ can; not editing CMakeLists.txt is a big improvement.

For the record, after “brew upgrade; brew install llvm libomp”, with source in $HOME/openmc, the commands are:

> `cd $HOME/openmc; rm -fr build; mkdir build; cd build; CC=/usr/local/opt/llvm/bin/clang CXX=/usr/local/opt/llvm/bin/clang++ LDFLAGS=-L/usr/local/lib cmake -DCMAKE_INSTALL_PREFIX=$HOME/openmc ..; make install`

That puts the executable into $HOME/openmc/bin

Thanks.
