[R-sig-hpc] multicore performance question

Mauricio Zambrano-Bigiarini mauricio.zambrano at jrc.ec.europa.eu
Mon Jul 9 10:49:54 CEST 2012


Dear list,

I need to evaluate a vectorial function (~30 dimensions), and I would 
like to know if it is possible to take advantage of a multicore machine.

So far, I'm using the multicore package, and I'm not getting any time 
saving. I guess the larger the computation time the larger the gain in 
performance, and probably that is the reason why I'm not speeding up my 
computations by using multicore.

However, I would like to ask you if the reason for not getting any time 
saving by using 'multicore' is the short time of my computations OR  the 
way in which I defined the function to be run (fn and fn1):

----------- START --------------
library(multicore)

  fn <- function(x) {
     n <- length(x)
     return(1 + (1/4000) * sum(x^2) - prod(cos(x/sqrt(seq(1:n)))))
  }

  fn1 <- function(i, x) fn(x[i,])

  nr <- 500
  X <- matrix(rnorm(1000), ncol=30, nrow=nr)

  # No multicore
  set.seed(100)
  system.time(
    unlist(lapply(1:nr, FUN=fn1, x=X))
  )

  # multicore
  set.seed(100)
  system.time(
    unlist(mclapply(1:nr, FUN=fn1, x=X, mc.cores=6))
  )

sessionInfo()
R version 2.15.0 (2012-03-30)
Platform: x86_64-redhat-linux-gnu (64-bit)

locale:
  [1] LC_CTYPE=en_GB.utf8       LC_NUMERIC=C
  [3] LC_TIME=en_GB.utf8        LC_COLLATE=en_GB.utf8
  [5] LC_MONETARY=en_GB.utf8    LC_MESSAGES=en_GB.utf8
  [7] LC_PAPER=C                LC_NAME=C
  [9] LC_ADDRESS=C              LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_GB.utf8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] multicore_0.1-7  hydroPSO_0.1-57  hydroTSM_0.3-5-2 xts_0.8-6
[5] zoo_1.7-7        sp_0.9-99

loaded via a namespace (and not attached):
[1] automap_1.0-12 class_7.3-4    cluster_1.14.2 e1071_1.6 
grid_2.15.0
[6] gstat_1.0-12   Hmisc_3.9-3    lattice_0.20-6 tools_2.15.0

----------- END --------------


any comment will be very much appreciated.


Thanks in advance,


Mauricio Zambrano-Bigiarini

-- 
====================================================
Water Resources Unit
Institute for Environment and Sustainability (IES)
Joint Research Centre (JRC), European Commission
webinfo    : http://floods.jrc.ec.europa.eu/
====================================================
DISCLAIMER:\ "The views expressed are purely those of th...{{dropped:10}}



More information about the R-sig-hpc mailing list