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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Jan 22 19:08:58 CET 2012


Author: jarioksa
Date: 2012-01-22 19:08:58 +0100 (Sun, 22 Jan 2012)
New Revision: 2051

Modified:
   pkg/vegan/DESCRIPTION
   pkg/vegan/R/mantel.R
   pkg/vegan/R/mantel.partial.R
   pkg/vegan/inst/ChangeLog
   pkg/vegan/man/mantel.Rd
Log:
partial processing in mantel & mantel.partial

Modified: pkg/vegan/DESCRIPTION
===================================================================
--- pkg/vegan/DESCRIPTION	2012-01-20 12:27:11 UTC (rev 2050)
+++ pkg/vegan/DESCRIPTION	2012-01-22 18:08:58 UTC (rev 2051)
@@ -1,7 +1,7 @@
 Package: vegan
 Title: Community Ecology Package
-Version: 2.1-9
-Date: January 8, 2012
+Version: 2.1-10
+Date: January 22, 2012
 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/mantel.R
===================================================================
--- pkg/vegan/R/mantel.R	2012-01-20 12:27:11 UTC (rev 2050)
+++ pkg/vegan/R/mantel.R	2012-01-22 18:08:58 UTC (rev 2051)
@@ -1,6 +1,6 @@
-"mantel" <-
+`mantel` <-
   function (xdis, ydis, method = "pearson", permutations = 999, 
-            strata) 
+            strata, parallel = getOption("mc.cores")) 
 {
     xdis <- as.dist(xdis)
     ydis <- as.vector(as.dist(ydis))
@@ -31,9 +31,32 @@
             permvec <- (xmat[take, take])[asdist]
             drop(cor(permvec, ydis, method = method))
         }
-        perm <- sapply(1:permutations, function(i, ...) ptest(permat[i,], ...) )
+        ## Parallel processing
+        if (is.null(parallel) && getRversion() >= "2.15.0")
+            parallel <- get("default", envir = parallel:::.reg)
+        if (is.null(parallel) || getRversion() < "2.14.0")
+            parallel <- 1
+        hasClus <- inherits(parallel, "cluster")
+        if ((hasClus || parallel > 1)  && require(parallel)) {
+            if(.Platform$OS.type == "unix" && !hasClus) {
+                perm <- do.call(rbind,
+                               mclapply(1:permutations,
+                                        function(i, ...) ptest(permat[i,],...),
+                                        mc.cores = parallel))
+            } else {
+                if (!hasClus) {
+                    parallel <- makeCluster(parallel)
+                    clusterEvalQ(parallel, library(vegan))
+                }
+                perm <- parRapply(parallel, permat, ptest)
+                if (!hasClus)
+                    stopCluster(parallel)
+            }
+        } else {
+            perm <- sapply(1:permutations, function(i, ...) ptest(permat[i,], ...))
+        }
         signif <- (sum(perm >= statistic) + 1)/(permutations + 1)
-     }
+    }
     else {
         signif <- NA
         perm <- NULL

Modified: pkg/vegan/R/mantel.partial.R
===================================================================
--- pkg/vegan/R/mantel.partial.R	2012-01-20 12:27:11 UTC (rev 2050)
+++ pkg/vegan/R/mantel.partial.R	2012-01-22 18:08:58 UTC (rev 2051)
@@ -1,6 +1,6 @@
-"mantel.partial" <-
+`mantel.partial` <-
   function (xdis, ydis, zdis, method = "pearson", permutations = 999, 
-            strata) 
+            strata, parallel = getOption("mc.cores")) 
 {
     part.cor <- function(rxy, rxz, ryz) {
         (rxy - rxz * ryz)/sqrt(1-rxz*rxz)/sqrt(1-ryz*ryz)
@@ -39,7 +39,30 @@
             rxz <- cor(permvec, zdis, method = method)
             part.cor(rxy, rxz, ryz)
         }
-        perm <- sapply(1:permutations, function(i, ...) ptest(permat[i,], ...))
+        ## parallel processing
+        if (is.null(parallel) && getRversion() >= "2.15.0")
+            parallel <- get("default", envir = parallel:::.reg)
+        if (is.null(parallel) || getRversion() < "2.14.0")
+            parallel <- 1
+        hasClus <- inherits(parallel, "cluster")
+        if ((hasClus || parallel > 1)  && require(parallel)) {
+            if(.Platform$OS.type == "unix" && !hasClus) {
+                perm <- do.call(rbind,
+                               mclapply(1:permutations,
+                                        function(i, ...) ptest(permat[i,],...),
+                                        mc.cores = parallel))
+            } else {
+                if (!hasClus) {
+                    parallel <- makeCluster(parallel)
+                    clusterEvalQ(parallel, library(vegan))
+                }
+                perm <- parRapply(parallel, permat, ptest)
+                if (!hasClus)
+                    stopCluster(parallel)
+            }
+        } else {
+            perm <- sapply(1:permutations, function(i, ...) ptest(permat[i,], ...))
+        }
         signif <- (sum(perm >= statistic)+1)/(permutations + 1)
     }
     else {

Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog	2012-01-20 12:27:11 UTC (rev 2050)
+++ pkg/vegan/inst/ChangeLog	2012-01-22 18:08:58 UTC (rev 2051)
@@ -2,8 +2,12 @@
 
 VEGAN DEVEL VERSIONS at http://r-forge.r-project.org/
 
-Version 2.1-9 (opened January 8, 2012)
+Vegan 2.1-10 (opened January 22, 2012)
 
+	* mantel, mantel.partial: implemented parallel processing.
+	
+Version 2.1-9 (closed January 22, 2012)
+
 	* public launch of parallel processing in vegan. First step was to
 	explain the implementation in decision-vegan.Rnw. 
 

Modified: pkg/vegan/man/mantel.Rd
===================================================================
--- pkg/vegan/man/mantel.Rd	2012-01-20 12:27:11 UTC (rev 2050)
+++ pkg/vegan/man/mantel.Rd	2012-01-22 18:08:58 UTC (rev 2051)
@@ -13,9 +13,10 @@
 
 }
 \usage{
-mantel(xdis, ydis, method="pearson", permutations=999, strata)
+mantel(xdis, ydis, method="pearson", permutations=999, strata,
+    parallel = getOption("mc.cores"))
 mantel.partial(xdis, ydis, zdis, method = "pearson", permutations = 999, 
-    strata)
+    strata, parallel = getOption("mc.cores"))
 }
 
 \arguments{
@@ -27,6 +28,11 @@
   \item{strata}{An integer vector or factor specifying the strata for
     permutation. If supplied, observations are permuted only within the
     specified strata.}
+  \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.}
+
 }
 \details{
   Mantel statistic is simply a correlation between entries of two



More information about the Vegan-commits mailing list