{{{ /* Program: * 每個 node 將自己的 id 送給下一個 node。 * History: * 2008-06-05 BETA */ #include #include int main(int argc,char *argv[]) { int n=0, myid, numprocs, i=0; MPI_Status status; MPI_Init(&argc,&argv); MPI_Comm_size(MPI_COMM_WORLD,&numprocs); MPI_Comm_rank(MPI_COMM_WORLD,&myid); if(myid==0) { MPI_Send(&n, 1, MPI_INT, 1, 99, MPI_COMM_WORLD); } if(myid!=0) { MPI_Recv(&n, 1, MPI_INT, myid-1, 99, MPI_COMM_WORLD, &status); n++; if(myid #include int main(int argc,char *argv[]) { int n, myid, numprocs, i=0; MPI_Status status; MPI_Init(&argc,&argv); MPI_Comm_size(MPI_COMM_WORLD,&numprocs); MPI_Comm_rank(MPI_COMM_WORLD,&myid); /* node 0 will send the first message */ if(myid==0) { n = 0; /* MPI_Send(&n, 1, MPI_INT, 1, 99, MPI_COMM_WORLD); */ printf("[Ndde %d] send number %d to Node %d\n\n", myid, n, myid+1); } /* node 1 to node n-2 will send message to the next node */ if(myid