InBlock.gif#include<stdio.h>
InBlock.gif#include<mpi.h>
InBlock.gif#define SIZE 4
InBlock.gif
InBlock.gifint main(int argc, char *argv[]){
InBlock.gif  int numTasks, rank, source = 0, dest, tag = 1;
InBlock.gif  float a[SIZE][SIZE] = {
InBlock.gif  {1.0, 2.0, 3.0, 4.0},
InBlock.gif  {5.0, 6.0, 7.0, 8.0},
InBlock.gif  {9.0, 10.0, 11.0, 12.0},
InBlock.gif  {13.0, 14.0, 15.0, 16.0}
InBlock.gif  };
InBlock.gif
InBlock.gif  float b[SIZE];
InBlock.gif
InBlock.gif  MPI_Status status;
InBlock.gif  MPI_Datatype columnType;
InBlock.gif
InBlock.gif  MPI_Init(&argc, &argv);
InBlock.gif  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
InBlock.gif  MPI_Comm_size(MPI_COMM_WORLD, &numTasks);
InBlock.gif
InBlock.gif  //MPI_Type_vector(count, blockLength, stride, oldType, &newType);
InBlock.gif  MPI_Type_vector(SIZE, 1, SIZE, MPI_FLOAT, &columnType);
InBlock.gif  MPI_Type_commit(&columnType);
InBlock.gif
InBlock.gif  if(numTasks ==    SIZE){
InBlock.gif    if(rank == 0){
InBlock.gif      int i, j;
InBlock.gif      for(j = 0; j < numTasks; j++){
InBlock.gif              int count = 1;
InBlock.gif        int dest = j;
InBlock.gif        for(i = 0; i < numTasks; i++){
InBlock.gif          MPI_Send(&a[i][j], count, columnType,    
InBlock.gif            dest, tag, MPI_COMM_WORLD);
InBlock.gif        }
InBlock.gif      }
InBlock.gif    }
InBlock.gif
InBlock.gif    MPI_Recv(b, SIZE, MPI_FLOAT, source, tag, MPI_COMM_WORLD, &status);
InBlock.gif    printf("rank = %d b = %3.1f %3.1f %3.1f %3.1f\n",
InBlock.gif      rank, b[0], b[1], b[2], b[3]);
InBlock.gif  }else{
InBlock.gif    printf("Must Specify %d processors. Terminating.\n", SIZE);    
InBlock.gif  }
InBlock.gif
InBlock.gif  MPI_Type_free(&columnType);
InBlock.gif  MPI_Finalize();
InBlock.gif}