[R-sig-hpc] multicore performance question

Rainer M Krug R.M.Krug at gmail.com
Mon Jul 9 12:03:28 CEST 2012


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 09/07/12 10:49, Mauricio Zambrano-Bigiarini wrote:
> 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'


Well - I see a difference:

Without multicore:
  user  system elapsed
  0.020   0.000   0.023

With multicore:
  user  system elapsed
  0.012   0.024   0.048

Approximately the same for a few tries, and the two times factor one would expect (I use a dual core).

Or even more pronounced:

> nr <- 5000; X <- matrix(rnorm(1000), ncol=30, nrow=nr) set.seed(100);
> system.time(unlist(lapply(1:nr, FUN=fn1, x=X)))
   user  system elapsed
  0.224   0.004   0.229
> set.seed(100); system.time(unlist(mclapply(1:nr, FUN=fn1, x=X)))
   user  system elapsed
  0.120   0.044   0.174
> 

Cheers,

Rainer


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


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk/6rHAACgkQoYgNqgF2egqIbwCfWrRiqXkJU8HaNbeDBjVcEYvp
cD8An0vfecXhlB4BKElZFQvzg5gaHMUh
=Vvy2
-----END PGP SIGNATURE-----



More information about the R-sig-hpc mailing list