PROGRAM main
    USE double
    USE mpi
    IMPLICIT NONE
    INTEGER, PARAMETER :: total = 12, size = 4, root = 1
    INTEGER :: nprocs, myrank, error
    REAL(KIND=DP), DIMENSION(total) :: source
    REAL(KIND=DP), DIMENSION(size) :: result

    source = 0.0_DP
    result = 0.0_DP
    CALL MPI_Init(error)
    CALL MPI_Comm_size(MPI_COMM_WORLD,nprocs,error)
    IF (size*nprocs /= total) 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/reals.input",ACTION="READ")
        READ (11,*) source
        CLOSE(11)
    END IF

    WRITE (*,"('Processor ',I0,' initial data',100(1X,F0.3))") myrank,source
    CALL MPI_Scatter(source,size,MPI_DOUBLE_PRECISION,    &
        result,size,MPI_DOUBLE_PRECISION,root,MPI_COMM_WORLD,error)
    WRITE (*,"('Processor ',I0,' now has data',100(1X,F0.3))") myrank,result
    CALL MPI_Finalize(error)
END PROGRAM main
