/* ******************************************************************* C-DAC Tech Workshop : hyPACK-2013 October 15-18, 2013 Example 4.4 : upper-traingular-portion-ddtype.c Objective : To build derived datatype in which process with rank 0 sends one row entries of a two dimensional real array, which are contiguous entries of two dimensional real array to the process with rank 1. Input : The input file for Two dimansioanl real array Output : Process with Rank 1 prints the elements of the Upper traingular matrix entries in a row-wise Created : August-2013 E-mail : hpcfte@cdac.in ********************************************************************* */ #include #include"mpi.h" #define n_size 5 int main(int argc , char **argv) { int Myrank, Numprocs; int In_Matrix[n_size][n_size],i=0,in=0,inc=0,j=0,k=0; int low_Matrix[n_size][n_size],col,row; int blocklen[n_size],displacement[n_size]; MPI_Datatype new_index_t; MPI_Status status; /*.......Initialize MPI.............................*/ MPI_Init(&argc,&argv); MPI_Comm_rank(MPI_COMM_WORLD,&Myrank); MPI_Comm_size(MPI_COMM_WORLD,&Numprocs); /*................Read Input Matrix......................*/ if(Numprocs == 2) { if(Myrank==0) { for(row=0; row=0;i--) { blocklen[j++]=(n_size+1)-i; displacement[k++]=n_size*inc++; } /*........Define the MPI index type & commit it..............................*/ MPI_Type_indexed(n_size,blocklen,displacement,MPI_INT,&new_index_t); MPI_Type_commit(&new_index_t); /*........Send the data to process 1.....................*/ if(Myrank == 0) { MPI_Send(In_Matrix,1,new_index_t,1,0,MPI_COMM_WORLD); } else { /*....Intialize the output matrix to 0.....................*/ for(row=0;row