Changes between Version 6 and Version 7 of mpich/point_to_point/demo2


Ignore:
Timestamp:
Jun 25, 2008, 5:15:48 PM (16 years ago)
Author:
wade
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • mpich/point_to_point/demo2

    v6 v7  
    77 *   2008-06-06 改變 #30 printf 位置,以了解 MPI 函式執行順序關係
    88 *   2008-06-12 更改顯示方法。
     9 *   2008-06-17 變更變數名 myid -> myrank,增加註解
    910 */
    1011
     
    1213#include <stdio.h>
    1314
    14 int main(int argc,char *argv[])
     15main(int argc,char **argv)     
    1516{
    16   int n, myid, numprocs;
     17  int n, myrank, numprocs;
    1718  MPI_Status status;
    1819  MPI_Init(&argc,&argv);
    1920  MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
    20   MPI_Comm_rank(MPI_COMM_WORLD,&myid);
     21  MPI_Comm_rank(MPI_COMM_WORLD,&myrank);
    2122
    2223  /* node 0 will send the first message */
    23   if(myid==0)
     24  if(myrank == 0)
    2425  {
    25     n = myid;
     26    n = myrank;
    2627    MPI_Send(&n, 1, MPI_INT, 1, 99, MPI_COMM_WORLD);
    27     printf("[Ndde %d]「%d」 >> [Node %d]\n\n", myid, n, myid+1);
     28    printf("[Ndde %d]「%d」 >> [Node %d]\n\n", myrank, n, myrank+1);
    2829  }
    2930
    3031  /* node 1 to node n-2 will send message to the next node */
    31   if(myid>0 && myid<numprocs-1)
     32  if(myrank>0 && myrank<numprocs-1)
    3233  {
    33     MPI_Recv(&n, 1, MPI_INT, myid-1, 99, MPI_COMM_WORLD, &status);
    34     printf("[Node %d] << 「%d」[Node %d]\n", myid, n, status.MPI_SOURCE);
    35     n = myid;
    36     MPI_Send(&n, 1, MPI_INT, myid+1, 99, MPI_COMM_WORLD);
    37     printf("[Ndde %d]「%d」 >> [Node %d]\n\n", myid, n, myid+1);
     34    MPI_Recv(&n, 1, MPI_INT, myrank-1, 99, MPI_COMM_WORLD, &status);
     35    printf("[Node %d] << 「%d」[Node %d]\n", myrank, n, status.MPI_SOURCE);
     36    n = myrank;
     37    MPI_Send(&n, 1, MPI_INT, myrank+1, 99, MPI_COMM_WORLD);
     38    printf("[Ndde %d]「%d」 >> [Node %d]\n\n", myrank, n, myrank+1);
    3839  }
    3940
    4041  /* the final node n-1 will not send any message but receive*/
    41   if(myid==numprocs-1)
     42  if(myrank==numprocs-1)
    4243  {
    43     MPI_Recv(&n, 1, MPI_INT, myid-1, 99, MPI_COMM_WORLD, &status);
    44     printf("[Node %d] << 「%d」[Node %d]\n", myid, n, status.MPI_SOURCE);
     44    MPI_Recv(&n, 1, MPI_INT, myrank-1, 99, MPI_COMM_WORLD, &status);
     45    printf("[Node %d] << 「%d」[Node %d]\n", myrank, n, status.MPI_SOURCE);
    4546  }
    4647  MPI_Finalize();
    47  return 0;
     48}
    4849}}}
    4950= Result =