PROGRAM main
    USE double
    USE mpi
    IMPLICIT NONE
    INTEGER, PARAMETER :: procs = 4, size = 3, root = 1
    INTEGER :: nprocs, myrank, error
    INTEGER, DIMENSION(size,procs) :: input
    LOGICAL, DIMENSION(size,procs) :: source
    LOGICAL, DIMENSION(size) :: result, summary

    source = .FALSE.
    result = .FALSE.
    summary = .FALSE.
    CALL MPI_Init(error)
    CALL MPI_Comm_size(MPI_COMM_WORLD,nprocs,error)
    IF (nprocs /= procs) THEN
        PRINT *, 'Invalid number of processes'
        CALL MPI_Abort(MPI_COMM_WORLD,1,error)
    END IF

    CALL MPI_Comm_rank(MPI_COMM_WORLD,myrank,error)
    IF (myrank == root) THEN
        OPEN (11,FILE="Programs/integers.input",ACTION="READ")
        READ (11,*) input
        source = (input > 5000)
        CLOSE(11)
    END IF

    CALL MPI_Scatter(source,size,MPI_LOGICAL,    &
        result,size,MPI_LOGICAL,root,MPI_COMM_WORLD,error)
    WRITE (*,"('Processor ',I0,' now has data',100(1X,L1))") myrank,result
    CALL MPI_Allreduce(result,summary,size,MPI_LOGICAL,    &
        MPI_LAND,MPI_COMM_WORLD,error)
    WRITE (*,"('Processor ',I0,' summary data',100(1X,L1))") myrank,summary
    CALL MPI_Finalize(error)
END PROGRAM main
