+++ /dev/null
-
- /* Simplest code to illustrate */
- /* Message Passing */
-
- /* process 0 sends a message to */
- /* all other processes */
-
- /* Michel Vallieres */
-#include <stdio.h>
-#include <mpi.h>
-
-int main (int argc, char *argv[])
-{
-int my_rank, size;
-int process;
-double number, send_mesg, recv_mesg;
- char buf[100];
-
-MPI_Status recv_status;
-
- MPI_Init(&argc, &argv);
-
- MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
- MPI_Comm_size(MPI_COMM_WORLD, &size);
-
- if ( my_rank == 0 )
- {
- number = 5.167321; /* arbitrary number */
- /* send number to other nodes */
- for ( process=1; process<size; process++)
- {
- MPI_Ssend(&number, 1, MPI_DOUBLE, process, 121, MPI_COMM_WORLD);
- }
- }
- else
- {
- /* receives message from master */
- MPI_Recv(&recv_mesg, 1, MPI_DOUBLE, 0, 121,
- MPI_COMM_WORLD, &recv_status);
-
- /* which host is this ? Message?*/
- strcpy(buf, "Hi from the exciting world of ");
- gethostname(buf + strlen(buf), 64);
- printf("%s --- I am %d out of %d -- message: %lf \n", buf, rank, size, recv_mesg);
-
- }
-
- MPI_Finalize();
-}