[R-SIG-Mac] OpenMP and MacOS (silicon)

Adrian Dușa du@@@@dr|@n @end|ng |rom gm@||@com
Tue May 6 18:54:51 CEST 2025


Dear All,

I followed with great interest the latest exchange regarding the status of
the OpenMP under MacOS, learned a great deal of things and now join others
in thanking Simon and team for making this possible.

This message is just to share my own experience. In following the least
effort path, my rather quick and painless procedure involves:
- installing R from CRAN
- installing GCC and OpenMP via homebrew
- (not using Xcode, but) using only the Command Line Tools
- building my package locally

This seems to work, and for that I have two Makevars files. The first is
located in ~/.R/, containing:
CC = /opt/homebrew/bin/gcc-14
CXX = /opt/homebrew/bin/g++-14
CXX11 = /opt/homebrew/bin/g++-14
CXX14 = /opt/homebrew/bin/g++-14
CXX17 = /opt/homebrew/bin/g++-14

The second Makevars file is package specific, in the src/ directory,
containing:
PKG_CFLAGS = -fopenmp -O3 -mcpu=apple-m2 -mtune=apple-m2
PKG_CXXFLAGS = -fopenmp -O3 -mcpu=apple-m2 -mtune=apple-m2
PKG_LIBS = -fopenmp

I did read (and duly acknowledged) Simon's advice to use R's binaries and
settings to make everything work on CRAN, it's just that building the
package locally allows me to use particular flags, for instance "-O3" that
indicates <speed>, as far as I understand.

I found that various Makevars settings make a huge difference in terms of
speed, and since speed matters most to me, I try to find the most
appropriate flags for my own use. Fine-tuning for "apple-m2", plus -O3,
made my OpenMP code run about 3 times faster than regular OpenMP.

Again, far from me to say this suits everyone's needs, and this procedure
probably departs from the best practices, it's just something that works
well in my case.

In hoping this proves useful to anyone, my 2 cents,
Adrian

	[[alternative HTML version deleted]]



More information about the R-SIG-Mac mailing list