并行模拟在同一文件上写入

Rem*_*i.b 5 parallel-processing file julia

我的目标是在一个集群上并行运行10,000个左右的Julia编码模拟(每个模拟独立于所有其他模拟).每个模拟都有一个数字输出(以及有关哪个模拟产生此数字的3列信息).因此,强制每个模拟在单独的文件上打印对我来说听起来有点愚蠢.

我可以安全地要求所有这些模拟在同一个文件上写入,或者如果两个模拟恰好在同一时间写入文件,这可能会导致错误吗?什么是最好的解决方案?

Sim*_*mon 4

下面是一个简单的示例,说明了一种方法,可以使用以下方法将一组 10000 个独立模拟设置为在 Julia 中并行运行pmap()

@everywhere function simulate(i)
    # we compute the simulation results here. In this case we just return
    # the simulation number and a random value
    x = rand()
    return (i,x)
end

x = pmap(simulate,1:10000)
# x is the array of tuples returned from all the simulations

showall(x)
# ... or we could write x to a file or do something else with it
Run Code Online (Sandbox Code Playgroud)

@everywhere需要确保该simulate()功能可用于所有进程,而不仅仅是一个进程。对第二个参数中的每个值并行pmap()调用一次,并返回 生成的所有结果的数组。simulate()simulate()