Я пытаюсь создать выходной файл с mpi io. Я проверяю правильность файла с другим кодом. Хорошо работает до 4 ядер, но после 4 ядер не дает ожидаемых результатов. Я проверил смещения, смещения выглядят правильно.
В отдельности у меня есть два массива (plane_coordinates, pixel_maxiter) и matrix (M), которые я хочу записать в файл соответственно. У Plane_coordinates есть 4 двойных элемента (32 байта) , pixel_maxiter имеет 3 элемента int (12 байт), а M имеет 500 x 500 целое число (1000000 байт)
Проблема установлена Мандельбротом, в основном я взял этот github repo и адаптировал к моей проблеме .
Редактировать : Код укорочен.
plane_coordinates = np.array([-2, 2, -2, 2], dtype='d')
pixel_maxiter = np.array([500, 500, 1000], dtype='i')
M = np.ones([500,500],dtype = 'i')
## MPI IO Part
# Broadcast the array that we are going to write with io
comm.Bcast([M, MPI.INT], root=0)
amode = MPI.MODE_WRONLY|MPI.MODE_CREATE
fh = MPI.File.Open(comm, "io_output", amode)
# Writing the coordinates
buffer_1= plane_coordinates
offset_1 = rank * plane_coordinates.nbytes // size
#print("plane_coordinates",plane_coordinates.nbytes)
print("rank",rank,"offset_1",offset_1)
fh.Set_view(offset_1,etype=MPI.DOUBLE)
fh.Write_at_all(offset_1,buffer_1)
# Writing the pixels
buffer_2 = pixel_maxiter
offset_2 = plane_coordinates.nbytes + rank * pixel_maxiter.nbytes // size
print("rank",rank,"offset_2",offset_2)
fh.Set_view(offset_2,etype=MPI.INT)
fh.Write_at_all(offset_2,buffer_2)
# Writing the matrix
buffer_3 = M
filetype = MPI.INT.Create_contiguous(M.shape[0])
filetype.Commit()
displacement = plane_coordinates.nbytes + pixel_maxiter.nbytes + rank * M.nbytes // size
print("rank",rank,"offset_3",displacement)
fh.Set_view(disp = displacement, etype = MPI.INT, filetype = filetype)
fh.Write_at_all(displacement, buffer_3)
filetype.Free()
fh.Close()
Код, который я прочитал файл и проверить результаты:
plane_coordinates = np.zeros(4, dtype='d')
pixel_maxiter = np.zeros(3, dtype='i')
array = np.ones(500*500, dtype='i')
if rank == 0:
print("data",plane_coordinates,"data_type",plane_coordinates.dtype,"number_of_bytes",plane_coordinates.nbytes)
print("data",pixel_maxiter,"data_type",pixel_maxiter.dtype,"number_of_bytes",pixel_maxiter.nbytes)
print("data",array,"data_type",array.dtype,"number_of_bytes",array.nbytes)
amode = MPI.MODE_RDONLY
fh = MPI.File.Open(comm, "io_output", amode)
buffer_1 = plane_coordinates
offset_1 = rank * plane_coordinates.nbytes // size
fh.Set_view(offset_1,etype=MPI.DOUBLE)
print("rank",rank, "offset_1",offset_1)
fh.Read_at_all(offset_1,buffer_1)
if rank == 0:
print(buffer_1)
buffer_2 = pixel_maxiter
offset_2 = plane_coordinates.nbytes + rank * pixel_maxiter.nbytes // size
fh.Set_view(offset_2,MPI.INT)
print("rank",rank, "offset_2",offset_2)
fh.Read_at_all(offset_2,buffer_2)
if rank == 0:
print(buffer_2)
buffer_3 = array
filetype = MPI.INT.Create_contiguous(array.shape[0])
filetype.Commit()
displacement = plane_coordinates.nbytes + pixel_maxiter.nbytes + rank * array.nbytes // size
fh.Set_view(disp = displacement, etype = MPI.INT, filetype = filetype)
print("rank",rank, "offset_3",displacement)
fh.Read_at_all(displacement, buffer_3)
filetype.Free()
if rank == 0:
print(buffer_3)
fh.Close()
Это ошибка в mpi4py или ошибка реализации?
Заранее спасибо за помощь!