Mars
2008-12-26 04:34:30 UTC
Hello all,
Merry Christmas!
I encountered some problems with MPI_FILE_READ_AT. I generated some
data files and wrote a code using MPI_FILE_READ_AT to read them but
never got correct answer. My MPI code is as follows:
======================================================================
program test_mpi_read
implicit none
include 'mpif.h'
integer :: fh, ierr, myid, numprocs
integer :: status(MPI_STATUS_SIZE)
integer :: irc
integer(kind=mpi_offset_kind) :: offset
integer :: i, j, k
integer :: num
character(len=64) :: filename
real(8):: q
call MPI_INIT( ierr )
call MPI_COMM_RANK( MPI_COMM_WORLD, myid, ierr )
call MPI_COMM_SIZE( MPI_COMM_WORLD, numprocs, ierr )
write(filename,'(a)') 'test_unformatted_direct'
call MPI_FILE_OPEN(MPI_COMM_WORLD, filename, MPI_MODE_RDONLY,
MPI_INFO_NULL, fh, ierr)
offset = 1
call MPI_FILE_READ_AT(fh, offset, q, 1, MPI_REAL8, status, ierr)
if ( myid == 0 ) then
print*, 'myid =', myid, 'q=', q
end if
call MPI_FILE_CLOSE(fh, ierr)
call MPI_FINALIZE(irc)
stop
end program test_mpi_read
============================================================================
The data files used for testing are generated by the following code:
============================================================================
program write_data
implicit none
integer :: i, j, k
character(len=64) :: filename
integer, parameter :: num = 100
real(8) :: q
write(filename,'(a)') 'test_unformatted_direct'
open (10, file=filename, form='unformatted', access='direct',
recl=4, action='write')
write(filename,'(a)') 'test_unformatted'
open (20, file=filename, form='unformatted', action='write')
write(filename,'(a)') 'test_binary'
open (30, file=filename, form='binary', action='write')
write(filename,'(a)') 'test_formatted'
open (40, file=filename, form='formatted', action='write')
do i = 1, num
q = exp(dble(i))
write(10, rec=i) q
write(20) q
write(30) q
write(40, '(e24.16)') q
end do
close(10)
close(20)
close(30)
close(40)
end program write_data
==============================================================================
'test_formatted' here is only for checking. I tried
'test_unformatted_direct', 'test_formatted' and 'test_binary' but
never got right answer. The output I got from these three files are:
1. myid = 0 q= 1.782556321367550E-307
2. myid = 0 q= 7.044881699546222E-258
3. myid = 0 q= -6.443473835168681E-086
The correct answer should be 0.7389056098930650E+01. I cannot figure
out where the problem is. Could you give me some advice? Another
questions is: if I need to use MPI_FILE_READ_AT, is there any
requirement on the format of the input data file?
I appreciate your help and look forward to your reply. Thanks!
Kan
Merry Christmas!
I encountered some problems with MPI_FILE_READ_AT. I generated some
data files and wrote a code using MPI_FILE_READ_AT to read them but
never got correct answer. My MPI code is as follows:
======================================================================
program test_mpi_read
implicit none
include 'mpif.h'
integer :: fh, ierr, myid, numprocs
integer :: status(MPI_STATUS_SIZE)
integer :: irc
integer(kind=mpi_offset_kind) :: offset
integer :: i, j, k
integer :: num
character(len=64) :: filename
real(8):: q
call MPI_INIT( ierr )
call MPI_COMM_RANK( MPI_COMM_WORLD, myid, ierr )
call MPI_COMM_SIZE( MPI_COMM_WORLD, numprocs, ierr )
write(filename,'(a)') 'test_unformatted_direct'
call MPI_FILE_OPEN(MPI_COMM_WORLD, filename, MPI_MODE_RDONLY,
MPI_INFO_NULL, fh, ierr)
offset = 1
call MPI_FILE_READ_AT(fh, offset, q, 1, MPI_REAL8, status, ierr)
if ( myid == 0 ) then
print*, 'myid =', myid, 'q=', q
end if
call MPI_FILE_CLOSE(fh, ierr)
call MPI_FINALIZE(irc)
stop
end program test_mpi_read
============================================================================
The data files used for testing are generated by the following code:
============================================================================
program write_data
implicit none
integer :: i, j, k
character(len=64) :: filename
integer, parameter :: num = 100
real(8) :: q
write(filename,'(a)') 'test_unformatted_direct'
open (10, file=filename, form='unformatted', access='direct',
recl=4, action='write')
write(filename,'(a)') 'test_unformatted'
open (20, file=filename, form='unformatted', action='write')
write(filename,'(a)') 'test_binary'
open (30, file=filename, form='binary', action='write')
write(filename,'(a)') 'test_formatted'
open (40, file=filename, form='formatted', action='write')
do i = 1, num
q = exp(dble(i))
write(10, rec=i) q
write(20) q
write(30) q
write(40, '(e24.16)') q
end do
close(10)
close(20)
close(30)
close(40)
end program write_data
==============================================================================
'test_formatted' here is only for checking. I tried
'test_unformatted_direct', 'test_formatted' and 'test_binary' but
never got right answer. The output I got from these three files are:
1. myid = 0 q= 1.782556321367550E-307
2. myid = 0 q= 7.044881699546222E-258
3. myid = 0 q= -6.443473835168681E-086
The correct answer should be 0.7389056098930650E+01. I cannot figure
out where the problem is. Could you give me some advice? Another
questions is: if I need to use MPI_FILE_READ_AT, is there any
requirement on the format of the input data file?
I appreciate your help and look forward to your reply. Thanks!
Kan