Changes between Version 2 and Version 3 of mpich/point_to_point/demo3
- Timestamp:
- Jun 17, 2008, 10:57:18 AM (16 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
mpich/point_to_point/demo3
v2 v3 5 5 * History: 6 6 * 2008-06-12 BETA 7 * 2008-06-17 更改顯示方式,並增加註解 7 8 */ 8 9 … … 19 20 MPI_Comm_size(MPI_COMM_WORLD, &numprocs); 20 21 MPI_Comm_rank(MPI_COMM_WORLD, &myrank); 22 23 /* Node 0 will do the following */ 21 24 if(myrank == 0) 22 25 { 23 printf("I am %d \n", myrank);24 for(i = 1; i < (numprocs); i++)26 /* receive messages from other nodes */ 27 for(i = 1; i < numprocs; i++) 25 28 { 26 29 MPI_Recv(message, 20, MPI_CHAR, i, 99, MPI_COMM_WORLD, &status); 27 printf(" I GOT %s \n", message);30 printf("[Node 0] << 「%s」[Node %d] \n", message, status.MPI_SOURCE); 28 31 } 29 printf("\n");30 32 } 33 34 /* other Nodes will do the following */ 31 35 if(myrank != 0) 32 36 { 33 sprintf(message, "i am %d", myrank); 37 /* send node's rank to Node 0 */ 38 sprintf(message, "[%d]", myrank); 34 39 MPI_Send(message, 20, MPI_CHAR, 0, 99, MPI_COMM_WORLD); 35 printf("I am %d \n", myrank); 36 printf("I send %s\n\n ", message); 40 printf("[Node %d]「%s」 >> [Node 0]\n", myrank, message); 37 41 } 38 42 MPI_Finalize();