[Fortran] 纯文本查看 复制代码
program test2
use mpi
integer rank, n_ranks, ierr
integer status(MPI_STATUS_SIZE)
character(len=13) message,message1
print*,'before MPI init'
! First call MPI_Init
call MPI_Init(ierr)
! Check that there are two ranks
call MPI_Comm_size(MPI_COMM_WORLD, n_ranks, ierr)
if (n_ranks .ne. 2) then
write(6,*) "This example exactly requires two ranks"
error stop
end if
! Get my rank
call MPI_Comm_rank(MPI_COMM_WORLD, rank, ierr)
if (rank == 0) then
message = "Hello, world!"
call MPI_Send( message, 13, MPI_CHARACTER, 1, 0, MPI_COMM_WORLD, ierr)
end if
if (rank == 1) then
call MPI_Recv( message1, 13, MPI_CHARACTER, 0, 0, MPI_COMM_WORLD, status, ierr)
write(6,*) message1
end if
! Call MPI_Finalize at the end
call MPI_Finalize(ierr)
end program