The R Project SVN R

Rev

Rev 89188 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 89188 Rev 89220
Line 144... Line 144...
144
        assign(names[i], list[[i]], envir = defaultClusterOptions)
144
        assign(names[i], list[[i]], envir = defaultClusterOptions)
145
}
145
}
146
 
146
 
147
clusterStarters <- new.env()
147
clusterStarters <- new.env()
148
registerClusterType <- function(type, starter, make.default = FALSE) {
148
registerClusterType <- function(type, starter, make.default = FALSE) {
-
 
149
    if (missing(type))
-
 
150
        return(c("PSOCK", "FORK", names(clusterStarters)))
149
    if (exists(type, clusterStarters))
151
    if (exists(type, clusterStarters))
150
        warning(sprintf("replacing registration for cluster type '%s'", type))
152
        warning(sprintf("replacing registration for cluster type '%s'", type))
151
    assign(type, starter, clusterStarters)
153
    assign(type, starter, clusterStarters)
152
    if (make.default)
154
    if (make.default)
153
        setDefaultClusterOptions(type = type)
155
        setDefaultClusterOptions(type = type)
154
}
156
}
155
 
157
 
-
 
158
initRegisterClusterTypes <- function() {
-
 
159
    registerClusterType("SOCK", function(spec, ...)
-
 
160
        snow::makeSOCKcluster(names = spec, ...))
-
 
161
    registerClusterType("MPI", function(spec, ...)
-
 
162
        snow::makeMPIcluster(count = spec, ...))
-
 
163
    registerClusterType("MIRAI", function(spec, ...)
-
 
164
        mirai::make_cluster(n = spec, ...))
-
 
165
    registerClusterType("RPSOCK", function(spec, ...)
-
 
166
        parallelly::makeClusterPSOCK(workers = spec, ...))
-
 
167
}
-
 
168
 
156
makeCluster <-
169
makeCluster <-
157
    function (spec, type = getClusterOption("type"), ...)
170
    function (spec, type = getClusterOption("type"), ...)
158
{
171
{
159
    switch(type,
172
    switch(type,
160
           PSOCK = makePSOCKcluster(names = spec, ...),
173
           PSOCK = makePSOCKcluster(names = spec, ...),
161
           FORK = makeForkCluster(nnodes = spec, ...),
174
           FORK = makeForkCluster(nnodes = spec, ...),
162
           SOCK = snow::makeSOCKcluster(names = spec, ...),
-
 
163
           MPI = snow::makeMPIcluster(count = spec, ...),
-
 
164
           MIRAI = mirai::make_cluster(n = spec, ...),
-
 
165
           RPSOCK = parallelly::makeClusterPSOCK(workers = spec, ...),
-
 
166
           ## NWS = snow::makeNWScluster(names = spec, ...),
-
 
167
           if (exists(type, clusterStarters))
175
           if (exists(type, clusterStarters))
168
               get(type, clusterStarters)(spec, ...)
176
               get(type, clusterStarters)(spec, ...)
169
           else stop(sprintf("unknown cluster type: '%s'", type)))
177
           else stop(sprintf("unknown cluster type: '%s'", type)))
170
}
178
}
171
 
179