title: MPI call inside function and function arguments
body: <p>I have a simulation that I want to write in MPI and I have started to read about it online. In my simulation I have a function to which I pass an argument as a pointer to the array of particles because I need to modify it during simulation. Now, I do not fully understand how MPI works so I wrote this little program.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include "mpi.h"
  void function(int* a)
  {
      int size, rank;
      MPI_Init(NULL,NULL);
      MPI_Comm_size(MPI_COMM_WORLD, &amp;size);
      MPI_Comm_rank(MPI_COMM_WORLD, &amp;rank);
      if(rank!=0)
      {
          printf("%d ", *a);
          printf("process: %d", rank);
      }
      else
      {
          (*a)++;
          printf("%d ", *a);
          printf("process: %d", rank);
      }
      printf("\n");
      MPI_Finalize();
  }
  
  int main (void) {
      int a,i;
      i=0;
      a=5;
      function(&amp;a);
      printf("%d %d\n",a,(i++));
      printf("%d\n", i);
      return 0;
  }
  </code></pre>
  
  <p>when I run it with: <code>mpirun -np 2 ./program</code> and  I got the output like below:</p>
  
  <pre><code>6 process: 0
  5 process: 1
  5 0
  6 0
  1
  1
  </code></pre>
  
  <p>Does this means that each process has its own copy of variables <strong><code>a</code></strong> and <strong><code>i</code></strong>, and how is MPI still running after I have called <code>MPI_Finalize()</code> inside <code>function()</code>.</p>