| latrend-parallel | R Documentation |
The model estimation functions support parallel computation through the use of the foreach mechanism. In order to make use of parallel execution, a parallel back-end must be registered.
On Windows, the parallel-package can be used to define parallel socket workers.
nCores <- parallel::detectCores(logical = FALSE) cl <- parallel::makeCluster(nCores)
Then, register the cluster as the parallel back-end using the doParallel package:
doParallel::registerDoParallel(cl)
If you defined your own lcMethod or lcModel extension classes, make sure to load them on the workers as well.
This can be done, for example, using:
parallel::clusterEvalQ(cl,
expr = setClass('lcMethodMyImpl', contains = "lcMethod"))
On Unix systems, it is easier to setup parallelization as the R process is forked.
In this example we use the doMC package:
nCores <- parallel::detectCores(logical = FALSE) doMC::registerDoMC(nCores)
latrendRep, latrendBatch, latrendBoot, latrendCV
data(latrendData) # parallel latrendRep() method <- lcMethodLMKM(Y ~ Time, id = "Id", time = "Time") models <- latrendRep(method, data = latrendData, .rep = 5, parallel = TRUE) # parallel latrendBatch() methods <- lcMethods(method, nClusters = 1:3) models <- latrendBatch(methods, data = latrendData, parallel = TRUE)