title: Seg Faults while using MPI (Fortran)
body: <p>I am very new to MPI and Fortran alike. I have been working on trying to figure this out for a few hours now, with no luck. In my code below, everything is working just fine (besides the fact that my <code>s</code> variable is isolated between processes. When I try to implement the <code>MPI_SEND</code> and <code>MPI_RECV</code> I get the seg faults constantly. I can't seem to figure out what the issue is.</p>
  
  <pre><code>  SUBROUTINE do_mpi_simpsons(l, u, n)
      INTEGER, INTENT (in) :: l, u, n
      ! REAL, INTENT (in) :: func
      DOUBLE PRECISION  :: result, walltime
      INTEGER :: clock_start, clock_rate, clock_max, clock_end
      DOUBLE PRECISION :: h, s, argVal, finalS
      INTEGER :: rank, size, ierror, tag, status(MPI_STATUS_SIZE), count, start, stop
  
      walltime = 0.0D0
  
      h = (u - l) / dble(n)
      s = func_hw(dble(l)) + func_hw(dble(u))
  
      CALL system_clock(clock_start, clock_rate, clock_max)
      CALL MPI_INIT(ierror)
      CALL MPI_COMM_SIZE(MPI_COMM_WORLD, size, ierror)
      CALL MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierror)
  
      count = n / size
  
      start = rank * count
      stop = start + count -1
  
      ! WRITE(*,*) "Start: ", start
      ! WRITE(*,*) "Stop: ", stop
      WRITE(*,*) rank
  
      DO i = start, stop, 2
        s = s + 4 * func_hw(dble(l)+dble(i)*h)
      END DO
      DO i = start+1, stop-1, 2
        s = s + 2 * func_hw(dble(l)+dble(i)*h)
      END DO
  
      ! This block is causing the seg faults
      IF(rank.eq.0) THEN
          finalS = s
          DO i = 1, size - 1
            CALL MPI_RECV(s, 64, MPI_DOUBLE, i, 1, MPI_COMM_WORLD, status, ierror)
            finalS = finalS + s
          END DO
      ELSE
          CALL MPI_SEND(s, 64, MPI_DOUBLE, 0, 1, MPI_COMM_WORLD, ierror)    
      END IF
  
      CALL MPI_FINALIZE(ierror)
      CALL system_clock(clock_end, clock_rate, clock_max)
  
      walltime = walltime + real(clock_end - clock_start) / real(clock_rate)
      result = s * h / 3 
  
      WRITE(*,*) "walltime = ", walltime, " seconds"
      WRITE(*,*) "result = ", result
    END SUBROUTINE
  </code></pre>