【问题标题】:How to run a own function with clusterApply several times parallel如何使用 clusterApply 并行运行自己的函数多次
【发布时间】:2014-07-18 19:00:19
【问题描述】:

我尝试使用不同的参数并行运行我自己的函数“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 算法的起始参数。

【问题讨论】:

  • 能否请您提供您的函数EMGMM 的代码和一些代表性数据?
  • 没有可重现的例子,很难说。但是,当您将jobX 重写为function() 而不是function(y) 以及尝试clusterApply(cl, tasks, function(f) f() ) 时会发生什么?

标签: r snow


【解决方案1】:

谢谢:) 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)

【讨论】:

    猜你喜欢
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多