当我尝试使用mpi4py文件I / O时出现错误

时间:2019-04-04 17:50:33

标签: python python-3.x mpi mpi4py

我想打开一个文件,写入该文件,然后使用mpi4py关闭它。我有以下代码:


comm = MPI.COMM_WORLD
mode = MPI.MODE_CREATE | MPI.MODE_WRONLY

fh = MPI.File.Open(comm, "./datafile1.txt", mode)
line1 = str(comm.rank)*(comm.rank+1) + '\n'
line2 = chr(ord('a')+comm.rank)*(comm.rank+1) + '\n'
fh.Write_all(line1)
fh.Write_all(line2)
fh.Close()

由于某种原因,它不起作用,并且出现此错误:

    fh.Write_all(line1)
  File "mpi4py/MPI/File.pyx", line 345, in mpi4py.MPI.File.Write_all
  File "mpi4py/MPI/msgbuffer.pxi", line 1095, in mpi4py.MPI.message_io_write
  File "mpi4py/MPI/msgbuffer.pxi", line 1081, in mpi4py.MPI._p_msg_io.for_write
  File "mpi4py/MPI/msgbuffer.pxi", line 149, in mpi4py.MPI.message_simple
TypeError: message: expecting buffer or list/tuple

我对下一步该做什么感到困惑。任何帮助将不胜感激。

0 个答案:

没有答案