[Fortran] 纯文本查看 复制代码
program main
use mpi
implicit none
integer::ierr,myid,nprocs
integer::msize=6, bsize
real(8)::buffer(6),b(6)
real(8),allocatable::tmbuff(:)
integer, parameter :: MAX_BUFFER_SIZE = 1024
integer::status(MPI_status_size)
call MPI_init(ierr)
call MPI_comm_size(MPI_comm_world,nprocs,ierr)
call MPI_comm_rank(MPI_comm_world,myid,ierr)
if(myid==0)then
buffer(1:6)=(/1.0,2.0,3.0,4.0,5.0,6.0/)
!call MPI_pack_size(msize,MPI_double_precision,MPI_comm_world,bsize,ierr)
print *,'MPI_bsend_overhead = ', MPI_bsend_overhead
allocate(tmbuff(size(buffer)+2*MPI_bsend_overhead))
call MPI_Buffer_attach(tmbuff, size(tmbuff), ierr)
call MPI_bsend(buffer,msize-1,MPI_double_precision,1,2000,MPI_comm_world,status,ierr)
call MPI_bsend(buffer,1, MPI_double_precision,1,2001,MPI_comm_world,status,ierr)
call MPI_buffer_detach(tmbuff, size(tmbuff), ierr)
else if (myid==1) then
call MPI_recv(b,msize-1,MPI_double_precision,0,2000,MPI_comm_world,status,ierr)
print *,'b1 = ',b
call MPI_recv(buffer,1, MPI_double_precision,0,2001,MPI_comm_world,status,ierr)
print *,'b2 = ',buffer
end if
call MPI_finalize(ierr)
end program