gpt4 book ai didi

r - 如何使用 OpenMP 编译在 OS X 中使 R 包 xgboost 并行?

转载 作者:行者123 更新时间:2023-12-05 09:20:49 25 4
gpt4 key购买 nike

我在 R 中使用 xgb.cv 和 xgboost。但是,它不能并行工作

我的示例代码如下

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)

但是,上面的代码不起作用。我必须做什么才能使它们平行?

我在 xgboost 网站和 github 上找到了这个东西

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

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

但是,我无法运行

brew install clang-omp

brew install gcc --without-multilib

sudo 也不起作用谢谢

最佳答案

不幸的是,之前选择的答案现在已经过时了。 clang-omp 包在自制软件中不再可用。这就是对我有用的方法。

首先,在外壳上:

brew reinstall gcc --without-multilib

然后,使用以下内容创建文件 ~/.R/Makevars,确保更新路径,以便它们正确反射(reflect)安装的 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

最后,重新启动 R 或 RStudio 并从源代码重新安装包。

https://asieira.github.io/using-openmp-with-r-packages-in-os-x.html 上写了一篇关于此的小博客文章, 顺便说一下。

关于r - 如何使用 OpenMP 编译在 OS X 中使 R 包 xgboost 并行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35709524/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com