Changes between Version 2 and Version 3 of mpich/point_to_point/demo3


Ignore:
Timestamp:
Jun 17, 2008, 10:57:18 AM (16 years ago)
Author:
wade
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • mpich/point_to_point/demo3

    v2 v3  
    55 * History:
    66 *   2008-06-12 BETA
     7 *   2008-06-17 更改顯示方式,並增加註解
    78 */
    89
     
    1920  MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
    2021  MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
     22
     23  /* Node 0 will do the following */
    2124  if(myrank == 0)
    2225  {
    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++)
    2528    {
    2629      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);
    2831    }
    29     printf("\n");
    3032  }
     33
     34  /* other Nodes will do the following */
    3135  if(myrank != 0)
    3236  {
    33     sprintf(message, "i am %d", myrank);
     37    /* send node's rank to Node 0 */
     38    sprintf(message, "[%d]", myrank);
    3439    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);
    3741  }
    3842  MPI_Finalize();