title: How to MPI_Gatherv columns from processor, where each process may send different number of columns
body: <p>Say 2 processes are participating. Process 0 (rank 0) has</p>
  
  <pre><code>A = { a d
        b e
        c f
      }
  </code></pre>
  
  <p>and process 1 (rank 1) has</p>
  
  <pre><code>A = { g
        h
        i
      }
  </code></pre>
  
  <p>I want both processors to send these columns to rank 0 so that rank 0 will have the following in say another 2D-array.</p>
  
  <pre><code>B = { a d g
        b e h
        c f i
      }
  </code></pre>
  
  <p>I create a new column data type for the MPI_Gatherv and am trying the following code, which is getting me no where. </p>
  
  <p>My specific questions are:</p>
  
  <ol>
  <li>How should I approach this</li>
  <li>What should be the send_type and recv_type. </li>
  <li>How should displacements be specified ( should they be in term of the new data type or MPI_CHAR)</li>
  </ol>
  
  <p>Thanks.</p>
  
  <p>This is my code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;mpi.h&gt;
  
  int main(int argc, char *argv[])
  {
    int numprocs, my_rank;
     long int i, j;
     MPI_Status status;
     char **A;
     char **B;
    MPI_Init(&amp;argc, &amp;argv);
    MPI_Comm_size(MPI_COMM_WORLD, &amp;numprocs);
    MPI_Comm_rank(MPI_COMM_WORLD, &amp;my_rank);
  
    if(my_rank == 0)
    {
      A = (char **)calloc((3), sizeof(char *));
      B = (char **)calloc((3), sizeof(char *));
      for(i=0; i&lt;3; ++i)
      {
         A[i] = (char *)calloc(2, sizeof(char));
         B[i] = (char *)calloc(3, sizeof(char));
      }
  
      A[0][0] = 'a';
      A[1][0] = 'b';
      A[2][0] = 'c';
      A[0][1] = 'd';
      A[1][1] = 'e';
      A[2][1] = 'f';
    }
    else
    {
      A = (char **)calloc((3), sizeof(char *));
      for(i=0; i&lt;3; ++i)
      {
         A[i] = (char *)calloc(1, sizeof(char));
      }
      A[0][0] = 'g';
      A[1][0] = 'h';
      A[2][0] = 'i';
  
    }
    MPI_Datatype b_col_type;
    MPI_Type_vector(3, 1, 1, MPI_CHAR, &amp;b_col_type);
    MPI_Type_commit(&amp;b_col_type);
    int displs[2] = {0, 2};
    int recvcounts[2] = {2, 1};
    MPI_Gatherv(&amp;A[0][0], recvcounts[my_rank], b_col_type, &amp;B[0][0], recvcounts, displs,    b_col_type, 0, MPI_COMM_WORLD);
    if(my_rank == 0)
    {
      for(i=0; i&lt;3; ++i)
      {
        for(j=0; j&lt;3; ++j)
          printf("%c ", B[i][j]);
        printf("\n");
      }
    }
    MPI_Finalize();
    return 0;
  }
  </code></pre>