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

Posted by Jan on Stack Overflow See other posts from Stack Overflow or by Jan
Published on 2010-04-23T05:08:45Z Indexed on 2010/04/23 5:13 UTC
Read the original article Hit count: 287

Hi guys,

I'm posting this question to ask for advice on how to optimize the use of multiple processors from R on a Windows XP machine.

At the moment I'm creating 4 scripts (each script with e.g. for (i in 1:100) and (i in 101:200), etc) which I run in 4 different R sessions at the same time. This seems to use all the available cpu.

I however would like to do this a bit more efficient. One solution could be to use the "doMC" and the "foreach" package but this is not possible in R on a Windows machine.

e.g.

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))

Any solutions or advice?

Thanks, Jan

© Stack Overflow or respective owner

Related posts about r

    Related posts about Windows