Skip to content
Prev 13159 / 15075 Next

OpenMP on CRAN (Simon Urbanek)

Hi Kevin et al.,

The setup you suggested did not work for me, but I was able to get OpenMP to work on Mac (10.13) with R v4.0 packages.  Here's what I did:

(1) After installing Homebrew, ran
brew install libomp
# Note it is also possible to install from OpenMP Source code: https://releases.llvm.org/download.html#10.0.0
(2) Determined the install path with
brew --prefix libomp
# In my case /usr/local/opt/libomp
(3) Added lines to ~/.R/Makevars
CC=/usr/local/clang4/bin/clang -fopenmp -I/usr/local/opt/libomp/include
LDFLAGS=-L/usr/local/opt/libomp/lib

I imagine the process is similar for C++ code by setting CXX.  Now parallelization for C code with OpenMP is working again on Mac.

As always, I am thankful to the R community for helping problem solve.

I wish more direction along these lines could be added to mac.r-project.org<http://mac.r-project.org>

Erik
On Apr 29, 2020, at 1:51 AM, Dmitriy Selivanov <selivanov.dmitriy at gmail.com<mailto:selivanov.dmitriy at gmail.com>> wrote:
Thanks, Kevin, I can confirm suggested setup works fine so far. Thank you!

I understand it, is that there's
no guarantee that this will work properly (or continue to work
properly) as the Apple toolchain continues to be updated -- e.g. a new
version of macOS / Xcode could install a version of Apple Clang that
is then incompatible with the version of libomp currently in use. In
such a case, I suspect one would need to find and reinstall libomp.

Thats understandable.
On Sat, Apr 25, 2020 at 8:09 PM Kevin Ushey <kevinushey at gmail.com<mailto:kevinushey at gmail.com>> wrote:
The following works for me on macOS 10.15.4 using Apple Clang + libomp
from LLVM 10 (via Homebrew).

Install libomp from Homebrew with:

    brew install libomp

Then, put the following in ~/.R/Makevars

    CPPFLAGS += -I/usr/local/opt/libomp/include -Xclang -fopenmp
    LDFLAGS += -L/usr/local/opt/libomp/lib -lomp

Then R will automatically enable + use OpenMP as appropriate when
installing packages from sources.

The main danger of this approach, as I understand it, is that there's
no guarantee that this will work properly (or continue to work
properly) as the Apple toolchain continues to be updated -- e.g. a new
version of macOS / Xcode could install a version of Apple Clang that
is then incompatible with the version of libomp currently in use. In
such a case, I suspect one would need to find and reinstall libomp.

In theory, this could be alleviated by ensuring all users download and
use the same version of Xcode as is being used by the macOS build
machine (Xcode 10.1), but in practice users will likely just be using
the "default" set of command line tools that comes with their version
of macOS.

Cunningham's law will hopefully ensure someone else will chime in if
I've got something wrong :-)

Best,
Kevin
On Sat, Apr 25, 2020 at 8:29 AM Wright, Erik Scott <ESWRIGHT at pitt.edu<mailto:ESWRIGHT at pitt.edu>> wrote:
--
Regards
Dmitriy Selivanov