Changes between Initial Version and Version 1 of mpich/point_to_point/demo4


Ignore:
Timestamp:
Jun 25, 2008, 3:51:43 PM (16 years ago)
Author:
wade
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • mpich/point_to_point/demo4

    v1 v1  
     1= Source code =
     2{{{
     3/* Program:
     4 *   讓 node 0 可以接受來自任何 node 的訊息
     5 * History:
     6 *   2008-06-24 BETA
     7 */
     8
     9#include <stdio.h>
     10#include <mpi.h>
     11
     12main (int argc, char **argv)
     13{
     14  int numprocs, myrank, i=0, buf;
     15  MPI_Status status;
     16  MPI_Init(&argc, &argv);
     17  MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
     18  MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
     19
     20  if (myrank > 0)
     21  {
     22    for(i = 0; i < 5; i++)
     23    {
     24      buf = myrank * 100 + i;
     25      MPI_Send(&buf, 1, MPI_INT, 0, i, MPI_COMM_WORLD);
     26    }
     27  }
     28  if (myrank == 0)
     29  {
     30    for (i = 0; i < 5*(numprocs-1); i++)
     31    {
     32      MPI_Recv(&buf, 1, MPI_INT, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
     33      printf("[Node %d][Tag %d] => %d\n", status.MPI_SOURCE, status.MPI_TAG, buf);
     34    }
     35  }
     36  MPI_Finalize();
     37}
     38
     39}}}
     40
     41= Result =
     42[[Image(demo4-01.png)]]