Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP-MPI User's Guide > Appendix A Example applications

send_receive.f

» 

Technical documentation

Complete book in PDF
» Feedback
Content starts here

 » Table of Contents

 » Glossary

 » Index

In this Fortran 77 example, process 0 sends an array to other processes in the default communicator MPI_COMM_WORLD.

program maininclude 'mpif.h'

integer rank, size, to, from, tag, count, i, ierr
integer src, dest
integer st_source, st_tag, st_count
integer status(MPI_STATUS_SIZE)
double precision data(100)

call MPI_Init(ierr)
call MPI_Comm_rank(MPI_COMM_WORLD, rank, ierr)
call MPI_Comm_size(MPI_COMM_WORLD, size, ierr)

if (size .eq. 1) then
print *, 'must have at least 2 processes'
call MPI_Finalize(ierr)
stop
endif

print *, 'Process ', rank, ' of ', size, ' is alive'
dest = size - 1
src = 0

if (rank .eq. src) then
to = dest
count = 10
tag = 2001

do i=1, 10
data(i) = 1
enddo

call MPI_Send(data, count, MPI_DOUBLE_PRECISION,
+ to, tag, MPI_COMM_WORLD, ierr)
endif

if (rank .eq. dest) then
tag = MPI_ANY_TAG
count = 10
from = MPI_ANY_SOURCE
call MPI_Recv(data, count, MPI_DOUBLE_PRECISION,
+ from, tag, MPI_COMM_WORLD, status, ierr)



call MPI_Get_Count(status, MPI_DOUBLE_PRECISION,
+ st_count, ierr)
st_source = status(MPI_SOURCE)
st_tag = status(MPI_TAG)

print *, 'Status info: source = ', st_source,
+ ' tag = ', st_tag, ' count = ', st_count
print *, rank, ' received', (data(i),i=1,10)

endif

call MPI_Finalize(ierr)
stop
end

send_receive output

The output from running the send_receive executable is shown below. The application was run with -np = 10.

Process  0 of  10 is alive
Process 1 of 10 is alive
Process 2 of 10 is alive
Process 3 of 10 is alive
Process 4 of 10 is alive
Process 5 of 10 is alive
Process 6 of 10 is alive
Process 7 of 10 is alive
Process 8 of 10 is alive
Process 9 of 10 is alive
Status info: source = 0 tag = 2001 count = 10
9 received 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© 1979-2007 Hewlett-Packard Development Company, L.P.