R在Windows XP上的多核处理 – 通过doMC和foreach

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

目前我正在创build4个脚本(每个脚本包含(我在1:100中)和(我在101:200中)等),这些脚本同时在4个不同的R会话中运行。 这似乎使用所有可用的CPU。

然而,我想这样做更高效一点。 一种解决scheme可能是使用“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)) 

任何解决scheme或build议?

为了完整起见,这里是对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可以以便携的方式使用它。

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

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