next up previous


CSE302/CS320/ECE392 Introduction to Parallel Programming Lecture 13

Message Passing Interface

Introduction to MPI

Introduction to MPI

The MPI Programming Model

Process Model and Groups

Communication Scope

Process Groups

Group Management

Group Management

Communicators

Asynchronous Library Calls

Synchronous Library Calls

Point-to-point Communication

Communcation Completion

Blocking Send/Recv

Return Status Objects

Blocking Behaviour

Non-blocking Send/Recv

Completion Routines

Multiple Completions

Communication Modes

Buffered Mode

Flavors of Communication

Naming Conventions

Send/Receive Operations

Collective Communication

Communicating Non-Primitive Datatypes

Contiguous Datatype Constructor

Vector Datatype Constructor

Indexed Datatype Constructor

Structure Datatype Constructor

Other Datatype Routines

Example of a General Datatype

#include "mpi.h"

main() 
{
   float a[100][100][100],e[9][9][9];
   int oneslice, twoslice, threeslice, sizeofreal;
   int rank, ierr, status[MPI_STATUS_SIZE];

   mpi_init (ierr);
   mpi_comm_rank (MPI_COMM_WORLD, rank, ierr);
   if (rank==0) {
     mpi_type_extent(MPI_REAL, sizeofreal, ierr);
     mpi_type_vector(9, 1, 2, MPI_REAL, oneslice, ierr);
     mpi_type_hvector(9, 1, 100*sizeofreal, oneslice, twoslice, ierr);
     mpi_type_hvector(9, 1, 100*100*sizeofreal, twoslice, threeslice, ierr);
     mpi_type_commit(threeslice, ierr);
     mpi_send(a(1,3,2), 1, threeslice, 1, 0, MPI_COMM_WORLD, ierr);
   } else if (rank==1) {
     mpi_recv(e, 9*9*9, MPI_REAL, 0, 0, MPI_COMM_WORLD, status, ierr);
   }
   mpi_finalize (ierr);
}

Application Topologies

Topological Inquiry Routines

Uses of Topologies

Pack and Unpack

Packing Data

Unpacking Data

Example of Unpacking

Code for Unpacking Example

mpi_recv(msg,size,MPI_PACKED,MPI_ANY_SOURCE,MPI_ANY_TAG,comm,status,ierr);

pos=0;
/* get typeid : 0 - end of message, 1 - integers, 2 - reals */
mpi_unpack(message,size,pos,typeid,1,MPI_INTEGER,comm,ierr);

/* check for end of message */
while (typeid>0) {

  /* unpack number of items field */
  mpi_unpack(message,size,pos,nitems,1,MPI_INTEGER,comm,ierr);

  /* select type of unpack based on typeid */
  if (typeid==1) {
    mpi_unpack(message,size,pos,ints(nints),nitems,MPI_INTEGER,comm,ierr)
    nints+=nitems;
  } else {
    mpi_unpack(message,size,pos,reals(nreals),nitems,MPI_REAL,comm,ierr);
    nreals+=nitems;
  }

  /* unpack next typeid */
  mpi_unpack(message,size,pos,typeid,1,MPI_INTEGER,comm,ierr)
}



next up previous




Carolin Tschopp
Tue Jan 23 10:01:39 CST 1996