0
logging
モジュールの共有ファイルを使用するファイルハンドラをmpi4py
にしようとしました。しかし、私はそれを書くことはできません。mpi4pyで共有MPIファイルに書き込めません
プログラム:
from mpi4py import MPI
import io
class MPILogFile(object):
def __init__(self, comm, filename, mode):
self.file_handle = MPI.File.Open(comm, filename, mode)
self.file_handle.Set_atomicity(True)
self.buffer = io.StringIO()
def write(self, msg):
print("msg type:", type(msg))
self.buffer.write(msg)
self.file_handle.Write_shared(self.buffer)
def close(self):
self.file_handle.Sync()
self.file_handle.Close()
comm = MPI.COMM_WORLD
logfile = MPILogFile(
comm, "test.log",
MPI.MODE_WRONLY | MPI.MODE_CREATE | MPI.MODE_APPEND
)
logfile.write("hello")
エラー:
Traceback (most recent call last):
File "test_mpi.py", line 21, in <module>
logfile.write("hello")
File "test_mpi.py", line 13, in write
self.file_handle.Write_shared(self.buffer)
File "MPI/File.pyx", line 438, in mpi4py.MPI.File.Write_shared (src/mpi4py.MPI.c:138222)
File "MPI/msgbuffer.pxi", line 1044, in mpi4py.MPI.message_io_write (src/mpi4py.MPI.c:39788)
File "MPI/msgbuffer.pxi", line 1030, in mpi4py.MPI._p_msg_io.for_write (src/mpi4py.MPI.c:39639)
File "MPI/msgbuffer.pxi", line 143, in mpi4py.MPI.message_simple (src/mpi4py.MPI.c:30601)
TypeError: message: expecting buffer or list/tuple