title: How to pass 2D array in MPI and create a dynamic tag value using C language?
body: <p>I am new to MPI programing. I have a 8 by 10 array that I need to use to find the summation of each row parallely. In rank 0 (process 0), it will generate the 8 by 10 matrix using a 2 dimensional array. Then I would use <code>tag</code> number as the first index value(row number) of the array. This way, I can use a unique buffer to send through Isend. However, it looks like my method of tag number generation for Isend is not working. Can you please look in to the following code and tell me if I am passing the 2D array correctly and tag number. When I run this code, it stop just after executing rannk 1 and waits. I use 3 process for this example and use the command <code>mpirun -np 3 test</code> please let me know how to tackle this problem with an example if possible. </p>
  
  <pre><code>#include "mpi.h"
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main (int argc, char *argv[])
  {
          MPI_Init(&amp;argc, &amp;argv);
          int world_rank;
          MPI_Comm_rank(MPI_COMM_WORLD, &amp;world_rank);
          int world_size;
          MPI_Comm_size(MPI_COMM_WORLD, &amp;world_size);        
          int tag = 1;        
          int arr[8][10]; 
          MPI_Request request;
          MPI_Status status;
          int source = 0;
          int dest;
  
          printf ("\n--Current Rank: %d\n", world_rank);
  
          if (world_rank == 0)
          {
              int i = 0;
              int a, b, x, y;
  
              printf("* Rank 0 excecuting\n");
  
              for(a=0; a&lt;8/(world_size-1); a++)//if -np is 3, this will loop 4 times
              {           
                  for(b=0; b&lt;(world_size-1); b++)//if -np is 3, this loops will loop 2 times
                  {//So, if -np is 3, due to both of these loops, Isend will be called 8 times
                      dest = b+1;     
                      tag = a+b;//create a uniqe tag value each time, which can be use as first index value of array
                      //Error: This tag value passing to Isend doesn't seems to be workiing
                      MPI_Isend(&amp;arr[tag][0], 10, MPI_INT, dest, tag, MPI_COMM_WORLD, &amp;request);  
                  }
              }
  
              for(x=0; x&lt;8; x++)//Generating the whole 8 by 10 2D array
              {   
                  i++;
                  for ( y = 0; y &lt; 10; y++ )
                  {
                      arr[x][y] = i; 
                  }   
              }               
          }
          else 
          {
              int a, b;                   
              for(b=1; b&lt;=8/(world_size-1); b++)
              {
                  int sum = 0;
                  int i;
                  MPI_Irecv(&amp;arr[tag][0], 10, MPI_INT, source, tag, MPI_COMM_WORLD, &amp;request);
                  MPI_Wait (&amp;request, &amp;status);               
                          //Error: not getting the correct tag value
                  for(i = 0; i&lt;10; i++)
                  {   
                      sum = arr[tag][i]+sum;
                  }
                  printf("\nSum is: %d at rank: %d and tag is:%d\n", sum, world_rank, tag);
              }           
          }
          MPI_Finalize();
  }
  </code></pre>