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


Ignore:
Timestamp:
Jun 6, 2008, 10:29:07 AM (16 years ago)
Author:
wade
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • mpich/point_to_point/demo2

    v1 v1  
     1/* Program:
     2 *   每個 node 將自己的 id 送給下一個 node。
     3 * History:
     4 *   2008-06-05 BETA
     5 */
     6
     7#include <mpi.h>
     8#include <stdio.h>
     9
     10int main(int argc,char *argv[])
     11{
     12  int n=0, myid, numprocs, i=0;
     13  MPI_Status status;
     14  MPI_Init(&argc,&argv);
     15  MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
     16  MPI_Comm_rank(MPI_COMM_WORLD,&myid);
     17  if(myid==0)
     18  {
     19    MPI_Send(&n, 1, MPI_INT, 1, 99, MPI_COMM_WORLD);
     20  }
     21  if(myid!=0)
     22  {
     23    MPI_Recv(&n, 1, MPI_INT, myid-1, 99, MPI_COMM_WORLD, &status);
     24    n++;
     25
     26    if(myid<numprocs-1)
     27
     28    {
     29
     30      MPI_Send(&n, 1, MPI_INT, myid+1, 99, MPI_COMM_WORLD);
     31
     32      printf("I am node %d\nI recive number %d from %d\n", myid, n, myid-1);
     33      printf("I send number %d to %d\n\n", n, myid+1);
     34
     35    }
     36
     37  }
     38
     39  MPI_Finalize();
     40
     41 return 0;
     42
     43}
     44