9 November 2022

OpenMP for R packages on M1 Mac

  1. Getting OpenMP working for your R packages on MacOS

Getting OpenMP working for your R packages on MacOS

# Uncomment if you want to use LLVM to get OpenMP working
# Newly installed Homebrew is located in
#  - /opt/homebrew for ARM Macs (M1 and its successors)
#  - /usr/local for Intel Macs

HOMEBREW_LOC=/opt/homebrew
LLVM_LOC=$(HOMEBREW_LOC)/opt/llvm
CC=$(LLVM_LOC)/bin/clang -fopenmp
CXX=$(LLVM_LOC)/bin/clang++ -fopenmp
CFLAGS=-g -O3 -Wall -pedantic -std=gnu99 -mtune=native -pipe
CXXFLAGS=-g -O3 -Wall -pedantic -std=c++11 -mtune=native -pipe
LDFLAGS=-L$(HOMEBREW_LOC)/opt/gettext/lib -L$(LLVM_LOC)/lib -Wl,-rpath,$(LLVM_LOC)/lib
CPPFLAGS=-I$(HOMEBREW_LOC)/opt/gettext/include -I$(LLVM_LOC)/include

This should go in your ~/.R/Makevars file. Compiling my packages with LLVM got OpenMP working with packages like fst for me. Hope it works for you.

Tags: MacOS R