# include # include # include "mpi_stubs_c.h" int main ( int argc, char *argv[] ); void timestamp ( void ); /******************************************************************************/ int main ( int argc, char *argv[] ) /******************************************************************************/ /* Purpose: MAIN is the main program for HELLO. Discussion: HELLO is a simple MPI test program. Each process prints out a "Hello, world!" message. The master process also prints out a short message. Licensing: This code is distributed under the GNU LGPL license. Modified: 04 October 2005 Author: John Burkardt Reference: William Gropp, Ewing Lusk, Anthony Skjellum, Using MPI: Portable Parallel Programming with the Message-Passing Interface, Second Edition, MIT Press, 1999, ISBN: 0262571323. */ { int ierr; int master = 0; int num_procs; int world_id; /* Initialize MPI. */ ierr = MPI_Init ( &argc, &argv ); /* Get the number of processes. */ ierr = MPI_Comm_size ( MPI_COMM_WORLD, &num_procs ); /* Get the individual process ID. */ ierr = MPI_Comm_rank ( MPI_COMM_WORLD, &world_id ); /* Process 0 prints an introductory message. */ if ( world_id == master ) { printf ( "\n" ); printf ( "HELLO_WORLD - Master process:\n" ); printf ( " C version\n" ); printf ( "\n" ); printf ( " An MPI example program.\n" ); printf ( "\n" ); printf ( " The number of processes is %d.\n", num_procs ); printf ( "\n" ); } /* Every process prints a hello. */ printf ( " Process %d says 'Hello, world!'\n", world_id ); /* Process 0 says goodbye. */ if ( world_id == master ) { printf ( "\n" ); printf ( "HELLO_WORLD - Master process:\n" ); printf ( " Normal end of execution: 'Goodbye, world!'\n" ); } /* Shut down MPI. */ ierr = MPI_Finalize ( ); return 0; } /******************************************************************************/ void timestamp ( void ) /******************************************************************************/ /* Purpose: TIMESTAMP prints the current YMDHMS date as a time stamp. Example: 31 May 2001 09:45:54 AM Licensing: This code is distributed under the GNU LGPL license. Modified: 24 September 2003 Author: John Burkardt Parameters: None */ { # define TIME_SIZE 40 static char time_buffer[TIME_SIZE]; const struct tm *tm; size_t len; time_t now; now = time ( NULL ); tm = localtime ( &now ); len = strftime ( time_buffer, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm ); printf ( "%s\n", time_buffer ); return; # undef TIME_SIZE }