program main
include 'mpif.h'
integer myid, size, src, newInt, ierr, status(MPI_STATUS_SIZE)
logical correct
call MPI_Init(ierr)
if (ierr .ne. MPI_SUCCESS) then
print *,'MPI Initialization failed'
stop 1
endif
call MPI_Comm_rank(MPI_COMM_WORLD, myid, ierr)
call MPI_Comm_size(MPI_COMM_WORLD, size, ierr)
call MPI_Send(myid, 1, MPI_INTEGER, 0, 99, MPI_COMM_WORLD, ierr)
if (myid .eq. 0) then
correct = .true.
do src=0,size-1
call MPI_Recv(newInt, 1, MPI_INTEGER, src, 99,
MPI_COMM_WORLD, status, ierr)
print *,'Hello data <', newInt,'> received from node ',src
if (newInt .ne. src) correct = .false.
enddo
if (correct) then
print *,'Data from all ',size,' nodes received correctly!'
else
print *,'Data NOT RECEIVED CORRECTLY from all ',size,' nodes!'
endif
endif
call MPI_Finalize(ierr)
end
Go to the first, previous, next, last section, table of contents.