#include #include #include int main (int argc, char *argv[]) { int id, np, j; char processor_name[MPI_MAX_PROCESSOR_NAME], message[100]; int processor_name_len; MPI_Status status; MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &np); MPI_Comm_rank(MPI_COMM_WORLD, &id); MPI_Get_processor_name(processor_name, &processor_name_len); /* want to do: print message to a string, then send this message from all proceesses to process 0, and have process 0 print them. */ sprintf(message, "Hello world from process %03d out of %03d, processor name %s", id, np, processor_name); if (id == 0) { printf("%s\n", message); for (j = 1; j < np; j++) { MPI_Recv(message,100,MPI_CHAR,j,0,MPI_COMM_WORLD, &status); printf("%s\n", message); } } else { MPI_Send(message,1+strlen(message),MPI_CHAR,0,0,MPI_COMM_WORLD); } MPI_Finalize(); return 0; }