I would like to split a large data.frame
into chunks and pass each individually to the different members of the cluster.
Something like:
library(parallel)
cl <- makeCluster(detectCores())
for (i in 1:detectCores()) {
clusterExport(cl, mydata[indices[[i]]], <extra option to specify a thread/process>)
}
Is this possible?
Here is an example that uses
clusterCall
inside afor
loop to send a different chunk of the data frame to each of the workers:Note that the call to
clusterCall
is subsettingcl
in order to execute the function on a single worker each time through thefor
loop.You can verify that the workers were properly initialized in this example using:
There are easier ways to do this, but this example minimizes the memory used by the master and the amount of data sent to each of the workers. This is important when the data frame is very large.