title: stack smashing detected when use MPI_Reduce
body: <p>I have learned to use some MPI functions. When I try to use <code>MPI_Reduce</code>, I get <strong>stack smashing detected</strong> when I run my code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;mpi.h&gt;
  
  void main(int argc, char **argv) {
      int i, rank, size;
      int sendBuf, recvBuf, count;
      MPI_Init(&amp;argc, &amp;argv);
      MPI_Comm_size(MPI_COMM_WORLD, &amp;size);
      MPI_Comm_rank(MPI_COMM_WORLD, &amp;rank);
      sendBuf = rank;
      count = size;
      MPI_Reduce(&amp;sendBuf, &amp;recvBuf, count, MPI_INT, 
          MPI_SUM, 0, MPI_COMM_WORLD);
  
      if (rank == 0) {
          printf("Sum is %d\n", recvBuf);
      }
  
      MPI_Finalize();
  }
  </code></pre>
  
  <p>It seem to be okey with my code. It will print <strong>sum of all</strong> rank in <code>recvBuf</code>with process 0. In this case, it will print <code>Sum is 45</code> if I run my code with 10 process <code>mpirun -np 10 myexecutefile</code>. But I don't know why my code has the error:</p>
  
  <pre><code>Sum is 45
  *** stack smashing detected ***: example6 terminated
  [ubuntu:06538] *** Process received signal ***
  [ubuntu:06538] Signal: Aborted (6)
  [ubuntu:06538] Signal code:  (-6)
  [ubuntu:06538] *** Process received signal ***
  [ubuntu:06538] Signal: Segmentation fault (11)
  [ubuntu:06538] Signal code:  (128)
  [ubuntu:06538] Failing at address: (nil)
  --------------------------------------------------------------------------
  mpirun noticed that process rank 0 with PID 0 on node ubuntu exited on signal 11 (Segmentation fault).
  --------------------------------------------------------------------------
  </code></pre>
  
  <p>What is the problem and how can I fix it?</p>