#include "mpi.h" #include #include int main( int argc, char *argv[] ) { int my_rank; /* rank of process */ int p; /* number of processes */ int source; /* rank of sender */ int dest; /* rank of receiver */ int tag = 0; /* tag for messages */ char message[200]; /* storage for message */ MPI_Status status; /* return status for */ /* receive */ char procname[MPI_MAX_PROCESSOR_NAME]; int resultlen; MPI_Comm slavecomm; MPI_Init( &argc, &argv ); MPI_Comm_get_parent( &slavecomm ); /* Find out process rank */ MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); /* Find out number of processes */ MPI_Comm_size(MPI_COMM_WORLD, &p); MPI_Get_processor_name(procname,&resultlen); /* Create message */ sprintf(message, "Greetings from slave process %d 0f %d, running on %s!", my_rank,p,procname); dest = 0; /* Use strlen+1 so that '\0' gets transmitted */ MPI_Send(message, strlen(message)+1, MPI_CHAR, dest, tag, slavecomm); MPI_Comm_free( &slavecomm ); MPI_Finalize(); return 0; }