简体   繁体   English

如何通过OpenMP编译在OS X中并行处理R包xgboost?

[英]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 我在R中使用xgb.cv和xgboost。但是,它不能并行运行

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 我在xgboost网站和github上发现了这个东西

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

  2. https://github.com/dmlc/xgboost/issues/276 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. 自制软件中不再提供clang-omp软件包。 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: 然后,使用以下内容创建文件~/.R/Makevars ,并确保更新路径,以便它们正确反映所安装的gcc版本homebrew:

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. 最后,重新启动R或RStudio,然后从源代码重新安装软件包。

Wrote a small blog post about this at https://asieira.github.io/using-openmp-with-r-packages-in-os-x.html , by the way. 顺便说一句,在https://asieira.github.io/using-openmp-with-r-packages-in-os-x.html上写了一篇有关此问题的小博客文章。

Alright, I figured this out. 好吧,我知道了。

create a new file vi ~/.R/Makevars and drop this in 创建一个新文件vi ~/.R/Makevars并将其放入

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") 然后使用install.packages("xgboost", repos="http://dmlc.ml/drat/", type = "source")

If that didn't work use brew to install clang and gcc 如果那不起作用,请使用brew安装clang和gcc

brew reinstall clang-omp

then run the code above. 然后运行上面的代码。

This seems to be fixed in a recent xgboost commit [1] 这似乎在最近的xgboost提交中已解决[1]

[1] https://github.com/dmlc/xgboost/commit/d754ce7dc19e0d7c7465999d464e13f9bf21b40d [1] https://github.com/dmlc/xgboost/commit/d754ce7dc19e0d7c7465999d464e13f9bf21b40d

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM