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
https://github.com/dmlc/xgboost/blob/master/doc/build.md#building-on-osx
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
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.
Alright, I figured this out.
create a new file vi ~/.R/Makevars
and drop this in
CC=clang-omp
CXX=clang-omp++
CXX1X=clang-omp++
SHLIB_OPENMP_CFLAGS=-fopenmp
SHLIB_OPENMP_CXXFLAGS=-fopenmp
SHLIB_OPENMP_FCFLAGS=-fopenmp
SHLIB_OPENMP_FFLAGS=-fopenmp
then install with
install.packages("xgboost", repos="http://dmlc.ml/drat/", type = "source")
If that didn't work use brew to install clang and gcc
brew reinstall clang-omp
then run the code above.
This seems to be fixed in a recent xgboost commit [1]
[1] https://github.com/dmlc/xgboost/commit/d754ce7dc19e0d7c7465999d464e13f9bf21b40d