如何让R使用计算机的所有核心? [英] How to let R use all the cores of the computer?

查看:164
本文介绍了如何让R使用计算机的所有核心?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经读到R仅使用一个CPU.如何让R使用所有可用的核来运行统计算法?

I have read that R uses only a single CPU. How can I let R use all the available cores to run statistical algorithms?

推荐答案

是的,对于初学者来说,请参见 CRAN上的高性能计算任务视图.这里列出了可用于在一台机器上支持并行计算的软件包的详细信息.

Yes, for starters, see the High Performance Computing Task View on CRAN. This lists details of packages that can be used in support of parallel computing on a single machine.

从R版本2.14.0开始,通过 parallel软件包内置了对并行计算的支持,其中包括对现有 snow 多核的稍作修改的版本软件包. parallel 程序包具有一个小插图,您应该阅读该小插图.您可以使用以下方式查看它:

From R version 2.14.0, there is inbuilt support for parallel computing via the parallel package, which includes slightly modified versions of the existing snow and multicore packages. The parallel package has a vignette that you should read. You can view it using:

vignette(package="parallel", topic = "parallel")

还有其他利用多核的方法,例如通过使用多线程BLAS进行线性代数计算.

There are other ways to exploit your multiple cores, for example via use of a multi-threaded BLAS for linear algebra computations.

这是否会加快您要执行的统计计算",将取决于这些统计计算"是什么.产生多个线程或工作者会产生设置,管理它们和收集结果的开销.有些操作看到使用多个内核/线程的好处(有些很大,有些很小),而其他操作由于这种额外的开销而减慢了速度.

Whether any of this will speed up the "statistics calculations" you want to do will depend on what those "statistics calculations" are. Spawning off multiple threads or workers entails an overhead cost to set them up, manage them and collect the results. Some operations see a benefit (some large, some small) of using multiple cores/threads, others are slowed down because of this extra overhead.

简而言之,不要期望通过使用 n 个内核而不是仅仅1个内核来减少计算时间 n 次.

In short, do not expect to get an n times decrease in your compute time by using n cores instead of just 1.

这篇关于如何让R使用计算机的所有核心?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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