选项“核心"从软件包doParallel在Windows上没用? [英] Option "cores" from package doParallel useless on Windows?

查看:189
本文介绍了选项“核心"从软件包doParallel在Windows上没用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Linux计算机上,遵循 doParallel 的小插图,我使用doParallel::registerDoParallel(),然后使用options(cores = N),其中N是要与foreach一起使用的内核数.

On a Linux computer, following doParallel's vignette, I use doParallel::registerDoParallel() and then I use options(cores = N) where N is the number of cores I want to use with foreach.

我可以用foreach::getDoParWorkers()验证,当我更改选项cores时,它会自动更改foreach使用的内核数.

I can verify with foreach::getDoParWorkers() that when I change the option cores, it automatically changes the number of cores used by foreach.

但是,在Windows 10(R和软件包的最新版本)上,此选项似乎没有任何作用,因为更改其值不会更改foreach::getDoParWorkers()的值(在以下情况下初始化为3)调用doParallel::registerDoParallel()).

Yet, on Windows 10 (latest versions of R and packages), this option doesn't seem to have any effect as changing its value doesn't change the value of foreach::getDoParWorkers() (which is initialized at 3 when calling doParallel::registerDoParallel()).

可复制的示例:

doParallel::registerDoParallel()
options(cores = 1)
foreach::getDoParWorkers()
options(cores = 2)
foreach::getDoParWorkers()
options(cores = 4)
foreach::getDoParWorkers()

这是一个错误吗?在Windows上不行吗?

Is it a bug? Won't it work on Windows?

编辑:我知道如何以不同方式注册并行后端.目标是使用一次doParallel::registerDoParallel()注册一次(在我的程序包加载时),然后使用一个选项来更改所使用的内核数.这就是为什么我希望它也可以在Windows上运行.

I know how to register parallel backends differently. The goal is to use doParallel::registerDoParallel() registering once (at the loading of my package) and then use an option to change the number of cores used. This is why I want it to work also on Windows.

推荐答案

Rich Calaway软件包 doParallel 的维护者的答案:

The answer from the maintainer of package doParallel, Rich Calaway:

Windows不支持派生,这是并行(和doParallel)程序包使用"cores"参数的目的.因此,在Windows上,所有核心"参数都设置为1.要在Windows上使用doParallel的多个核心,请使用makeCluster创建多个工作程序群集cl,然后注册doParallel(cl).

Windows does not support forking, which is what the parallel (and doParallel) packages use the "cores" argument for. So, on Windows, all "cores" arguments are set to 1. To use multiple cores on Windows with doParallel, use makeCluster to create a multiple worker cluster cl, then registerDoParallel(cl).

所以这不是错误,而是Windows的非功能,真是遗憾.

So this isn't a bug, but a non-Windows feature, which is a pity.

这篇关于选项“核心"从软件包doParallel在Windows上没用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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