做了一个关于FORTRAN中MPI_CHARACTER的有趣测试:
(环境:CVF+F90+MPICH2)
-
program main
-
!USE MPI
-
include 'mpif.h'
-
character*50 message
-
integer myid,numprocs,ierr
-
integer status(MPI_STATUS_SIZE)
-
-
message="hello process 1"
-
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
-
call MPI_SEND(message,1,MPI_CHARACTER,1,99,MPI_COMM_WORLD,ierr)
-
else if(myid==1) then
-
call MPI_RECV(message,1,MPI_CHARACTER,0,99,MPI_COMM_WORLD,ierr,status)
-
WRITE(*,*) message
-
end if
-
-
call MPI_FINALIZE(ierr)
-
-
end
结果显示:
如果增大message的长度,改为:
hello process 1!hello process 1!hello process 1!hello process 1!
-
program main
-
!USE MPI
-
include 'mpif.h'
-
character*50 message
-
integer myid,numprocs,ierr
-
integer status(MPI_STATUS_SIZE)
-
-
message="hello process 1!hello process 1!hello process 1!hello process 1!"
-
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
-
call MPI_SEND(message,1,MPI_CHARACTER,1,99,MPI_COMM_WORLD,ierr)
-
else if(myid==1) then
-
call MPI_RECV(message,1,MPI_CHARACTER,0,99,MPI_COMM_WORLD,ierr,status)
-
WRITE(*,*) message
-
end if
-
-
call MPI_FINALIZE(ierr)
-
-
end
运行结果则为:
由上对比可知:
1、MPI确实是以数据的个数来计数的,而不是以数据字节大小来
计数的
call MPI_SEND(message,
1,MPI_CHARACTER,1,99,MPI_COMM_WORLD,ierr)
call MPI_RECV(message,
1,MPI_CHARACTER,0,99,MPI_COMM_WORLD,ierr,status)
2、MPI_CHARACTER最大支持50个字节的字符串
有兴趣可以做做其他类型数据的测试。
阅读(879) | 评论(0) | 转发(0) |