SUBROUTINE GSTATS_PSUT

! MEASURE PARALLELL START UP TIME

USE PARKIND1  ,ONLY : JPIM     ,JPRB

USE YOMGSTATS
USE YOMMPI   , ONLY : MREALT
USE MPL_MODULE


IMPLICIT NONE

INTEGER(KIND=JPIM) :: ITAG,ILSEND,ILBUF,JROC,IRECV,ISEND
REAL(KIND=JPRB) :: ZTBUF(2),ZCLOCK,ZCLOCKB

INTERFACE
#include "user_clock.h"
END INTERFACE

IF(NPROC_STATS > 1) THEN
  CALL USER_CLOCK(PELAPSED_TIME=ZCLOCKB)
  CALL MPL_BARRIER
  CALL USER_CLOCK(PELAPSED_TIME=ZCLOCK)
  ITAG = JPTAGSTAT
  IF (MYPROC_STATS /= 1) THEN
    ZTBUF(1) = ZCLOCKB
    ZTBUF(2) = ZCLOCK
    ILSEND = 2
    ISEND = 1
    CALL MPL_SEND(ZTBUF(1:ILSEND),KDEST=NPRCIDS_STATS(ISEND), &
     & KTAG=ITAG,CDSTRING='SUSTATS:')
  ELSE
    ILBUF = 2
    ALLOCATE(TIME_START(NPROC_STATS))
    TIME_START(1) = ZCLOCKB - TIMELCALL(0)
    DO JROC=2,NPROC_STATS
      IRECV = JROC
      CALL MPL_RECV(ZTBUF(1:ILBUF),KSOURCE=NPRCIDS_STATS(IRECV), &
       & KTAG=ITAG,CDSTRING='SUSTATS:')
      TIME_START(JROC) = ZTBUF(1) - TIMELCALL(0) -(ZTBUF(2)-ZCLOCK)
    ENDDO
  ENDIF
ENDIF

END SUBROUTINE GSTATS_PSUT
