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();
}