title: Receiving with MPI_Type_vector in C
body: <p>I have a a statically allocated 2D array NxN, and I want to send the <code>i</code>th column (with <code>i = 0 ... N-1</code>).</p>
  
  <p>I write:</p>
  
  <pre><code>int main(int argc, char **argv) {
  
      int myrank, nprocs;
      int i,j;
  
      int matrix[N][N]={{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}};
      int col[N];
  
      ...
  
      // Define type "column"
      MPI_Datatype column;
      MPI_Type_vector(N,1,N,MPI_INT,&amp;column);
      MPI_Type_commit(&amp;column);
  
      if(myrank==0){
          j=0;
          MPI_Send(&amp;matrix[0][j],1,column,1,99,MPI_COMM_WORLD);
      }
  
      if(myrank==1){
          // **** FIRST MODE: Don't use "column" type *****
          MPI_Recv(col,N,MPI_INT,0,99,MPI_COMM_WORLD,&amp;info);
  
          // **** SECOND MODE: Use "column" type *****
          // MPI_Recv(col,1,column_INT,0,99,MPI_COMM_WORLD,&amp;info);
  
          printf("\nColumn: ");
          for(j=0;j&lt;N;j++)
              printf("\n %d",col[j]);
      }
  
      MPI_Type_free(&amp;column);
      MPI_Finalize();
  
      return 0;
  }
  </code></pre>
  
  <p>Why does the first mode return correctly:</p>
  
  <pre><code>1 5 9 13
  </code></pre>
  
  <p>And the second return incorrectly?</p>
  
  <pre><code>1  -2  1980804601  1980804675
  </code></pre>