title: Not able to run Histogram using MPI_Scatter and MPI_Reduce
body: <p>I am getting error while running below program when paralleling using MPI_Scatter and MPI_Reduce. When data does not belong to the particular bin it gets exited. But it is happening every time. All the time i run the program and its get exited by throwing this error of "Data does not belong to the bin". I am not sure it is because of wrong place for MPI_Scatter or MPI_Reduce. Please help me in regards to what is wrong with this c code? I am just putting here Main routine.</p>
  
  <pre><code>int main(int argc, char* argv[]) {   
     int bin_count = 5;   
     int i, bin;  
     float min_meas = 1.00;  
     float max_meas = sizeof(float);  
     float* bin_maxes;  
     int* bin_counts;  
     int* bin_result;  
     int data_count = 100;  
     float* data;  
     int size = 1;  
     int rank = 0;  
  
    MPI_Init(&amp;argc, &amp;argv);  
   // note that argc and argv are passed by address  
  
    MPI_Comm_rank(MPI_COMM_WORLD,&amp;rank);  
    MPI_Comm_size(MPI_COMM_WORLD,&amp;size);  
  
   /* Allocate arrays needed */  
    bin_maxes = malloc(bin_count*sizeof(float));     
    bin_counts = malloc(bin_count*sizeof(int));  
    bin_result = malloc(bin_count*sizeof(int));  
    data = malloc(data_count*sizeof(float));  
    int count = (int)data_count/size;  
  
    if (rank == 0){  
    /* Generate the random data */  
    Gen_data(min_meas, max_meas, data, data_count);   
  
    }  
  
    MPI_Scatter(data,count,MPI_FLOAT,data,data_count,MPI_FLOAT,0,MPI_COMM_WORLD);  
  
   /* Create bins for storing counts */  
    Gen_bins(min_meas, max_meas, bin_maxes, bin_counts, bin_count);  
  
   /* Count number of values in each bin */  
   for (i = 0; i &lt; count; i++) {  
      bin = Which_bin(data[i], bin_maxes, bin_count, min_meas); //decide data is belong to which bin  
      bin_counts[bin]++; //increments bin    
   }
  
   MPI_Reduce(bin_counts,bin_result,bin_count,MPI_INT,MPI_SUM,0,MPI_COMM_WORLD);  
  
   if(rank == 0) {  
      /* Print the histogram */  
      Print_histo(bin_maxes, bin_result, bin_count, min_meas); // prints the result  
   }  
  
   free(data);  
   free(bin_maxes);  
   free(bin_counts);  
   free(bin_result);  
  
   MPI_Finalize();  
  
   return 0;  
  
  }  
  </code></pre>