OpenMP, OS-X and R

This is a quick technical post, that is as much about disseminating the information as putting it in a place where I can find it again in the future. I have been trying to use openMP in an R package that I am currently developing. OpenMP is supported by the popular gcc compiler. However, OS-X Xcode now ship with a clang compiler that does not support openMP. So first one needs to install gcc (from homebrew for instance). The thing is then to get R to actually use this gcc compiler. After many hours of struggle, I got it working by modifying the “~/.R/Makevars” file, in which clang must be replaced by gcc (or gcc-$version).

EDIT:
In the case where there is no .R folder and/or Makevar file, just create one. In order to replace clang by gcc, the two following lines suffice:

CC=gcc-4.9
CXX=g++-4.9

gcc-4.9 can of course be replace by any other compiler  you might want to use ( such as another version of gcc for instance), and an absolute path to the compiler can also be specified (see comment from kamvarz below)

Advertisements

2 thoughts on “OpenMP, OS-X and R

  1. kamvarz says:

    We ran into this problem a while ago as well. I took the route of installing gcc (and fortran) via http://hpc.sourceforge.net/. This installs to /usr/local/bin/gcc.

    I then set my ~/.R/Makevars to:

    CC=/usr/local/bin/gcc
    CXX=/usr/local/bin/g++
    FC=/usr/local/bin/gfortran
    F77=/usr/local/bin/gfortran
    #LFLAGS= -Lopenmp
    PKG_LIBS = -fopenmp -lgomp
    PKG_CFLAGS= -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp
    CFLAGS= -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s