#include #include #include #include #include int main(int argc, char * argv[]) { /*Simple general MPI example*/ /*MPI initialization*/ MPI_Init(&argc,&argv); /*Initialize "global" variables*/ int root=0; /*The process that will do the receiving and output*/ int isendcount=1; /*How many integers will be gathered*/ /*Get the MPI "locals"*/ int rank; MPI_Comm_rank(MPI_COMM_WORLD,&rank); /*The process rank*/ char proc_name[MPI_MAX_PROCESSOR_NAME]; int name_len; MPI_Get_processor_name(proc_name,&name_len); /*The processor name*/ /*Do the initialization, only by the root process*/ int numtasks; int* irecvbuf; if (rank==root) { MPI_Comm_size(MPI_COMM_WORLD,&numtasks); irecvbuf=malloc(numtasks*sizeof(int)); /*Make room for gathering the process ranks*/ } /*Do "the work" (by all processes)*/ int isendbuf=rank; int name_len_max; /*Find out the maximum length of the processor name, accross all processes*/ MPI_Allreduce(&name_len,&name_len_max,isendcount,MPI_INT,MPI_MAX,MPI_COMM_WORLD); /*Waste some time, so that the program takes a noticeable time to finish*/ int length=100000; double atmp[length],btmp[length]; for (int i=0; i