Basic HTML version of Foils prepared 19 September 98

Foil 30 Hello World in C plus MPI

From MPI Message Passing Interface Computational Science for Simulations -- Fall Semester 1998. by Geoffrey C. Fox, Nancy McCracken


1 # all processes execute this program
2 #include <stdio.h>
3 #include <mpi.h>
4 void main(int argc,char *argv[])
5 { int ierror, rank, size
  • MPI_Init(&argc, &argv); # Initialize
  • # In following Find Process Number
  • MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  • if( rank == 0)
    • printf ("hello World!\n");
  • # In following, Find Total number of processes
  • ierror = MPI_Comm_size(MPI_COMM_WORLD, &size);
  • if( ierror != MPI_SUCCESS )
    • MPI_Abort(MPI_COMM_WORLD,ierror); # Abort
  • printf("I am processor %d out of total of %d\n", rank, size);
  • MPI_Finalize(); # Finalize }

in Table To:


© 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