Basic HTML version of Foils prepared 10 Oct 1995

Foil 28 Hello World:C Example of Broadcast

From Fox Presentation Fall 1995 CPS615 Basic Simulation Track for Computational Science -- Fall Semester 95. by Geoffrey C. Fox


1 #include "mpi.h"
2 main( int argc, char **argv )
3 {
  • char message[20];
  • int rank;
  • MPI_Init (&argc, &argv);
  • MPI_Comm_rank(MPI_COMM_WORLD, &rank); # Who is this processor
  • if( rank == 0 ) # We are on "root" -- Processor 0
    • strcpy(message,"Hello MPI World"); # Generate message
  • # MPI_Bcast sends from root=0 and receives on all other processors
  • MPI_Bcast(message,20, MPI_CHAR, 0, MPI_COMM_WORLD);
  • printf("This is a message from node %d saying %s\n", rank,
    • message);
  • MPI_Finalize();
4 }

in Table To:


© on Tue Oct 7 1997