1.snow-clustercluster-level on a snow cluster
Snow-clustercluster-level on a snow cluster |
Clustersplit (cl, seq) |
Clustercall (cl, fun, ...) |
Clusterapply (cl, x, Fun, ...) |
CLUSTERAPPLYLB (cl, x, Fun, ...) |
Clusterevalq (cl, expr) |
Clusterexport (CL, list, EnviR =. GLOBALENV) |
Clustermap (cl, fun, ..., Moreargs = NULL, RECYCLE = TRUE) |
Arguments |
Description |
Cl |
Cluster objects |
Fun |
Function |
Expr |
The expression to be executed for each node |
Seq |
Vectors to be split into each node |
List |
List of global variables passed to each node |
EnviR |
Variable mode (default global) |
X |
Matrix |
... |
Additional parameters to pass to the fun |
Moreargs |
Additional parameters of fun |
RECYCLE |
logical value; If true, short parameters are recycled |
Detailed description
These are the basic functions for cluster computing. All programs running on child nodes run under the Trycatch function. That is, if any child nodes have errors, they will be marked on the master node. Much more detail will be considered later.
Clustercall (cl, fun, ...)
Use the same function fun for each node to output the results of each node as a list.
Clusterevalq (cl, expr)
Using fun for each node, unlike Clustercall, there are no additional parameter inputs.
Clusterapply (cl, x, Fun, ...)
Each parameter of the matrix X is assigned to each node separately, and the x parameter is calculated by looping over the number of nodes.
CLUSTERAPPLYLB (cl, x, Fun, ...)
Balanced load mode for clusterapply. If the x parameter exceeds the number of nodes, the remaining parameters are assigned to the node that has finished executing the task. Using this function makes better use of the cluster, but this approach reduces computational performance.
Clustermap (cl, fun, ..., Moreargs = NULL, RECYCLE = TRUE)
Similar to mapply, examples
Clustermap (cl,function (x, y) Seq_len (x) + y,c (a = 1, b = 2, c = 3), C (A = ten, B = 0, c = -10))
[[1]]
[1] 11
[[2]
[1] 1 2
[[3]]
[1]-9-8-7
1 2 3 4 5 6 7 8 9
Clusterexport (CL, list, EnviR =. GLOBALENV)
Pass the list parameter as a global variable to each node.
Clustersplit (cl, seq)
The SEQ sequence is assigned to each node, and the current version requires the sequence length to be the same as the number of nodes.
> Clustersplit (cl,c)
[[1]]
[1] 1
[[2]]
[1] 2
1 2 3 4 5 6
Comprehensive Examples:
CL <-Makesockcluster (C ("localhost", "localhost")) #建立集群
clusterapply (cl, 1:2, get ("+"), 3) #第一个节点算1 +3 The second node counts 2+3
Clusterevalq (CL, library (boot)) #每个节点加载lib
x<-1
clusterexport (cl, "x") #每个节点加载x作为环境变量
Clustercall (cl, function (y) x + y, 2) #每个节点计算一次1 +3
1 2 3 4 5 6
2.snow-parallel ———-Higher level snow functions
snow-parallel ———-higher level snow functions |
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, ...) |
parmm (cl, A, B) |
Arguments |
Description |
Cl |
Cluster objects |
Fun,fun |
Function |
X,x,a,b |
Matrix |
... |
Additional parameters to pass to the fun |
Moreargs |
Additional parameters of fun |
MARGIN |
Specify the vector dimension to use |
Simplify |
logical value; see sapply |
Use. NAMES |
logical value; see sapply |
Detailed description
1.parlapply,parsapply and parapply are parallel computational versions of lapply,sapply,apply.
2.parRapply and parcapply are the corresponding versions of the row and column calculations for apply, and are more efficient than parapply.
3.parmm:is a very simple (minded) parallel matrix multiply; It's intended as an illustration (not yet functional)
4. For more details see: Simple Network of workstations for R
Example
# # NOT run:
cl <-makesockcluster (C ("localhost", "localhost"))
parsapply (cl, 1:20, get ("+"), 3)
# # END ( Not run)
1 2 3 4
[1] 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
1
Snow-rand generating random numbers in a cluster |
CLUSTERSETUPRNG (cl, type = "Rngstream", ...) |
Clustersetuprngstream (cl, Seed=rep (12345,6), ...) |
CLUSTERSETUPSPRNG (cl, seed = round (2^32 * runif (1)), Prngkind = "Default", para = 0, ...) |
Describe
Initializes the random number in the cluster, using the L ' Ecuyer or SPRNG package to generate a random number (Rlecuyer and spring packages are required respectively).
Parameters |
Description |
Cl |
Cluster |
Type |
Random number generation mode type= "Rngstream" (default) type= "Sprng" |
Seed |
Random seeds |
Prngkind |
The generator form of sprng |
Para |
Additional parameters of the generator |
CLUSTERSETUPRNG (cl, type = "Rngstream", ...)
1. If the SPRNG parameter is set, the CLUSTERSETUPSPRNG function is called. 2. If you set the Rngstream parameter, the CLUSTERSETUPSPRNG function is called.
Clustersetuprngstream (cl, Seed=rep (12345,6), ...)
Load the RSPRNG package and initialize each node separately. See the INIT.SPRNG documentation for further details.
CLUSTERSETUPSPRNG (cl, seed = round (2^32 * runif (1)), Prngkind = "Default", para = 0, ...)
Load the Rlecuyer package, create a data stream at each node and assign it to each node.
# # Not run:
clustersetupsprng (CL)
clustersetupsprng (cl, seed=1234)
clustersetuprng (cl, Seed=rep (1,6))
# # END (not run)
1 2 3) 4 5
3.snow-startstop
snow-startstop starting and stopping snow Clusters |
makecluster (spec,type = Getclusterop |