【问题标题】:mpi processes working in a burstmpi 进程突发工作
【发布时间】:2014-10-12 05:38:40
【问题描述】:

我正在使用 mpi4py 对分布式应用程序进行建模。

我有 n 个进程访问共享文件并在执行期间将一些日志写入共享文件。我注意到日志没有统一写入。以下是如何将日志写入共享文件的示例:

process0.log0
process0.log1
process0.log2
process0.log3
process0.log4
process2.log0
process2.log1
process2.log2
process1.log0
process1.log1

理想情况下应该是这样的:

process0.log0
process1.log0
process2.log0
process0.log1
process2.log1
process1.log1
process0.log2

谁能告诉我我的实现可能有什么问题?我正在使用 Pickle 模块写入文件。

以下是转储日志的函数:

import pickle

log_file_name = "store.log"

def writeLog(data):
  try:
    with open(log_file_name,"a") as fp:
        pickle.dump(obj=data,file=fp)
  except:
    with open(log_file_name,"w") as fp:
        pickle.dump(obj=data,file=fp)

def readLog():
 data = []
 try:
    with open(log_file_name,"r") as fp:
        while True:
            data.append(pickle.load(fp))
    return data
 except EOFError:
    return data

所有n个进程都访问这个函数来转储数据

【问题讨论】:

  • 请分享您的实现代码。以便我们找到解决方法
  • @sundarnatarajСундар 完成
  • 您的 MPI 分发策略是worker pool 还是scatter-gather

标签: python mpi pickle


【解决方案1】:

有很多问题/答案可以解释您在这里看到的现象:

尽管这些(大部分)是在谈论打印到屏幕上,但问题是一样的。 MPI 是一种分布式模型,这意味着某些进程将比其他进程执行得更快,并且每次可能会根据每个进程的工作负载/顺序而采用不同的顺序。

如果顺序很重要,您可以使用同步功能来强制执行它,或者您可以使用像 MPI I/O 这样更花哨的东西来写入文件(不是我的专长,所以我不能告诉你更多关于它的信息)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-02-19
    • 1970-01-01
    • 2018-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-28
    相关资源
    最近更新 更多