title: MPI_Scatterv don't work well
body: <p>I want to scatter rows of an boolean random array among 4 nodes but just node 0 work properly ,The following is the result of the run, please help me.
  regards</p>
  
  <pre><code>int main(int argc, char *argv[]) {
  
  
      int size, rank, divided_pop_size, sum = 0, root = 0,procgridsize;
      const int num_vertices = 3;
      int **indivisual, **recbuf;
      int *sendcounts;     //specifying the number of elements to send to each processor
      int *displs;         //Entry i specifies the displacement   
      MPI_Status status;
      int offset,rows;
  
      MPI_Init(&amp;argc, &amp;argv);
      MPI_Comm_size(MPI_COMM_WORLD, &amp;size);
      MPI_Comm_rank(MPI_COMM_WORLD, &amp;rank);
  
      divided_pop_size = (n_initial_pop / size)*num_vertices;
      rows = n_initial_pop / size;
      //~~~~~~~~~~~~~~~~~~~~~~~decleration of receive buffer
      recbuf = new int*[n_initial_pop / size];
  
      for (int i = 0; i &lt; n_initial_pop / size; i++)
          recbuf[i] = new int[num_vertices]; 
  
  
      if (rank == root)
      {
  
          indivisual = new int*[n_initial_pop];
  
          for (int i = 0; i &lt; n_initial_pop; i++)
              indivisual[i] = new int[num_vertices];
  
          for (int i = 0; i &lt; n_initial_pop; i++)
          {
              for (int j = 0; j &lt; num_vertices; j++)
              {
                  indivisual[i][j] = rand() % 2;
              }
          }
          printf("indivisual array is:\n");
          for (int i = 0; i &lt; n_initial_pop; i++)
          {
              printf("\n");
              for (int j = 0; j &lt; num_vertices; j++)
                  printf("  %d", indivisual[i][j]);
          }
      }
  
      sendcounts = (int*)malloc(sizeof(int)*size);
      displs = (int*)malloc(sizeof(int)*size);
  
      if (rank == 0) {
          for (int i = 0; i&lt;size; i++) {
              sendcounts[i] = divided_pop_size;
  
              displs[i] = sum;
              sum += sendcounts[i];
  
          }
      }
      if (rank == 0) {
          for (int i = 0; i &lt; size; i++) {
              printf("sendcounts[%d] = %d\tdispls[%d] = %d\n", i, sendcounts[i], i, displs[i]);
          }
      }
      MPI_Scatterv(indivisual, sendcounts, displs, MPI_INT, recbuf,
          sendcounts[rank], MPI_INT,
          0, MPI_COMM_WORLD);
  
      for (int p = 0; p&lt;size; p++) {
          //printf("\nrank : %d", rank);
          if (rank == p) {
              printf("Local process on rank %d is:\n", rank);
              for (int i = 0; i&lt;n_initial_pop / size; i++) {
                  putchar('|');
                  for (int j = 0; j&lt;num_vertices; j++) {
                      printf("%d ", recbuf[i][j]);
                  }
                  printf("|\n");
              }
          }
          MPI_Barrier(MPI_COMM_WORLD);
      }
  
  
  
      MPI_Finalize();
  
      return 0;
  }
  </code></pre>
  
  <p>The result of run is:</p>
  
  <p><img src="https://i.stack.imgur.com/OuurY.png" alt=""></p>