[Vegan-commits] r1949 - in pkg/vegan: R inst man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Oct 11 21:00:48 CEST 2011


Author: jarioksa
Date: 2011-10-11 21:00:46 +0200 (Tue, 11 Oct 2011)
New Revision: 1949

Modified:
   pkg/vegan/R/oecosimu.R
   pkg/vegan/inst/ChangeLog
   pkg/vegan/man/oecosimu.Rd
Log:
implement multicore parallelization in oecosimu

Modified: pkg/vegan/R/oecosimu.R
===================================================================
--- pkg/vegan/R/oecosimu.R	2011-10-10 19:18:34 UTC (rev 1948)
+++ pkg/vegan/R/oecosimu.R	2011-10-11 19:00:46 UTC (rev 1949)
@@ -2,8 +2,10 @@
     function(comm, nestfun, method, nsimul=99,
              burnin=0, thin=1, statistic = "statistic",
              alternative = c("two.sided", "less", "greater"),
-             parallel = 1, ...)
+             parallel = 1, ..., kind = c("snow", "multicore"))
 {
+    kind = match.arg(kind)
+    parallel = as.integer(parallel)
     alternative <- match.arg(alternative)
     nestfun <- match.fun(nestfun)
     applynestfun <-
@@ -14,7 +16,6 @@
             else
                 tmp
     }
-
     if (inherits(comm, "simmat")) {
         x <- comm
         method <- attr(x, "method")
@@ -58,13 +59,23 @@
 
     ## socket cluster if parallel > 1 (and we can do this)
     if (parallel > 1 && getRversion() >= "2.14" && require(parallel)) {
-        oecoClus <- makePSOCKcluster(as.integer(parallel))
-        ## make vegan functions available: others may be unavailable
-        clusterEvalQ(oecoClus, library(vegan))
-        simind <- parApply(oecoClus, x, 3, function(z)
-                           applynestfun(z, fun = nestfun,
-                           statistic = statistic, ...))
-        stopCluster(oecoClus)
+##        if(.Platform$OS.type == "unix") {
+        if(kind == "multicore") {
+            tmp <- mclapply(1:nsimul,
+                            function(i)
+                            applynestfun(x[,,i], fun=nestfun,
+                                         statistic = statistic, ...),
+                            mc.cores = parallel)
+            simind <- do.call(cbind, tmp)
+        } else {
+            oecoClus <- makeCluster(parallel)
+            ## make vegan functions available: others may be unavailable
+            clusterEvalQ(oecoClus, library(vegan))
+            simind <- parApply(oecoClus, x, 3, function(z)
+                               applynestfun(z, fun = nestfun,
+                                            statistic = statistic, ...))
+            stopCluster(oecoClus)
+        }
     } else {
         simind <- apply(x, 3, applynestfun, fun = nestfun,
                         statistic = statistic, ...)

Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog	2011-10-10 19:18:34 UTC (rev 1948)
+++ pkg/vegan/inst/ChangeLog	2011-10-11 19:00:46 UTC (rev 1949)
@@ -39,14 +39,8 @@
 
 	* oecosimu: An attempt to set 'parallel' processing in evaluating
 	the statistic, and only evaluating the statistic -- the simulation
-	of null models is not influenced. This uses socket cluster and is
-	available in all operating systems. It seems that parallel
-	processing is only useful when the evaluation of the statistic is
-	slow (tens of seconds). Moreover, it seems that increasing the
-	number of parallel processes slows down calculations
-	(communication between processes?). Further, socket processing may
-	not find function in all packages, but 'vegan' is made known, and
-	'stats' and 'base' seem to be known.
+	of null models is not influenced. Both "multicore" (fork) and
+	"snow" (socket) style parallelization are implemented. 
 
 	* permutest.cca: implemented 'parallel' processing in
 	permutest.cca.  The parallelization only works in R 2.14.0 (alpha)

Modified: pkg/vegan/man/oecosimu.Rd
===================================================================
--- pkg/vegan/man/oecosimu.Rd	2011-10-10 19:18:34 UTC (rev 1948)
+++ pkg/vegan/man/oecosimu.Rd	2011-10-11 19:00:46 UTC (rev 1949)
@@ -29,7 +29,8 @@
 \usage{
 oecosimu(comm, nestfun, method, nsimul = 99, burnin = 0, thin = 1,
    statistic = "statistic", 
-   alternative = c("two.sided", "less", "greater"), parallel = 1, ...)
+   alternative = c("two.sided", "less", "greater"), parallel = 1, ...,
+   kind = c("snow", "multicore"))
 \method{as.ts}{oecosimu}(x, ...)
 \method{as.mcmc}{oecosimu}(x)
 \method{density}{oecosimu}(x, ...)
@@ -85,6 +86,17 @@
   \item{x}{An \code{oecosimu} result object.}
   \item{data}{Ignored argument of the generic function.}
   \item{xlab}{Label of the x-axis.}
+
+  \item{kind}{Kind of parallelization: \code{kind = "snow"} uses
+    socket clusters that are slow to set up, but work in all operating
+    systems, and \code{kind = "multicore"} uses fork clusters that are
+    usually faster, but only work in unix-like systems (Linux, MacOS
+    X). With \code{kind = "snow"}, the \code{nestfun} can only handle
+    functions of \pkg{base}, \pkg{stats} and \pkg{vegan}: other
+    function can cause an error and have an adverse effect on
+    computations for the rest of the session. The argument is intended
+    for testing, and will be probably removed later.}
+
   \item{\dots}{Other arguments to functions.}
 }
 



More information about the Vegan-commits mailing list