Skip to content

New R toolchain for Mac OS

September 18, 2017

The new release of R 3.4.1 “Single Candle” for macOS 10.11 (El Capitan) and higher was built with clang 4.0.0 and gfortran 6.1. Given my previous issues with the clang++ compiler, I was curious to see how much of an improvement this would be. The details are below, but in brief my conclusion is that Stan and nVidia CUDA users should hold off for now, until some teething problems with the new toolchain have been sorted out. This is disappointing, since it looks like OpenMP is working (finally!) in this version of the compiler.

The first problem that I ran into was that the gfortran 6.1 install package isn’t signed, so you can’t install it without admin access. Not a good start! For many people, this will be reason enough to avoid upgrading to R 3.4.x for the time being.

This comes with an unofficial version of clang-4.0.0-darwin15.6-Release.tar.gz, since the official release of clang 4.0.0 is only available for macOS 10.12 and above. It replaces Apple LLVM version 8.1.0 that I had previously installed with Xcode 8.3.2. These are the two versions:

$ /usr/local/clang4/bin/clang --version
clang version 4.0.0 (tags/RELEASE_400/final)
Target: x86_64-apple-darwin16.7.0
Thread model: posix
InstalledDir: /usr/local/clang4/bin

$ /usr/bin/clang --version
Apple LLVM version 8.1.0 (clang-802.0.42)
Target: x86_64-apple-darwin16.7.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

Both versions of clang claim to support POSIX threads, but I know that the Apple LLVM version doesn’t support OpenMP pragma directives. I was also curious to see whether Stan and CUDA would continue to work with the new toolchain, since they have both been very fussy about compilers in the past.

I updated my ~/.R/Makevars as advised, to point to the new compilers:

LDFLAGS=-L/usr/local/clang4/lib -fopenmp

Stan picked up the new version of clang:

/usr/local/clang4/bin/clang++ ... -I/usr/local/include -fPIC -mtune=core2 -O3 -fopenmp -c file5d687a875d0d.cpp ... <truncated>

However, I got some weird errors when I tried to run a Stan model:

Error in sampler$call_sampler(args_list[[i]]) : 
empty_nested() must be true before calling recover_memory()

I’m not sure what’s going on here. I tried installing both Rcpp and rstan from source, but haven’t had any luck.

CUDA 8.0.61 requires Xcode 8.2 (Apple LLVM 8.0.0) on macOS 10.12 (Sierra). As expected, this resulted in the following error message when compiling the R package gputools from source:

nvcc fatal : The version ('80100') of the host compiler ('Apple clang') is not supported

The final test was to try compiling both of my own R packages from source, bayesImageS and serrsBayes. I downloaded the source package bayesImageS_0.4-0 from CRAN and it compiled fine using clang 4.0.0. I ran the SMC-ABC example from the README and was pleased to see up to 800% CPU utilisation (indicating all 8 cores on my i7 were fully utilised). This indicates that OpenMP is working on clang 4.0.0, which would be a great reason to switch (if not for all of the other problems that I encountered!)

I was also able to compile the (pre-release) version of serrsBayes_0.3-4 and run the example from the package documentation. CPU utilisation was around 600% for fitSpectraSMC, which indicates that OpenMP is working for this R package as well.


From → R, Toolchain

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Ella Kaye on Ella Kaye

Computational Bayesian statistics

Bayes' Food Cake

A bit of statistics, a bit of cakes. - Blogs to Learn R from the Community

Computational Bayesian statistics

Richard Everitt's blog

Computational Bayesian statistics

Let's Look at the Figures

David Firth's blog

Nicholas Tierney

Computational Bayesian statistics

Mad (Data) Scientist

Musings, useful code etc. on R and data science

Another Astrostatistics Blog

The random musings of a reformed astronomer ...

Darren Wilkinson's research blog

Statistics, computing, data science, Bayes, stochastic modelling, systems biology and bioinformatics

(badness 10000)

Computational Bayesian statistics

Igor Kromin

Computational Bayesian statistics


I can't get no

Xi'an's Og

an attempt at bloggin, nothing more...

Sam Clifford

Postdoctoral Fellow, Bayesian Statistics, Aerosol Science

%d bloggers like this: