Kppatel Patel Kppatel Patel - 3 months ago 38
R Question

How to make R package xgboost parallel in OS X with OpenMP compilation?

I am using xgb.cv and xgboost in R. However, it is not working as parallel

My example code as follow

library(xgboost)
library(parallel)
param <- list("objective" = "reg:logistic"
, "eval_metric" = "logloss"
,"nthread" = 8
,"bst:eta" = .025
,"bst:max_depth" = 3
,"lambda" = 1
,"lambda_bias" = 0
,"alpha" = .8
,"min_child_weight" = 3
,"subsample" = .9
,"colsample_bytree" = .6)
bst.cv3 = xgb.cv(param=param, data = x, label = y,
nfold = 3, nrounds=cv.nround, missing = NA
,prediction = TRUE)


However, above code is not working. What I have to do to make them parallel?

There is thing I found this on xgboost website and github


  1. https://github.com/dmlc/xgboost/blob/master/doc/build.md#building-on-osx

  2. https://github.com/dmlc/xgboost/issues/276



However, I am not able to run

brew install clang-omp


or

brew install gcc --without-multilib


with sudo also not working
Thanks

Answer

The previously selected answer unfortunately is now outdated. The clang-omp package is no longer available in homebrew. So here's what worked for me.

First, at the shell:

brew reinstall gcc --without-multilib

Then, create the file ~/.R/Makevars with the following contents, making sure to update the paths so they correctly reflect the gcc version homebrew installed:

CC=/usr/local/Cellar/gcc/6.1.0/bin/gcc-6
CXX=/usr/local/Cellar/gcc/6.1.0/bin/g++-6
SHLIB_CXXLD=/usr/local/Cellar/gcc/6.1.0/bin/g++-6
FC=/usr/local/Cellar/gcc/6.1.0/bin/gfortran-6
F77=/usr/local/Cellar/gcc/6.1.0/bin/gfortran-6
MAKE=make -j8

SHLIB_OPENMP_CFLAGS=-fopenmp
SHLIB_OPENMP_CXXFLAGS=-fopenmp
SHLIB_OPENMP_FCFLAGS=-fopenmp
SHLIB_OPENMP_FFLAGS=-fopenmp

Finally, restart R or RStudio and re-install the packages from source.

Wrote a small blog post about this at https://asieira.github.io/using-openmp-with-r-packages-in-os-x.html, by the way.

Comments