13

so I try to run a package called BTYDplus when I load it I got this warning

This data.table install has not detected OpenMP support. It will work but slower in single threaded mode.

I could run it without OpenMP but it is very slow, so I tried to install openMP by following this tutorial http://thecoatlessprofessor.com/programming/openmp-in-r-on-os-x/ but I stuck at Enabling R to Compile Code with OpenMP on OS X part specifically when I try to run vim ~/.R/Makevars/. It resulted with "~/.R/Makevars/" Illegal file name.

any suggestion on how to tell R to use GCC ?

william
  • 131
  • 1
  • 5
  • 1
    `"~/.R/Makevars/"` would be a folder, not a file. Maybe it should be without the trailing `/`? – rosscova Dec 01 '16 at 07:46
  • @rosscova I just tried it, I made a folder .R and make a file called Makevars. after that I enter the configuration. but no luck :( – william Dec 01 '16 at 07:55
  • Are you sure the `.R` folder wasn't already there? It's hidden, but I think it should be part of a regular installation of R (someone please correct me if I'm wrong here?) – rosscova Dec 01 '16 at 08:00
  • 1
    `"it is very slow"` That surprises me. I still use 1.9.6, which does not provide OpenMP support, and it is far from slow. – Roland Dec 01 '16 at 08:17
  • Try following the instructions [by the data.table maintainers](https://github.com/Rdatatable/data.table/wiki/Installation). – Roland Dec 01 '16 at 08:20
  • @rosscovaIt's from the link that roland provided I got the impression that it might not exist. `likely you need to create the .R directory and the file Makevars in it if it doesn't already exist.` – william Dec 01 '16 at 08:30
  • @Roland hmm, maybe it is very slow because i use 500 chain for markov ? I have tried to follow the instruction on the link you provided. but no luck. – william Dec 01 '16 at 08:32
  • I fail to see how a Markov chain is related to package data.table and how enabling OpenMP within data.table would help with its performance. You should benchmark to see if data.table is your actual bottleneck, which I seriously doubt. – Roland Dec 01 '16 at 08:38
  • @Roland any tips on how to do that ? – william Dec 01 '16 at 08:46
  • `help("Rprof")` – Roland Dec 01 '16 at 08:49
  • 1
    It would still be interesting to find out what is wrong here. I followed the instruction on the data.table GitHub mentioned by @Roland, but get the same warning on loading the package.. – altabq Dec 14 '16 at 16:39

2 Answers2

3

If you are using clang to compile OpenMP code you will need libomp. I found the easiest way to get it is through homebrew with brew install libomp.

2

Although it is possible to get openmp compilation working on a Mac Sierra by updating clang (not sure if newer versions of MacOS have fixed this by updating clang) as in Enable OpenMP support in clang in Mac OS X (sierra) it is also possible to get Apple's default clang to work. Simple add the following to ~/.R/Makevars

SHLIB_OPENMP_CFLAGS=-Xpreprocessor -fopenmp
SHLIB_OPENMP_CXXFLAGS=-Xpreprocessor -fopenmp

This takes advantage of special CXX/CFLAGS R packages ought to use when compiling OpenMP packages, and that

Apple Clang does allow you to process the OpenMP pragmas with -Xpreprocessor -fopenmp, and then you can manually link to the OpenMP library.

More details here.

Andrew M
  • 490
  • 5
  • 11