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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Nov 2 09:09:02 CET 2011


Author: jarioksa
Date: 2011-11-02 09:09:02 +0100 (Wed, 02 Nov 2011)
New Revision: 1981

Modified:
   pkg/vegan/R/oecosimu.R
   pkg/vegan/inst/ChangeLog
   pkg/vegan/man/oecosimu.Rd
Log:
Proposal for parallel UI was improved following comments by
Peter Solymos: the only arg is 'parallel' which can now be
either the number of created parallel processes or a predefined
socket cluster (or NULL for the default cluster in R-devel)


Modified: pkg/vegan/R/oecosimu.R
===================================================================
--- pkg/vegan/R/oecosimu.R	2011-11-01 19:26:52 UTC (rev 1980)
+++ pkg/vegan/R/oecosimu.R	2011-11-02 08:09:02 UTC (rev 1981)
@@ -2,7 +2,7 @@
     function(comm, nestfun, method, nsimul=99,
              burnin=0, thin=1, statistic = "statistic",
              alternative = c("two.sided", "less", "greater"),
-             parallel = getOption("mc.cores", 1L), ..., cl)
+             parallel = getOption("mc.cores", 1L), ...)
 {
     alternative <- match.arg(alternative)
     nestfun <- match.fun(nestfun)
@@ -55,10 +55,11 @@
         x <- simulate(nm, nsim = nsimul, burnin = burnin, thin = thin)
     }
 
-    ## socket cluster if parallel > 1 (and we can do this)
-    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")
+    ## Go to parallel processing if 'parallel > 1' or 'parallel' could
+    ## be a pre-defined socket cluster or 'parallel = NULL' in which
+    ## case it could be setDefaultCluster (or a user error)
+    hasClus <- inherits(parallel, "cluster") || is.null(parallel)
+    if ((hasClus || parallel > 1)  && require(parallel)) {
         if(.Platform$OS.type == "unix" && !hasClus) {
             tmp <- mclapply(1:nsimul,
                             function(i)
@@ -69,15 +70,15 @@
         } else {
             ## if hasClus, do not set up and stop a temporary cluster
             if (!hasClus) {
-                cl <- makeCluster(parallel)
+                parallel <- makeCluster(parallel)
                 ## make vegan functions available: others may be unavailable
-                clusterEvalQ(cl, library(vegan))
+                clusterEvalQ(parallel, library(vegan))
             }
-            simind <- parApply(cl, x, 3, function(z)
+            simind <- parApply(parallel, x, 3, function(z)
                                applynestfun(z, fun = nestfun,
                                             statistic = statistic, ...))
             if (!hasClus)
-                stopCluster(cl)
+                stopCluster(parallel)
         }
     } else {
         simind <- apply(x, 3, applynestfun, fun = nestfun,

Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog	2011-11-01 19:26:52 UTC (rev 1980)
+++ pkg/vegan/inst/ChangeLog	2011-11-02 08:09:02 UTC (rev 1981)
@@ -17,19 +17,25 @@
 	add points as per
 	https://stat.ethz.ch/pipermail/r-help/2011-October/293955.html
 
-	* 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.
+	* oecosimu: new proposition for implementing parallel processing
+	following suggestions of Peter Solymos.  The only relevant
+	argument is now 'parallel' which can be either the number of
+	parallel processes (defaults getOption("mc.cores", 1)) or a
+	pre-defined socket cluster or NULL in which case it is taken as
+	the default cluster defined by setDefaultCluster (this last option
+	only works in R-to-be-2.15.0 unstable, and using NULL is a user
+	error in R 2.14.0 and hence undocumented). 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 parallel processes.  (The "mc.cores" argument is
+	used by the 'parallel' package, but it is normally unset.) If
+	'parallel' is a socket cluster or there is a default cluster
+	('parallel = NULL'), this will be used without setting up and
+	closing the cluster. 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)
 

Modified: pkg/vegan/man/oecosimu.Rd
===================================================================
--- pkg/vegan/man/oecosimu.Rd	2011-11-01 19:26:52 UTC (rev 1980)
+++ pkg/vegan/man/oecosimu.Rd	2011-11-02 08:09:02 UTC (rev 1981)
@@ -29,7 +29,7 @@
 \usage{
 oecosimu(comm, nestfun, method, nsimul = 99, burnin = 0, thin = 1,
    statistic = "statistic", alternative = c("two.sided", "less", "greater"), 
-   parallel = getOption("mc.cores", 1L), ..., cl)
+   parallel = getOption("mc.cores", 1L), ...)
 \method{as.ts}{oecosimu}(x, ...)
 \method{as.mcmc}{oecosimu}(x)
 \method{density}{oecosimu}(x, ...)
@@ -72,29 +72,13 @@
   \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{parallel}{Number of parallel processes or a predefined socket
+    cluster.  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.}
   \item{x}{An \code{oecosimu} result object.}
   \item{data}{Ignored argument of the generic function.}
   \item{xlab}{Label of the x-axis.}
-
-  \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