Changes between Version 4 and Version 5 of mpich/point_to_point/demo2
- Timestamp:
- Jun 12, 2008, 4:39:50 PM (16 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
mpich/point_to_point/demo2
v4 v5 1 1 {{{ 2 2 /* Program: 3 * 每個 node 將自己的 id 送給下一個 node。3 * 每個 node 將自己的 id 資訊送給下一個 node。 4 4 * History: 5 5 * 2008-06-05 BETA 6 * 2008-06-06 改變 #30 printf 位置,以了解 MPI 函式執行順序關係 7 * 2008-06-12 更改顯示方法。 6 8 */ 7 9 … … 11 13 int main(int argc,char *argv[]) 12 14 { 13 int n =0, myid, numprocs, i=0;15 int n, myid, numprocs; 14 16 MPI_Status status; 15 17 MPI_Init(&argc,&argv); 16 18 MPI_Comm_size(MPI_COMM_WORLD,&numprocs); 17 19 MPI_Comm_rank(MPI_COMM_WORLD,&myid); 20 21 /* node 0 will send the first message */ 18 22 if(myid==0) 19 23 { 24 n = myid; 20 25 MPI_Send(&n, 1, MPI_INT, 1, 99, MPI_COMM_WORLD); 26 printf("[Ndde %d]「%d」 >> [Node %d]\n\n", myid, n, myid+1); 21 27 } 22 if(myid!=0) 28 29 /* node 1 to node n-2 will send message to the next node */ 30 if(myid>0 && myid<numprocs-1) 23 31 { 24 32 MPI_Recv(&n, 1, MPI_INT, myid-1, 99, MPI_COMM_WORLD, &status); 25 n++; 26 27 if(myid<numprocs-1) 28 29 { 30 31 MPI_Send(&n, 1, MPI_INT, myid+1, 99, MPI_COMM_WORLD); 32 33 printf("I am node %d\nI recive number %d from %d\n", myid, n, myid-1); 34 printf("I send number %d to %d\n\n", n, myid+1); 35 36 } 37 33 printf("[Node %d] << 「%d」[Node %d]\n", myid, n, status.MPI_SOURCE); 34 n = myid; 35 MPI_Send(&n, 1, MPI_INT, myid+1, 99, MPI_COMM_WORLD); 36 printf("[Ndde %d]「%d」 >> [Node %d]\n\n", myid, n, myid+1); 38 37 } 39 38 39 /* the final node n-1 will not send any message but receive*/ 40 if(myid==numprocs-1) 41 { 42 MPI_Recv(&n, 1, MPI_INT, myid-1, 99, MPI_COMM_WORLD, &status); 43 printf("[Node %d] << 「%d」[Node %d]\n", myid, n, status.MPI_SOURCE); 44 } 40 45 MPI_Finalize(); 41 42 46 return 0; 43 44 }45 47 }}}