繁体   English   中英

在Windows XP上的R中进行多核处理 - 通过doMC和foreach

[英]multi-core processing in R on windows XP - via doMC and foreach

我发布这个问题是为了询问如何在Windows XP机器上优化R中多个处理器的使用。

目前我正在创建4个脚本(每个脚本用例如for(i in 1:100)和(i in 101:200)等)我同时在4个不同的R会话中运行。 这似乎使用了所有可用的cpu。

但是,我希望这样做更有效率。 一种解决方案可能是使用“doMC”和“foreach”软件包,但这在Windows机器上的R中是不可能的。

例如

library("foreach")
library("strucchange")
library("doMC") # would this be possible on a windows machine?
registerDoMC(2)  # for a computer with two cores (processors)
## Nile data with one breakpoint: the annual flows drop in 1898
## because the first Ashwan dam was built
data("Nile")
plot(Nile)

## F statistics indicate one breakpoint
fs.nile <- Fstats(Nile ~ 1)
plot(fs.nile)
breakpoints(fs.nile)     # , hpc = "foreach" --> It would be great to test this.
lines(breakpoints(fs.nile))

任何解决方案或建议?

尝试使用doSNOW并行后端 - 它在Windows上支持开箱即用。 与雪插座群集一起使用。

为了完整起见,这里是Tal的评论所要求的答案,它提供了一个简单而便携的替代方案。 答案包括跑步

 > library(snow)
 > help(makeCluster)

并从示例的顶部运行前三行代码:部分:

> cl <- makeCluster(c("localhost","localhost"), type = "SOCK")
> clusterApply(cl, 1:2, get("+"), 3)
[[1]]
[1] 4

[[2]]
[1] 5

> stopCluster(cl)
> .Platform$OS.type
[1] "windows"
> 

真的那么难吗?

doSNOW这样的附加软件包以及之后的foreach可以以便携的方式使用它。

您可以尝试doSMP REvolution Computing中的doSMP 有关更多信息,请参阅此博客文章: 使用R进行并行多核处理(在Windows上)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM