title: Scatter a vector into a variable MPI
body: <p>I'm trying to send from process with rank = 0 to all other process (1,2,3,4) a value from the vector <code>n_pointsBuffer</code>. The problem is that just process 0 gets its value but the others don't. Can anyone explain to me if it's possible what I'm trying to do, if so, how? It's the first time I use MPI.</p>
  
  <pre><code>#include &lt;mpi.h&gt;
  #include &lt;iostream&gt;
  #include &lt;cstdlib&gt;
  #include &lt;cmath&gt;
  
  using namespace std;
  
  int main(int argc, char* argv[]) {
  
  MPI::Init(argc, argv);
  
  int num_procs = MPI::COMM_WORLD.Get_size();
  int rank = MPI::COMM_WORLD.Get_rank();
  
  srand(getpid());
  int n_points;
  
  if (rank == 0) {
      int n_pointsBuffer[] = { 1000000, 1203100, 1231230, 1231000, 1312322 };
      MPI::COMM_WORLD.Scatter(n_pointsBuffer, 1, MPI::INT, &amp;n_points, 1,
              MPI::INT, 0);
  }
  
  cout &lt;&lt; "Rank = " &lt;&lt; rank &lt;&lt; ", n_points = " &lt;&lt; n_points &lt;&lt; "\n";
  
  double sum = 0;
  
  for (int i = 0; i &lt; n_points; i++) {
      double x = rand() / ((double) (RAND_MAX));
      double f = 1.0 / (1.0 + x * x);
      sum += f;
  }
  
  double avg_sum = 0;
  MPI::COMM_WORLD.Reduce(&amp;sum, &amp;avg_sum, 1, MPI::DOUBLE, MPI::SUM, 0);
  
  if (rank == 0) {
      double pi = 4.0 * (avg_sum / num_procs / ((double) (n_points)));
      cout &lt;&lt; "Pi is approx " &lt;&lt; pi &lt;&lt; " with error " &lt;&lt; pi - M_PI &lt;&lt; ".\n";
  }
  
  MPI::Finalize();
  
  return 0;
  }
  </code></pre>