【发布时间】: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?