我在macOS High Sierra上使用Anaconda环境,即使我将nthread参数设置为8,也无法使用8线程运行XGBoost。在
python代码是这样的。当我运行它时,我通过查看htop来监视执行情况。只有一个过程是100%。在
clf = xgb.XGBClassifier(
**xgb_params,
n_estimators=1000,
nthread=8
)
然后我在网上搜索,找到了这个链接。有人提到这个,我就照做了。在
https://www.ibm.com/developerworks/community/blogs/jfp/entry/Installing_XGBoost_on_Mac_OSX?lang=en
^{pr2}$在看到这些信息后,我在xgboost配置中添加了以下行
export CC = gcc-8
export CXX = g++-8
当构建完成时。我又试了一次,什么也没变。在
所以,我一直在寻找解决办法。我找到了这个页面。在
然后我跑了下面的一行。在
brew install llvm
我试着在那个网站上做这个例子。我创建了一个名为hello.c的文件,并将以下代码放入其中。在
#include <omp.h>
#include <stdio.h>
int main() {
#pragma omp parallel
printf("Hello from thread %d, nthreads %d\n", omp_get_thread_num(),
omp_get_num_threads());
}
然后我试着像上面提到的那样编译它。在
clang -fopenmp hello.c -o hello
成功了!我还尝试了gcc-8,如下所示。在
gcc-8 -fopenmp hello.c -o hello
它也奏效了。这是我运行/hello时的输出
➜ ~ ./hello
Hello from thread 4, nthreads 8
Hello from thread 7, nthreads 8
Hello from thread 2, nthreads 8
Hello from thread 1, nthreads 8
Hello from thread 6, nthreads 8
Hello from thread 3, nthreads 8
Hello from thread 0, nthreads 8
Hello from thread 5, nthreads 8
所以,我在xgboost配置文件中添加了gcc-8,并且gcc-8能够与-fopenmp选项并行运行,如您所见。但是,即使我用这个设置编译XGBoost并将nthread参数设置为8,它也不会并行运行。在
有没有办法让我再试试?在
编辑1:我尝试了更复杂的代码来确保并行处理有效。我试了this code。输出显示8个线程工作。我也可以通过输入htop来查看它。在
➜ ~ clang -fopenmp OpenMP.c -o OpenMP
➜ ~ ./OpenMP
---- Serial
---- Serial done in 37.058571 seconds.
---- Parallel
---- Parallel done in 9.674641 seconds.
---- Check
Passed
编辑2:我安装了gcc-7并执行了相同的过程。它也不起作用。在
目前没有回答
相关问题 更多 >
编程相关推荐