Basic HTML version of Foils prepared
19 September 98
Foil 43 Hello World:C Example of Broadcast
From
MPI Message Passing Interface Computational Science for Simulations --
Fall Semester 1998
.
by
Geoffrey C. Fox, Nancy McCracken
#include "mpi.h"
main( int argc, char **argv )
{ 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 processor
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(); }
Note that all processes issue the broadcast operation, process 0 sends the message and all processes receive the message.
©
Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu
If you have any comments about this server, send e-mail to
webmaster@npac.syr.edu
.
Page produced by
wwwfoil
on Sun Apr 11 1999