找回密码
 注册
查看: 2921|回复: 0

R语言:clusterApply()函数中文帮助文档(中英文对照)

[复制链接]
发表于 2012-2-16 18:24:46 | 显示全部楼层 |阅读模式
clusterApply(parallel)
clusterApply()所属R语言包:parallel

                                        Apply Operations using Clusters
                                         申请使用集群的行动

                                         译者:生物统计家园网 机器人LoveR

描述----------Description----------

These functions provide several ways to parallelize computations using a cluster.
这些功能提供了使用集群并行计算的几种方法。


用法----------Usage----------


clusterCall(cl, fun, ...)
clusterApply(cl, x, fun, ...)
clusterApplyLB(cl, x, fun, ...)
clusterEvalQ(cl, expr)
clusterExport(cl, varlist, envir = .GlobalEnv)
clusterMap(cl, fun, ..., MoreArgs = NULL, RECYCLE = TRUE,
           SIMPLIFY = FALSE, USE.NAMES = TRUE)
clusterSplit(cl, seq)

parLapply(cl, X, fun, ...)
parSapply(cl, X, FUN, ..., simplify = TRUE, USE.NAMES = TRUE)
parApply(cl, X, MARGIN, FUN, ...)
parRapply(cl, x, FUN, ...)
parCapply(cl, x, FUN, ...)



参数----------Arguments----------

参数:cl
a cluster object, created by this package or by package snow.
群集对象,创建这个包或包snow。


参数:fun, FUN
function or character string naming a function.
函数或字符串命名函数。


参数:expr
expression to evaluate.
表达式。


参数:seq
vector to split.
向量分裂。


参数:varlist
character vector of names of objects to export.
特征向量导出的对象的名称。


参数:envir
environment from which t export variables
环境,从其中T出口变量


参数:x
a vector for clusterApply and clusterApplyLB, a matrix for parRapply and parCapply.
clusterApply和clusterApplyLB,一个parRapply和parCapply矩阵向量。


参数:...
additional arguments to pass to fun or FUN: beware of partial matching to earlier arguments.
额外的参数传递给fun或FUN:提防部分匹配更早的论点。


参数:MoreArgs
additional arguments for fun.
fun额外的参数。


参数:RECYCLE
logical; if true shorter arguments are recycled.
逻辑;如果真正的短参数被回收。


参数:X
A vector (atomic or list) for parLapply and parSapply, an array for parApply.
一个parLapply和parSapply,parApply阵列向量(原子或列表)。


参数:MARGIN
vector specifying the dimensions to use.
向量指定使用的尺寸。


参数:simplify, USE.NAMES
logical; see sapply.
逻辑;看到sapply。


参数:SIMPLIFY
logical; see mapply.
逻辑;看到mapply。


Details

详情----------Details----------

clusterCall calls a function fun with identical arguments ... on each node.
clusterCall调用函数fun具有相同的参数...每个节点上。

clusterEvalQ evaluates a literal expression on each cluster node.  It a parallel version of evalq, and is a convenience function invoking clusterCall.
clusterEvalQ评估每个群集节点上的文字表达。它的evalq,是一个方便的功能调用clusterCall并行版本。

clusterApply calls fun on the first node with arguments seq[[1]] and ..., on the second node with seq[[2]] and ..., and so on, recycling nodes as needed.
clusterApply要求fun带参数的第一个节点上seq[[1]]和...,seq[[2]]和...,等第二个节点上,回收所需的节点。

clusterApplyLB is a load balancing version of clusterApply.  If the length p of seq is not greater than the number of nodes n, then a job is sent to p nodes.  Otherwise the first n jobs are placed in order on the n nodes.  When the first job completes, the next job is placed on the node that has become free; this continues until all jobs are complete.  Using clusterApplyLB can result in better cluster utilization than using clusterApply, but increased communication can reduce performance.  Furthermore, the node that executes a particular job is non-deterministic.
clusterApplyLB是clusterApply的负载均衡的版本。如果长度pseq是不大于节点的数量n,然后一个作业发送到p节点。否则,第一个n工作置于为了n节点。当第一个作业完成后,接下来的工作就是安置,已成为自由节点;这种情况持续下去,直到所有的工作都是完整的。使用clusterApplyLB可以导致更好的集群利用率比使用clusterApply,但增加了沟通,可能会降低性能。此外,节点执行特定的工作具有不确定性。

clusterMap is a multi-argument version of clusterApply, analogous to mapply and Map.  If RECYCLE is true shorter arguments are recycled (and either none or all must be of length zero); otherwise, the result length is the length of the shortest argument.  Nodes are recycled if the length of the result is greater than the number of nodes.  (mapply always uses RECYCLE = TRUE, and has argument SIMPLIFY = TRUE. Map always uses RECYCLE = TRUE.)
clusterMap是clusterApply的多参数的版本,类似于mapply和Map。如果RECYCLE是真正的短参数回收(要么没有或都必须是长度为零),否则,结果的长度是最短的参数的长度。节点被回收,如果结果的长度大于节点的数量。 (mapply总是使用RECYCLE = TRUE,有参数SIMPLIFY = TRUE。Map总是使用RECYCLE = TRUE。)

