# Message Passing

- ## Tasks, in Unix generally separate processes, are complete programs with their own local data.

  - Each task has its own ID.
  - Tasks communicate by sending and receiving messages.

- ## Widely available message passing libraries:

  - PVM
    - good for clusters.
  - MPI
    - emerging standard.

    #include <stdio.h>
    #include "mpi.h"
    main(int argc,char **argv)
    {
        int rank,size,sdata=100155,rdata=0;
        MPI_Status status;
        MPI_Init(&argc,&argv);
        MPI_Comm_rank( MPI_COMM_WORLD, &rank);
        MPI_Comm_size( MPI_COMM_WORLD, &size);
        if(rank==0) {
            MPI_Send(&sdata,1,MPI_INT,1,0,
                     MPI_COMM_WORLD);
            MPI_Recv(&rdata,1,MPI_INT,1,1,
                     MPI_COMM_WORLD,&status);
            if(rdata==sdata)
                 printf("test succeeds\n");
            else printf("test fails\n");
        }
        else {
            MPI_Recv(&rdata,1,MPI_INT,0,0,
                      MPI_COMM_WORLD,&status);
            MPI_Send(&rdata,1,MPI_INT,0,1,
                      MPI_COMM_WORLD);
        }
        MPI_Finalize(); exit(0);
    }

Previous slide | Next slide | Back to first slide | View graphic version