title: MPI_Scatter - not working as expected
body: <p>I am writing my first program using MPI and I am having hard time trying to properly send data to other processes using MPI_Scatter, modify them and receive the values using MPI_Gather. The code is as follows:</p>
  
  <pre><code>int** matrix;
  int m = 2, n = 2;
  int status;
  
  // could have been int matrix[2][2];
  
  matrix = malloc(m*sizeof(int*));
  
  for(i = 0; i &lt; m; i++) {
    matrix[i] = malloc(n*sizeof(int));
  }
  
  matrix[0][0] = 1;
  matrix[0][1] = 2;
  matrix[1][0] = 2;
  matrix[1][1] = 3;
  
  MPI_Init( &amp;argc, &amp;argv );
  MPI_Comm_rank( MPI_COMM_WORLD, &amp;rank ); 
  MPI_Comm_size( MPI_COMM_WORLD, &amp;size );
  
  printf("My name is %d out of %d\n", rank, size);
  
  MPI_Scatter(&amp;matrix, 1, MPI_INT, &amp;status, 1, MPI_INT, 0, MPI_COMM_WORLD);
  
  printf("My name is %d and my status is %d\n", rank, status);
  
  status += 1;
  
  MPI_Gather(&amp;status,1,MPI_INT,&amp;matrix,1,MPI_INT,0,MPI_COMM_WORLD);
  </code></pre>
  
  <p>The results is as follows:</p>
  
  <pre><code>My name is 0 out of 4
  My name is 1 out of 4
  My name is 1 and my status is 0
  My name is 2 out of 4
  My name is 2 and my status is 120
  My name is 0 and my status is 17773264
  My name is 3 out of 4
  My name is 3 and my status is 0
  </code></pre>
  
  <p>After MPI_Gather when I try to print the content of matrix I get segmentation fault...</p>
  
  <p>Which is not what I expect... I suspect that the problem is I have a 2d array and want to send single values. Is this right? How to correct this?</p>