我尝试用不同的参数并行运行我自己的函数"EMGMM(y, startmy = 0)":
require(snow)
library(parallel)
tasks = list(
job1 = function(y) EMGMM(y=y, startmy = 0),
job2 = function(y) EMGMM(y=y, startmy = 1),
job3 = function(y) EMGMM(y=y, startmy = 2)
)
cl = makeCluster( length(tasks) )
clusterExport(cl, list("EMGMM"))
out = clusterApply(cl, tasks, ????)
stopCluster(cl)
但是我现在不知道如何调用"clusterApply"。每个作业中的y参数相同,startmy是my算法的起始参数。
谢谢。y是多维随机变量矩阵
这对我来说很好(这可能不是最好的解决方案):
require(snow)
library(parallel)
tasks = list(
job1 = function(y) EMGMM(y=y, startmy = 0),
job2 = function(y) EMGMM(y=y, startmy = 1),
job3 = function(y) EMGMM(y=y, startmy = 2)
)
cl = makeCluster( length(tasks) )
clusterExport(cl, ls())
clusterExport(cl, "dmvnorm") #needed in EMGMM()
out = clusterApply(cl, tasks, function(f) f(y))
stopCluster(cl)