Fortran 使用MPI I/O读取二进制文件时的结果不正确
我是MPI新手,正在努力读取二进制文件。 具体来说,我在二进制文件中存储了一个$198\乘以50\乘以50$的整数数组(具体来说是16位整数)。我想使用2个计算节点来处理这个文件。因此有两个MPI进程,每个进程将处理一半的输入。我正在使用函数MPI_FILE_READ_AT读取各个区域。我希望数组值填充传入函数调用的变量/参数“bucket”。但“bucket”条目的健全性检查打印结果告诉我bucket中的值都不正确。我觉得我的论点有问题Fortran 使用MPI I/O读取二进制文件时的结果不正确,fortran,mpi,binaryfiles,mpi-io,Fortran,Mpi,Binaryfiles,Mpi Io,我是MPI新手,正在努力读取二进制文件。 具体来说,我在二进制文件中存储了一个$198\乘以50\乘以50$的整数数组(具体来说是16位整数)。我想使用2个计算节点来处理这个文件。因此有两个MPI进程,每个进程将处理一半的输入。我正在使用函数MPI_FILE_READ_AT读取各个区域。我希望数组值填充传入函数调用的变量/参数“bucket”。但“bucket”条目的健全性检查打印结果告诉我bucket中的值都不正确。我觉得我的论点有问题 program main use mpi implici
program main
use mpi
implicit none
integer :: i, error, num_processes, id, fh
integer(MPI_OFFSET_KIND) :: filesize, offset
integer(MPI_OFFSET_KIND) :: num_bytes_per_process
integer(MPI_OFFSET_KIND) :: num_bytes_this_process
integer :: num_ints_per_process, num_ints_this_process
integer(kind = 2), dimension(:), allocatable :: bucket
character(len=100) :: inputFileName
integer, parameter :: INTKIND=2
! Initialize
inputFileName = 'xyz_50x50'
print *, 'MPI_OFFSET_KIND =', MPI_OFFSET_KIND
! MPI basics
call MPI_Init ( error )
call MPI_Comm_size ( MPI_COMM_WORLD, num_processes, error )
call MPI_Comm_rank ( MPI_COMM_WORLD, id, error )
! Open the file
call MPI_FILE_OPEN(MPI_COMM_WORLD, inputFileName, MPI_MODE_RDONLY, &
MPI_INFO_NULL, fh, error)
! get the size of the file
call MPI_File_get_size(fh, filesize, error)
! Note: filesize is the TOTAL number of bytes in the file
num_bytes_per_process = filesize/num_processes
num_ints_per_process = num_bytes_per_process/INTKIND
offset = id * num_bytes_per_process
num_bytes_this_process = min(num_bytes_per_process, filesize - offset)
num_ints_this_process = num_bytes_this_process/INTKIND
allocate(bucket(num_ints_this_process))
call MPI_FILE_READ_AT(fh, offset, bucket, num_ints_this_process, &
MPI_SHORT, MPI_STATUS_SIZE, error)
do i = 1, num_ints_this_process
if (bucket(i) /= 0) then
print *, "my id is ", id, " and bucket(",i,")=", bucket(i)
endif
enddo
! close the file
call MPI_File_close(fh, error)
! close mpi
call MPI_Finalize(error)
end program main
您必须使用
MPI\u STATUS\u IGNORE
而不是MPI\u STATUS\u SIZE
(fwiw,我无法编译这个程序,除非我修复它)
请注意,由于所有MPI任务都在相同的时间读取文件,因此您宁愿使用集合
MPI\u file\u read\u at\u all()
子例程来提高性能。您必须使用MPI\u STATUS\u IGNORE
而不是MPI\u STATUS\u SIZE
(fwiw,我无法编译这个程序,除非我修复它)
请注意,由于所有MPI任务都在相同的时间读取文件,因此为了提高性能,您更愿意使用集合
MPI\u file\u read\u at\u all()
子例程。公平地说,大多数MPI实现都会编译此子例程。但有些人确实明白了这一点。公平地说,我认为这更像是一种与编译器相关的行为gfortran 7.1.0
无法编译,但是gfortran 4.8.5
是一只快乐的熊猫(都是用最新的Open MPI master测试的),谢谢。将MPI_状态更改为MPI_状态_忽略修复了我的输出。公平地说,大多数MPI实现都会编译这个。但有些人确实明白了这一点。公平地说,我认为这更像是一种与编译器相关的行为gfortran 7.1.0
无法编译,但是gfortran 4.8.5
是一只快乐的熊猫(都是用最新的Open MPI master测试的),谢谢。将MPI_状态更改为MPI_状态_忽略修复了我的输出。请用于所有Fortran问题。具体版本在这里不是很重要。MPI库版本和编译器版本更为重要。我使用gcc 5.2附带的mvapich2/2.2,请用于所有Fortran问题。具体版本在这里不是很重要。MPI库版本和编译器版本更为重要
call MPI_FILE_READ_AT(fh, offset, bucket, num_ints_this_process, &
MPI_SHORT, MPI_STATUS_IGNORE, error)