[R] %dopar% parallel processing experiment

ivo welch ivowel at gmail.com
Sat Jul 2 19:32:35 CEST 2011


dear R experts---

I am experimenting with multicore processing, so far with pretty
disappointing results.  Here is my simple example:

A <- 100000
randvalues <- abs(rnorm(A))
minfn <- function( x, i ) { log(abs(x))+x^3+i/A+randvalues[i] }  ## an
arbitrary function

ARGV <- commandArgs(trailingOnly=TRUE)

if (ARGV[1] == "do-onecore") {
   library(foreach)
   discard <- foreach(i = 1:A) %do% uniroot( minfn, c(1e-20,9e20), i ) } else
if (ARGV[1] == "do-multicore") {
   library(doMC)
   registerDoMC()
   cat("You have", getDoParWorkers(), "cores\n")
   discard <- foreach(i = 1:A) %dopar% uniroot( minfn, c(1e-20,9e20), i ) } else
if (ARGV[1] == "plain")
   for (i in 1:A) discard <- uniroot( minfn, c(1e-20,9e20), i ) else
cat("sorry, but argument", ARGV[1], "is not plain|do-onecore|do-multicore\n")


on my Mac Pro 3,1 (2 quad-cores), R 2.12.0, which reports 8 cores,

  "plain" takes about 68 seconds (real and user, using the unix timing
function).
  "do-onecore" takes about 300 seconds.
  "do-multicore" takes about 210 seconds real, (300 seconds user).

this seems pretty disappointing.  the cores are not used for the most
part, either.  feedback appreciated.

/iaw


----
Ivo Welch (ivo.welch at gmail.com)



More information about the R-help mailing list