title: How to parallelize dot product with MPI_Scatter correctly?
body: <p>Stack overflow! I'm writing a parallel computation program for term project in my university. I've tried to parallelize dot product with MPI:</p>
  <pre><code>double Multiply(double *X,double *Y,int N) {
      MPI_Init(NULL,NULL);
      int world_size;
      MPI_Comm_size(MPI_COMM_WORLD, &amp;world_size);
      int world_rank;
      MPI_Comm_rank(MPI_COMM_WORLD, &amp;world_rank);
      MPI_Comm comm;
      double *Xbuffer;
      Xbuffer=new double[N/world_size];
      double *Ybuffer;
      Ybuffer=new double[N/world_size];
      double *curr;
      curr=new double[N/world_size];
      MPI_Scatter(X,N/world_size,MPI_DOUBLE,Xbuffer,1,MPI_DOUBLE,0,comm);
      MPI_Scatter(Y,N/world_size,MPI_DOUBLE,Ybuffer,1,MPI_DOUBLE,0,comm);
      for (int i=0;i&lt;N/world_size;i++) curr[i]=Xbuffer[i]*Ybuffer[i];
      if (world_rank==0) {
          double *prods;
          prods=new double[N];
          MPI_Gather(curr,N/world_size,MPI_DOUBLE,prods,1,MPI_DOUBLE,0,comm);
          double Sum=0;
          for (int i=0;i&lt;N;i++) Sum+=prods[i];
          return Sum;
      }
  }
  </code></pre>
  <p>However, this code doesn't work, it shows me Segmentation fault in the result. As I understand, I can't scatter vectors into more pieces than I have processors to send them to, so I scatter them into N/world_size parts instead of N parts. What have I done wrong in this function?</p>