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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Oct 30 17:25:18 CET 2011


Author: jarioksa
Date: 2011-10-30 17:25:18 +0100 (Sun, 30 Oct 2011)
New Revision: 1967

Modified:
   pkg/vegan/DESCRIPTION
   pkg/vegan/R/oecosimu.R
   pkg/vegan/inst/ChangeLog
   pkg/vegan/man/oecosimu.Rd
Log:
a new proposal to set up parallel processing in vegan: see ChangeLog

Modified: pkg/vegan/DESCRIPTION
===================================================================
--- pkg/vegan/DESCRIPTION	2011-10-30 13:41:22 UTC (rev 1966)
+++ pkg/vegan/DESCRIPTION	2011-10-30 16:25:18 UTC (rev 1967)
@@ -1,7 +1,7 @@
 Package: vegan
 Title: Community Ecology Package
-Version: 2.1-5
-Date: October 20, 2011
+Version: 2.1-6
+Date: October 30, 2011
 Author: Jari Oksanen, F. Guillaume Blanchet, Roeland Kindt, Pierre Legendre, 
    Peter R. Minchin, R. B. O'Hara, Gavin L. Simpson, Peter Solymos, 
    M. Henry H. Stevens, Helene Wagner  

Modified: pkg/vegan/R/oecosimu.R
===================================================================
--- pkg/vegan/R/oecosimu.R	2011-10-30 13:41:22 UTC (rev 1966)
+++ pkg/vegan/R/oecosimu.R	2011-10-30 16:25:18 UTC (rev 1967)
@@ -2,10 +2,8 @@
     function(comm, nestfun, method, nsimul=99,
              burnin=0, thin=1, statistic = "statistic",
              alternative = c("two.sided", "less", "greater"),
-             parallel = 1, ..., kind = c("snow", "multicore"))
+             parallel = getOption("mc.cores", 1L), ..., cl)
 {
-    kind = match.arg(kind)
-    parallel = as.integer(parallel)
     alternative <- match.arg(alternative)
     nestfun <- match.fun(nestfun)
     applynestfun <-
@@ -58,9 +56,10 @@
     }
 
     ## socket cluster if parallel > 1 (and we can do this)
-    if (parallel > 1 && getRversion() >= "2.14" && require(parallel)) {
-##        if(.Platform$OS.type == "unix") {
-        if(kind == "multicore") {
+    if ((parallel > 1 || !missing(cl))  && require(parallel)) {
+        ## If 'cl' is given (and is a cluster), use it for socket clusters
+        hasClus <- !missing(cl) && inherits(cl, "cluster")
+        if(.Platform$OS.type == "unix" && !hasClus) {
             tmp <- mclapply(1:nsimul,
                             function(i)
                             applynestfun(x[,,i], fun=nestfun,
@@ -68,13 +67,17 @@
                             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)
+            ## if hasClus, do not set up and stop a temporary cluster
+            if (!hasClus) {
+                cl <- makeCluster(parallel)
+                ## make vegan functions available: others may be unavailable
+                clusterEvalQ(cl, library(vegan))
+            }
+            simind <- parApply(cl, x, 3, function(z)
                                applynestfun(z, fun = nestfun,
                                             statistic = statistic, ...))
-            stopCluster(oecoClus)
+            if (!hasClus)
+                stopCluster(cl)
         }
     } else {
         simind <- apply(x, 3, applynestfun, fun = nestfun,

Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog	2011-10-30 13:41:22 UTC (rev 1966)
+++ pkg/vegan/inst/ChangeLog	2011-10-30 16:25:18 UTC (rev 1967)
@@ -2,8 +2,24 @@
 
 VEGAN DEVEL VERSIONS at http://r-forge.r-project.org/
 
-Version 2.1-5 (opened October 20, 2011)
+Version 2.1-6 (opened October 30, 2011)
 
+	* oecosimu: new proposition for implementing parallel processing.
+	The relevant arguments are now 'parallel = getOption("mc.cores",
+	1)' and 'cl'. The 'parallel' defaults to 1 (no parallel
+	processing), but if the user sets the "mc.cores" option, all
+	parallel processing functions will automatically use that number
+	of paralle processes.  (The "mc.cores" argument is used by the
+	'parallel' package, but it is normally unset.)  The 'cl' argument
+	is an existing pre-defined socket ("snow") cluster, and if given,
+	that will be reused without resetting and closing. This (1) saves
+	time, (2) allows using of other packages than 'vegan' if user has
+	given command 'clusterEvalQ(library(foo))', and (3) makes
+	unix-like OS (incl. MacOS X and Linux) to use the socket
+	processing instead of forking.
+
+Version 2.1-5 (closed October 30, 2011)
+
 	* opened a new version with the release of vegan 2.0-1 on Oct 20,
 	2011.
 

Modified: pkg/vegan/man/oecosimu.Rd
===================================================================
--- pkg/vegan/man/oecosimu.Rd	2011-10-30 13:41:22 UTC (rev 1966)
+++ pkg/vegan/man/oecosimu.Rd	2011-10-30 16:25:18 UTC (rev 1967)
@@ -28,9 +28,8 @@
 
 \usage{
 oecosimu(comm, nestfun, method, nsimul = 99, burnin = 0, thin = 1,
-   statistic = "statistic", 
-   alternative = c("two.sided", "less", "greater"), parallel = 1, ...,
-   kind = c("snow", "multicore"))
+   statistic = "statistic", alternative = c("two.sided", "less", "greater"), 
+   parallel = getOption("mc.cores", 1L), ..., cl)
 \method{as.ts}{oecosimu}(x, ...)
 \method{as.mcmc}{oecosimu}(x)
 \method{density}{oecosimu}(x, ...)
@@ -87,15 +86,14 @@
   \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{cl}{A socket cluster created with
+    \code{\link[parallel]{makeCluster}} or similar.  Usually command
+    \code{clusterEvalQ(cl, library(vegan))} also must be given. If
+    other packages than \pkg{vegan} are needed for the \code{nestfun},
+    they must be evaluated similarly with
+    \code{\link[parallel]{clusterEvalQ}}. The socket clusters are used
+    in default only in Windows, but if \code{cl} is given, the
+    specified cluster will be used also in other operating systems.}
 
   \item{\dots}{Other arguments to functions.}
 }



More information about the Vegan-commits mailing list