clusterExport assigns the values on the master R process of the variables named in varlist to variables of the same names in the global environment (aka "workspace") of each node.  The environment on the master from which variables are exported defaults to the global environment.
clusterExport分配值主的Rvarlist命名的变量,在全球环境中的每个节点(又名“工作区”)的名称相同的变量过程。从出口的变量默认为全球环境的主环境。

clusterSplit splits seq into a consecutive piece for each cluster and returns the result as a list with length equal to the number of nodes.  Currently the pieces are chosen to be close to equal in length: the computation is done on the master.
clusterSplit分裂seq到每个群集连续片长度等于节点数量的列表,并传回结果。目前件选择长度接近等于:主计算。

parLapply, parSapply, and parApply are parallel versions of lapply, sapply and apply.
parLapply,parSapply,parApplylapply,sapply和apply并行版本。

parRapply and parCapply are parallel row and column apply functions for a matrix x; they may be slightly more efficient than parApply.
parRapply和parCapply是平行的矩阵的行和列apply功能x;他们可能会比parApply稍微更有效率。


值----------Value----------

For clusterCall, clusterEvalQ and clusterSplit, a list with one element per node.
clusterCall,clusterEvalQ和clusterSplit,每一个节点元素的列表。

For clusterApply and clusterApplyLB, a list the same length as seq.
clusterApply和clusterApplyLB,列表中的seq长度相同。

clusterMap follows mapply.
clusterMap如下mapply。

clusterExport returns nothing.
clusterExport返回任何内容。

parLapply returns a list the length of X.
parLapply长度X返回一个列表。

parSapply and parApply follow sapply and apply respectively.
parSapply和parApply的sapply和apply分别。

An error is signalled on the master if any of the workers produces an error.
一个错误信号主,如果有任何工人产生错误。


注意----------Note----------

These functions are almost identical to those in package snow.
这些功能几乎是相同的包snow。

Two exceptions: parLapply has argument X not x for consistency with lapply, and parSapply has been updated to match sapply.
两个例外:parLapply参数X不x的一致性lapply,parSapply已更新以匹配sapply。


作者(S)----------Author(s)----------



Luke Tierney and R Core.

Derived from the <span class="pkg">snow</span> package.




举例----------Examples----------


## Use option cl.core to choose an appropriate cluster size.[#使用选项cl.core来选择一个合适的簇大小。]
cl <- makeCluster(getOption("cl.cores", 2))

clusterApply(cl, 1:2, get("+"), 3)
xx <- 1
clusterExport(cl, "xx")
clusterCall(cl, function(y) xx + y, 2)

## Use clusterMap like an mapply example[#使用像mapply的例子clusterMap]
clusterMap(cl, function(x,y) seq_len(x) + y,
          c(a =  1, b = 2, c = 3), c(A = 10, B = 0, C = -10))


parSapply(cl, 1:20, get("+"), 3)
stopCluster(cl)

## A bootstrapping example, which can be done in many ways:[#自举的例子,在许多方面可以做的:]
cl <- makeCluster(getOption("cl.cores", 2))
clusterEvalQ(cl, {
  ## set up each worker.  Could also use clusterExport()[#设置每一个工人。也可以使用clusterExport()]
  library(boot)
  cd4.rg <- function(data, mle) MASS::mvrnorm(nrow(data), mle$m, mle$v)
  cd4.mle <- list(m = colMeans(cd4), v = var(cd4))
  NULL
})
res <- clusterEvalQ(cl, boot(cd4, corr, R = 100,
                    sim = "parametric", ran.gen = cd4.rg, mle = cd4.mle))
library(boot)
cd4.boot <- do.call(c, res)
boot.ci(cd4.boot,  type = c("norm", "basic", "perc"),
        conf = 0.9, h = atanh, hinv = tanh)
stopCluster(cl)

## or[#或]
library(boot)
run1 <- function(...) {
   library(boot)
   cd4.rg <- function(data, mle) MASS::mvrnorm(nrow(data), mle$m, mle$v)
   cd4.mle <- list(m = colMeans(cd4), v = var(cd4))
   boot(cd4, corr, R = 500, sim = "parametric",
        ran.gen = cd4.rg, mle = cd4.mle)
}
cl <- makeCluster(mc <- getOption("cl.cores", 2))
## to make this reproducible[#使这种重复性]
clusterSetRNGStream(cl, 123)
cd4.boot <- do.call(c, parLapply(cl, seq_len(mc), run1))
boot.ci(cd4.boot,  type = c("norm", "basic", "perc"),
        conf = 0.9, h = atanh, hinv = tanh)
stopCluster(cl)

转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。


注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|小黑屋|生物统计家园 网站价格

GMT+8, 2025-1-23 21:11 , Processed in 0.022693 second(s), 15 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表