如何获得R以使用更多的CPU使用率? [英] How can I get R to use more CPU usage?

查看:315
本文介绍了如何获得R以使用更多的CPU使用率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到R并没有使用我所有的CPU,因此我希望将其大幅度增加(最多100%).我不希望它仅并行化一些功能;我希望R使用更多的CPU资源.我正在尝试使用lp()函数运行纯IP集打包程序.当前,我运行Windows,并且我的计算机上有4个内核.

I noticed that R doesn't use all of my CPU, and I want to increase that tremendously (upwards to 100%). I don't want it to just parallelize a few functions; I want R to use more of my CPU resources. I am trying to run a pure IP set packing program using the lp() function. Currently, I run windows and I have 4 cores on my computer.

我曾尝试过下雪,doParallel和foreach(尽管我不知道我到底对他们做什么).

I have tried to experiment with snow, doParallel, and foreach (though I do not know what I am doing with them really).

在我的代码中,我有这个...

In my code I have this...

library(foreach)
library(doParallel)
library(snowfall)

cl <- makeCluster(4)
registerDoParallel(cl)

sfInit(parallel = TRUE, cpus = 4)


#code that is taking a while to run but does not involve simulations/iterations

lp (......, all.int = TRUE)

sfStop()

R卡住并在很长时间内运行lp().我的CPU大约是25%,但是我该如何提高呢?

R gets stuck and runs lp() for a very long time. My CPU is around 25%, but how can I increase that?

推荐答案

将其发布为答案,因为注释中没有足够的空间.
这不是直接针对您的问题的答案,而是更多关于性能的答案.

Posting this as an answer because there's not enough space in a comment.
This is not an answer directly towards your question but more to the performance.

R默认情况下使用慢速统计库,默认情况下也只能使用单核.改进的库是OPENBLAS/ATLAS.但是,这些可能很难安装.
我个人最终使用本指南.

R uses slow statistical libraries by default which also can only use single core by default. Improved libraries are OPENBLAS/ATLAS. These however, can be a pain to install.
Personally I eventually got it working using this guide.

我最终使用了革命R open(RRO) + MKL,具有改进的BLAS库和多CPU支持.这是另一种R分布,应该具有比普通R快20倍的速度(我无法证实这一点,但是速度要快得多).

I ended up using Revolution R open(RRO) + MKL which has both improved BLAS libraries and multi-cpu support. It is an alternative R distribution which is supposed to have up to 20x the speed of regular R (I cannot confirm this, but it is alot faster).

此外,您可以检查 CRAN HPC软件包以查看是否有任何改进的支持lp功能的软件包.

Furthermore, you could check the CRAN HPC packages to see if there is any improved packages which support the lp function.

还有一些用于探索多CPU使用情况的软件包.
答案Gavin撰写的文章以及@ user3293236的以上答案显示了允许使用多个CPU的软件包的几种可能性.

There is also packages to explore multi cpu usage.
This answer by Gavin, as well as @user3293236's answer above show several possibilities for packages allowing multi CPU usage.

这篇关于如何获得R以使用更多的CPU使用率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