
c*****************************************************************
c
c                        Example 1 ( hello_world.f ) 
c
c  Objective           : MPI Program to print "Hello World"
c                        This example demonstrates the use of
c                        MPI_Init
c                        MPI_Comm_rank
c                        MPI_Comm_size
c                        MPI_Send
c                        MPI_Recv
c                        MPI_Finalize
c
c  Input               : Message="Hello World"
c
c  Output              : Message and Rank of the process. 
c
c  Necessary Condition : Number of Processes should be 
c                        less than or equal to 8.
c
c********************************************************************



	 program main

	 include "mpif.h"

	 integer  MyRank, Numprocs
   	 integer  Destination, Source, iproc
	 integer  Destination_tag, Source_tag 
	 integer  Root, MessageSize
	 integer  status(MPI_STATUS_SIZE)
	 character*12   Message 

	 data Message/'Hello World'/

C.........MPI initialization.... 

    	 call MPI_INIT(ierror)
    	 call MPI_COMM_SIZE(MPI_COMM_WORLD, Numprocs, ierror)
    	 call MPI_COMM_RANK(MPI_COMM_WORLD, MyRank, ierror)

	 Root = 0
	 MessageSize = 12

	 if(MyRank .ne. Root) then
	    Destination = Root
	    Destination_tag = 0
	    call MPI_SEND(Message, MessageSize, MPI_CHARACTER, Destination, 
     $  	Destination_tag,  MPI_COMM_WORLD, ierror)
	  else 
	   do iproc = 1, Numprocs-1
	     Source = iproc
	     Source_tag = 0
	     call MPI_RECV(Message, MessageSize, MPI_CHARACTER, Source, 
     $	     Source_tag, MPI_COMM_WORLD, status, ierror)
	        print *, Message,' from Process with Rank ', iproc
	   enddo

	 endif

         call MPI_FINALIZE( ierror )

         stop
         end



