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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Oct 5 14:33:34 CEST 2011


Author: jarioksa
Date: 2011-10-05 14:33:34 +0200 (Wed, 05 Oct 2011)
New Revision: 1931

Modified:
   pkg/vegan/R/oecosimu.R
   pkg/vegan/inst/ChangeLog
   pkg/vegan/man/oecosimu.Rd
Log:
parallel processing in evaluating the statistic (but not in simulation)

Modified: pkg/vegan/R/oecosimu.R
===================================================================
--- pkg/vegan/R/oecosimu.R	2011-10-04 19:42:47 UTC (rev 1930)
+++ pkg/vegan/R/oecosimu.R	2011-10-05 12:33:34 UTC (rev 1931)
@@ -2,7 +2,7 @@
     function(comm, nestfun, method, nsimul=99,
              burnin=0, thin=1, statistic = "statistic",
              alternative = c("two.sided", "less", "greater"),
-             ...)
+             parallel = 1, ...)
 {
     alternative <- match.arg(alternative)
     nestfun <- match.fun(nestfun)
@@ -54,7 +54,20 @@
         x <- simulate(nm, nsim = nsimul, burnin = burnin, thin = thin)
     }
 
-    simind <- apply(x, 3, applynestfun, fun = nestfun, statistic = statistic, ...) 
+    ## 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)
+    } else {
+        simind <- apply(x, 3, applynestfun, fun = nestfun,
+                        statistic = statistic, ...)
+    }
+    
     simind <- matrix(simind, ncol = nsimul)
 
     if (attr(x, "isSeq")) {

Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog	2011-10-04 19:42:47 UTC (rev 1930)
+++ pkg/vegan/inst/ChangeLog	2011-10-05 12:33:34 UTC (rev 1931)
@@ -4,6 +4,17 @@
 
 Version 2.1-3 (opened October 4, 2011)
 
+	* 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.
+
 	* permutest.cca: First attempt of setting 'parallel' processing in
 	permutest.cca. Currently the parallelization only works in R
 	2.14.0 (alpha) and later with the 'parallel' package, and in

Modified: pkg/vegan/man/oecosimu.Rd
===================================================================
--- pkg/vegan/man/oecosimu.Rd	2011-10-04 19:42:47 UTC (rev 1930)
+++ pkg/vegan/man/oecosimu.Rd	2011-10-05 12:33:34 UTC (rev 1931)
@@ -29,7 +29,7 @@
 \usage{
 oecosimu(comm, nestfun, method, nsimul = 99, burnin = 0, thin = 1,
    statistic = "statistic", 
-   alternative = c("two.sided", "less", "greater"), ...)
+   alternative = c("two.sided", "less", "greater"), parallel = 1, ...)
 \method{as.ts}{oecosimu}(x, ...)
 \method{as.mcmc}{oecosimu}(x)
 \method{density}{oecosimu}(x, ...)
@@ -72,6 +72,16 @@
   \item{alternative}{a character string specifying the alternative
     hypothesis, must be one of \code{"two.sided"} (default), \code{"greater"}
     or \code{"less"}.}
+  \item{parallel}{Use parallel processing with \code{parallel} number of
+    processes when evaluating the \code{statistic}. With \code{parallel
+    = 1} uses ordinary, non-parallel processing. The parallel processing
+    is done with \pkg{parallel} package which is available only for \R
+    2.14.0 and later, and uses socket clusters which are available for
+    all operating systems. Due to overhead in setting up and using the
+    cluster, parallel processing is only useful when the estimation of
+    the statistic is slow. Not all functions are available in parallel
+    processing: the error messages on missing functions can be
+    surprsing.} 
   \item{x}{An \code{oecosimu} result object.}
   \item{data}{Ignored argument of the generic function.}
   \item{xlab}{Label of the x-axis.}



More information about the Vegan-commits mailing list