title: Segmentation fault (core dumped) in parallel computing
body: <p>I am trying to code an AMPI to sum a 1d array in parallel. However, I am getting a segmentation fault (core dumped). </p>
  
  <p>I tried to fix my function so many times but I could not find where the error is or how to fix it. </p>
  
  <pre><code>/* File: mpi_sum.c
  * Compile as: mpicc -g -Wall -std=c99 -o mpi_sum mpi_sum.c -lm
  * Run as:  mpirun -n 40  ./mpi_sum
  * Description: An MPI solution to sum a 1D array. */
  
  int main(int argc, char *argv[]) {
    int myID, numProcs;  // myID for the index to know when should the cpu start and stop calculate
                         //numPro numper of cpu you need to do the calculation
    double localSum;    // this for one operation on one cpu
    double parallelSum; // this for collecting the values of localsum
    int length = 10000000; // this for how many num
    double Fact = 1 ;
    int i; // this for for loop
    clock_t clockStart, clockEnd;   // timer
    srand(5); // Initialize MPI
    MPI_Init(NULL, NULL); //Initialize MPI
    MPI_Comm_size(MPI_COMM_WORLD, &amp;numProcs); // Get size 
    MPI_Comm_rank(MPI_COMM_WORLD, &amp;myID); // Get rank
    localSum = 0.0;                               // the value for eash cpu is 0
    int A = (length / numProcs)*((long)myID);     // this is to make each cpu work on his area
    int B = (length / numProcs)*((long)myID + 1); // this is to make each cpu work on his area
  
    A ++;                                         // add 1 to go to next num
    B ++;
  
    clockStart = clock();                     // start the timer to see how much time it take
    for (i = A; i &lt; B; i++)
    {
            Fact = (1 / myID - 1/numProcs) / (1 - 1/numProcs);
            localSum += Fact ;
    }
  
    MPI_Reduce(&amp;localSum, &amp;parallelSum, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
  
    clockEnd = clock();
  
    if (myID == 0)
    {
            printf("Time to sum %d floats with MPI in parallel %3.5f seconds\n", length, (clockEnd - clockStart) / (float)CLOCKS_PER_SEC);
            printf("The parallel sum: %f\n", parallelSum + 1);
    }
  
      MPI_Finalize();
    return 0;
  }
  </code></pre>