#include "mpi.h" /* combined mpi test program */ #include #include #include double f( double a ) { return (4.0 / (1.0 + a*a)); } int main(int argc, char ** argv) { int rank; int size; int source; int dest; int tag=50; #define BUFFERSIZE 128 char message[BUFFERSIZE]; MPI_Status status; MPI_Request request; int namelen; char processor_name[MPI_MAX_PROCESSOR_NAME]; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); MPI_Get_processor_name(processor_name,&namelen); printf("Process %d on %s\n",rank, processor_name); printf("\ntesting MPI_Bcast from node zero:\n"); if( rank == 0 ) sprintf(message,"Hello MPI World from processor 0"); else sprintf(message,"no message received"); MPI_Bcast(message,BUFFERSIZE, MPI_CHAR, 0, MPI_COMM_WORLD); printf("The message on node %d says \"%s\"\n", rank, message); printf("\ntesting MPI_Bcast from node 3:\n"); if( rank == 3 ) sprintf(message,"Hello MPI World from processor 3"); else sprintf(message,"no message received"); MPI_Bcast(message,BUFFERSIZE, MPI_CHAR, 3, MPI_COMM_WORLD); printf("The message on node %d says \"%s\"\n", rank, message); printf("\ntesting MPI_Send/Recv:\n"); /* MPI_Send and MPI_Recv should be separated by an MPI_Wait on each node */ sprintf(message, "Greetings from process %d using MPI_Send/Recv", rank); dest = 0; for (source=0; source