#include #include #include /* This program illustrates the simplest of MPI programs. The program * leverages the 'six essential' MPI calls, and one additional call * that determines the name of the host where the program is running. * To compile this program, issue: * mpicc -o hello_world_mpi hello_world_mpi.c * In order to run the program on the bccd: * i. Make sure that each of the hosts have run "bccd-allowall" * ii. Check that all of the hosts are available with * bccd-checkem * iii. Make the binary available on all hosts in the collective with * bccd-syncdir * iv. Change directories to where your files were sync'd to. * v. Run the program with: * mpirun -np -machinefile ./hello_world_mpi */ /* Typically process 0 in the ranking is the server process */ #define SERVER_NODE 0 int main(int argc, char ** argv) { int my_rank, world_size, destination, tag, source, length; char message[256], name[80]; MPI_Status status; MPI_Init(&argc, &argv); /* note that argc and argv are passed by address */ MPI_Comm_rank(MPI_COMM_WORLD,&my_rank); MPI_Comm_size(MPI_COMM_WORLD,&world_size); if ( my_rank!=SERVER_NODE) { printf("I am the client, with rank %d of %d\n", my_rank, world_size); MPI_Get_processor_name(name,&length); sprintf(message,"Greetings from process %d, %s!",my_rank,name); destination = 0; tag = 2; MPI_Send(message,strlen(message)+1,MPI_CHAR,destination,tag,MPI_COMM_WORLD); } else { /* I am the server */ printf("I am the server, with rank %d of %d\n", my_rank, world_size); tag = 2; for (source = 1; source < world_size ; source ++) { MPI_Recv(message,256,MPI_CHAR,source,tag,MPI_COMM_WORLD, &status); fprintf(stderr, "%s\n", message); } } printf("Calling Finalize %d\n",my_rank); MPI_Finalize(); }