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


Ignore:
Timestamp:
Mar 28, 2008, 11:27:35 AM (16 years ago)
Author:
wade
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • mpich/point_to_point/demo1

    v1 v1  
     1= 程式碼 =
     2{{{
     3/*
     4 * 每個 node 將訊息傳送給 node 0,由,node 0 統一印出
     5 */
     6
     7#include <stdio.h>
     8#include <mpi.h>
     9#include <string.h>
     10
     11main(int argc, char **argv)
     12{
     13  int myrank, i, numprocs;
     14  char message[20];
     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  if(myrank == 0)
     20  {
     21    printf("I am %d \n", myrank);
     22    for(i = 1; i < (numprocs); i++)
     23    {
     24      MPI_Recv(message, 20, MPI_CHAR, i, 99, MPI_COMM_WORLD, &status);
     25      printf(" I GOT %s \n", message);
     26    }
     27    printf("\n");
     28  }
     29  if(myrank != 0)
     30  {
     31    sprintf(message, "i am %d", myrank);
     32    MPI_Send(message, 20, MPI_CHAR, 0, 99, MPI_COMM_WORLD);
     33    printf("I am %d \n", myrank);
     34    printf("I send '%s\n\n ", message);
     35  }
     36  MPI_Finalize();
     37}
     38
     39結果: