How to install XGBoost on OSX with multi-threading

一个人想着一个人 提交于 2019-12-05 15:17:12

Updated Solution

As of March 2019, R version 3.5.3, xgboost version 0.82.0.1, things have changed since my old answer. The following steps are based on the installation guide here, but differ slightly.

  1. brew install cmake or brew upgrade cmake (cmake --version shows 3.14.0 for me)
  2. brew install gcc or brew upgrade gcc (Note the version of gcc that gets installed. It should be located in /usr/local/bin. I get gcc 8.3.0 (gcc-8 --version))
  3. cd some/unimportant/directory
  4. git clone --recursive https://github.com/dmlc/xgboost
  5. cd xgboost/
  6. mkdir build
  7. cd build
  8. CC=gcc-8 CXX=g++-8 cmake .. -DR_LIB=ON
  9. make -j4
  10. sudo make install

Now restart/refresh RStudio and it should be installed

Test in R

set.seed(222)
N <- 2*10^5
p <- 350
x <- matrix(rnorm(N  * p), ncol = p)
y <- rnorm(N)

system.time(mymodel <- xgboost(
  # nthread = 4,
  data = x,
  label = y, 
  nrounds = 5, 
  objective = "reg:linear", 
  tree_method = "exact",
  max_depth = 10,
  min_child_weight = 1, 
  eta = 1, 
  subsample = 0.66, 
  colsample_bytree = 0.33
))

# Tested on 2018 MPB, xgboost version 0.82.0.1, multi-threaded version
# nthread = default:   7.4 seconds (elapsed)
# nthread = 1:        24.0 seconds (elapsed)
# nthread = 2:        13.7 seconds (elapsed)
# nthread = 4:         7.5 seconds (elapsed)

Old Answer

It's amazing how writing your question on StackOverflow often leads you directly to the answer. After spending hours on this, I figured out that I needed to change these three lines in ~/.R/Makevars

CC=gcc-5
CXX=g++-5
CXX1X = g++-5

to

CC=gcc-6
CXX=g++-6
CXX1X = g++-6

Also, I ended up installing xgboost from the "drat" repo

install.packages("drat", repos="https://cran.rstudio.com")
drat:::addRepo("dmlc")
install.packages("xgboost", repos="http://dmlc.ml/drat/", type = "source")

My approach is after your first(update gcc) and second(clone) steps, no need to build anything(they are for other languages like python)

3) update ~/.R/Makevars

https://github.com/dmlc/xgboost/issues/1136

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

4) from the clone xgboost/R-package/configure change ac_pkg_openmp to yes https://github.com/dmlc/xgboost/issues/2503

5) in xgboost/R-package type R CMD INSTALL . http://xgboost.readthedocs.io/en/latest/build.html#r-package-installation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!