beginCluster
creates, and endCluster
deletes a 'snow' cluster object. This object can be used for multi-core computing with those 'raster' functions that support it.
beginCluster
determines the number of nodes (cores) that are available and uses all of them (unless the argument n
is used).
NOTE: beginCluster may fail when the package 'nws' is installed. You can fix that by removing the 'nws' package, or by setting the cluster type manually, e.g. beginCluster(type="SOCK")
endCluster closes the cluster and removes the object.
The use of the cluster is automatic in these functions" predict, projectRaster, resample
and in extract
when using polygons.
clusterR
is a flexible interface for using cluster with other functions. This function only works with functions from the raster package that return Raster* objects that operate on a cell by cell basis and return an object with the same number of cells as the input raster object(s). Among other functions, it does _not_ work with mrege, crop, mosaic, (dis)aggregate, resample, projectRaster, focal, distance, direction.beginCluster(n, type, nice, exclude)
endCluster()
clusterR(x, fun, args=NULL, filename='', cl=NULL, m=2, ...)
#beginCluster()
beginCluster(type="SOCK")
r <- raster()
r[] <- 1:ncell(r)
x <- clusterR(r, sqrt, verbose=T)
f1 <- function(x) calc(x, sqrt)
y <- clusterR(r, f1)
s <- stack(r, r*2, r*3)
f2 <- function(x) calc(x, range)
z <- clusterR(s, f2)
pts <- matrix(c(0,0, 45,45), ncol=2, byrow=T)
d <- clusterR(r, distanceFromPoints, args=list(xy=pts))
endCluster()
Run the code above in your browser using DataLab