title: MPI and multidimensional array allocation in C
body: <p>I'm try to use MPI_Scatter, sending rows of matrix(that are dynamically allocated), but it sending only one row, in others are junk. When I use static memory allocation - everything is good.</p>
  
  <pre><code>MPI_Init(&amp;argc, &amp;argv);
  int **matrix, *matrix_stor, *row,rank, P;
  MPI_Comm_size(MPI_COMM_WORLD, &amp;P);
  row = new int [P];
  for(int i = 0; i &lt; P; i++)
  {
      row[i] = 0;
  }
  matrix = new int *[P];
  for(int i = 0; i &lt; P; i ++)
      matrix[i] = new int [P];
  
  //int matrix[4][4], row[4], rank, size;
  MPI_Comm_rank(MPI_COMM_WORLD, &amp;rank);
  
  if (rank == 0){
      for(int i = 0; i &lt; P; i++){
          for(int j = 0; j &lt; P; j++){
              matrix[i][j] = rand()%20;
              cout &lt;&lt; matrix[i][j] &lt;&lt; " ";
          }
          cout &lt;&lt; endl;
      }
  }
  cout &lt;&lt; endl;
  
  MPI_Scatter(&amp;matrix[0][0], P, MPI_INT,&amp;row[0], P, MPI_INT,0,MPI_COMM_WORLD);
  for(int i = 0; i &lt; P; i++)
      cout &lt;&lt; row[i] &lt;&lt; " ";
  cout &lt;&lt; endl;
  free(matrix);
  free(row);
  MPI_Finalize();
  return 0;
  </code></pre>
  
  <p>And result is:<br>
  Source matrix:<br>
  1 7 14 0<br>
  9 4 18 18<br>
  2 4 5 5<br>
  1 7 1 11<br>
  Received rows:<br>
  1 7 14 0<br>
  3626672 3626800 0 0<br>
  16 1 119 -33686019<br>
  -33686019 -572662307 524296 786765  </p>