Sending 2 dim array using scatter

Posted by MPI_Beginner on Stack Overflow See other posts from Stack Overflow or by MPI_Beginner
Published on 2010-05-19T21:57:10Z Indexed on 2010/05/19 22:00 UTC
Read the original article Hit count: 406

Filed under:
|
|
|

I am a beginner in MPI, and i am using C Language, and Simulator for Processors (MPICH2), i wrote the following code to send a 2D array to make 2 processors take a line from it but it produces error when running MPICH2, the code is:

int main ( int argc , char *argv[] )

{

  int rank;

  int commsize;

  MPI_Init(&argc, &argv);

  MPI_Comm_size(MPI_COMM_WORLD,&commsize);

  MPI_Comm_rank(MPI_COMM_WORLD,&rank);

  char** name=malloc(2*sizeof(char*));

  int i;

  for(i=0;i<2;i++){

      name[i]=malloc(15*sizeof(char));
  }

  name[0]="name";

  name[1]="age";

  if(rank==0){


  char** mArray=malloc(2*sizeof(char*));

  MPI_Scatter(&name,1,MPI_CHAR,&mArray,1,MPI_CHAR,0,MPI_COMM_WORLD);//send

 }

 else{

       char** mArray=malloc(2*sizeof(char*));

       int k;

       for(k=0;k<2;k++){
             mArray[k]=malloc(15*sizeof(char));
       }
       MPI_Scatter(&mArray,1,MPI_CHAR,&mArray,1,MPI_CHAR,0,MPI_COMM_WORLD);//receive       

       printf("line is %s \n",mArray[rank-1]);

       }
       MPI_Finalize();
}

© Stack Overflow or respective owner

Related posts about 2d-array

Related posts about scatter