title: MPI 2D array processing
body: <p>I have 2d array of integers. I want to process it to the new array. Each element of new array is average of primary array element neighbours with given margin. The simple algorithm would be:</p>
  <pre><code>double *buffer = new double[bufferSize];
  for (int row = margin; row &lt; arraySize - margin; row++)
          for (int col = margin; col &lt; arraySize - margin; col++) {
              fillBuffer(row, col, buffer);
              nextData[row][col] = average(buffer);
          }
  </code></pre>
  <p>fillBuffer function:</p>
  <pre><code>void fillBuffer(int row, int col, double *buffer) {
      int counter = 0;
      for (int i = row - margin; i &lt;= row + margin; i++)
          for (int j = col - margin; j &lt;= col + margin; j++)
              buffer[counter++] = data[i][j];
  }
  </code></pre>
  <p>I want to parrarelize it using MPI. I was wondering if I could use MPI_Scatter function to split primary array for every rank but still every rank will need a data from another rank to calculate values at the edges of array chunk. Maybe I can send primary array to all ranks but how to manage them to process only their part of it? Then how to share calculated elements of array with another rank which needs it to calculate elements at the edges?</p>
  <p>As I am new to MPI any tip might be helpful.</p>