title: using MPI_Scatter causing error EXIT CODE 139
body: <p>i'm trying to work on some image using parallel computation..
  my code is:</p>
  
  <pre><code>int main(int argc, char **argv){
  int myid, numprocs, rows_per_process;
  int N, i, j, x, y;
  int    namelen,num_of_pixels;
  double startwtime = 0.0 , endwtime;
  char   processor_name[MPI_MAX_PROCESSOR_NAME];
  PPMImage *image;
  
  MPI_Init(&amp;argc,&amp;argv);
  MPI_Comm_size(MPI_COMM_WORLD,&amp;numprocs);
  MPI_Comm_rank(MPI_COMM_WORLD,&amp;myid);
  MPI_Get_processor_name(processor_name,&amp;namelen);
  
  if( myid==0){
      startwtime = MPI_Wtime();
      image = readPPM("pic.ppm");
      x = image-&gt;x;
      y = image-&gt;y;
  }
  
  MPI_Barrier(MPI_COMM_WORLD);
  MPI_Bcast( &amp;x , 1 , MPI_INT , 0 , MPI_COMM_WORLD);
  MPI_Bcast( &amp;y , 1 , MPI_INT , 0 , MPI_COMM_WORLD);
  
  unsigned char *pic_array;
  unsigned char *old_pic, *new_pic;
  rows_per_process = y/numprocs;
  old_pic = (unsigned char*)malloc(sizeof(unsigned char)*(x*rows_per_process*3));
  new_pic = (unsigned char*)malloc(sizeof(unsigned char)*(x*rows_per_process*3));
  
  fprintf(stdout,"total rgb pixels =  %d\n",x*y*3);
  
  if (myid == 0){
      num_of_pixels = image-&gt;x * image-&gt;y;
      pic_array = (unsigned char*)malloc(sizeof(unsigned char)*(rows_per_process*numprocs*3*x));
      for(i=0;i&lt;rows_per_process*numprocs*x;i++){
          pic_array[3*i] = image-&gt;data[i].red;
          pic_array[3*i+1] = image-&gt;data[i].green;
          pic_array[3*i+2] = image-&gt;data[i].blue;
      }
      fprintf(stdout,"FINISH \n");
  }
  
  MPI_Barrier(MPI_COMM_WORLD);
  
      fprintf(stdout,"BARRIER x = %d\n",x);
  
  MPI_Scatter(pic_array, rows_per_process*numprocs*3*x ,MPI_UNSIGNED_CHAR, old_pic,  rows_per_process * x * 3 ,MPI_UNSIGNED_CHAR,0, MPI_COMM_WORLD);
  
  N = .8 * x;
  </code></pre>
  
  <p>where x and y are the resolution parameters of the image.
  the thing is that for some reason i'm getting this as output and i can't figure out why:</p>
  
  <pre><code>total rgb pixels =  5992704
  
  total rgb pixels =  5992704
  
  total rgb pixels =  5992704
  
  total rgb pixels =  5992704
  
  FINISH
  
  BARRIER x = 1224
  
  BARRIER x = 1224
  
  BARRIER x = 1224
  
  BARRIER x = 1224
  
  ===================================================================================
  =   BAD TERMINATION OF ONE OF YOUR APPLICATION PROCESSES
  =   EXIT CODE: 139
  =   CLEANING UP REMAINING PROCESSES
  =   YOU CAN IGNORE THE BELOW CLEANUP MESSAGES
  </code></pre>
  
  <p>thanks for helping</p>