上一篇讲到MPI_SEND是以数据个数来计数的,实际测试也得到了这样的结论。
但是今天做的一个测试却又显示了不同的结果。请看:
环境:CVF+F90+MPICH2
程序1:
-
program main
-
include 'mpif.h'
-
character*50 message(2)
-
integer myid,numprocs,ierr
-
integer status(MPI_STATUS_SIZE)
-
character*8 FILENAME(10)
-
-
call MPI_INIT(ierr)
-
call MPI_COMM_RANK(MPI_COMM_WORLD,myid,ierr)
-
call MPI_COMM_SIZE(MPI_COMM_WORLD,numprocs,ierr)
-
-
if (myid==0) then
-
OPEN(1,FILE='files.txt')
-
DO I=1,10
-
READ(1,*) FILENAME(I)
-
call MPI_SEND(FILENAME(I),1,MPI_CHARACTER,1,99,MPI_COMM_WORLD,ierr)
-
END DO
-
-
else if(myid==1) then
-
DO I=1,10
-
call MPI_RECV(FILENAME(I),1,MPI_CHARACTER,0,99,MPI_COMM_WORLD,ierr,status)
-
END DO
-
WRITE(*,'(A20)') FILENAME(:)
-
end if
-
-
call MPI_FINALIZE(ierr)
-
-
end
其中,files.txt内容为:
按理说,结果应该是files.txt的内容。但是运行结果却是:
也就是只显示了FILENAME(I)的头字符!很奇怪!
于是将代码稍作修改,程序2:
-
program main
-
include 'mpif.h'
-
character*50 message(2)
-
integer myid,numprocs,ierr
-
integer status(MPI_STATUS_SIZE)
-
character*8 FILENAME(10)
-
-
call MPI_INIT(ierr)
-
call MPI_COMM_RANK(MPI_COMM_WORLD,myid,ierr)
-
call MPI_COMM_SIZE(MPI_COMM_WORLD,numprocs,ierr)
-
-
if (myid==0) then
-
OPEN(1,FILE='files.txt')
-
DO I=1,10
-
READ(1,*) FILENAME(I)
-
call MPI_SEND(FILENAME(I),8,MPI_CHARACTER,1,99,MPI_COMM_WORLD,ierr)
-
END DO
-
-
else if(myid==1) then
-
DO I=1,10
-
call MPI_RECV(FILENAME(I),8,MPI_CHARACTER,0,99,MPI_COMM_WORLD,ierr,status)
-
END DO
-
WRITE(*,'(A20)') FILENAME(:)
-
end if
-
-
call MPI_FINALIZE(ierr)
-
-
end
结果却能显示正常:
由上对比可知,MPI_SEND传递数据似乎有时是以数据个数来计数,有时却又是以字节来计数。WHY??
阅读(1054) | 评论(0) | 转发(0) |