SURFEX v8.1
General documentation of Surfex
getmemstat.F90
Go to the documentation of this file.
1 SUBROUTINE getmemstat(KOUT, CDLABEL)
2 
3 USE parkind1 ,ONLY : jpim ,jprb ,jpib
4 #ifdef SFX_MPI
5 USE mpl_module
6 #endif
7 IMPLICIT NONE
8 
9 INTEGER(KIND=JPIM), INTENT(IN) :: KOUT
10 CHARACTER(LEN=*), INTENT(IN) :: CDLABEL
11 INTEGER(KIND=JPIM) :: I, IMYPROC, INPROC, IOFFSET
12 INTEGER(KIND=JPIM), PARAMETER :: JP_MEMKEYS = 5 ! pls. consult ifsaux/utilities/getmemvals.F90
13 INTEGER(KIND=JPIM) IMEMKEYS(jp_memkeys)
14 INTEGER(KIND=JPIB) IMEMVALS(jp_memkeys)
15 REAL(KIND=JPRB), ALLOCATABLE :: ZSEND(:), ZRECV(:)
16 INTEGER(KIND=JPIM), ALLOCATABLE :: ICOUNTS(:)
17 CHARACTER(LEN=1) CLENV
18 
19 CALL get_environment_variable("EC_PROFILE_MEM", clenv) ! turn OFF by export EC_PROFILE_MEM=0
20 
21 IF (kout >= 0 .AND. clenv /= '0') THEN
22 #ifdef SFX_MPI
23  imyproc = mpl_myrank()
24  inproc = mpl_nproc()
25 #else
26  imyproc = 0
27  inproc = 1
28 #endif
29  ALLOCATE(zsend(jp_memkeys))
30  ALLOCATE(zrecv(jp_memkeys * inproc))
31  ALLOCATE(icounts(inproc))
32 
33 ! 1=MAXHEAP, 2=MAXRSS, 3=CURRENTHEAP, 5=MAXSTACK, 6=PAGING
34  imemkeys(:) = (/1, 2, 3, 5, 6/)
35  CALL getmemvals(jp_memkeys, imemkeys, imemvals)
36 
37  zsend(:) = 0
38  DO i=1,jp_memkeys
39  zsend(i) = imemvals(i)
40  ENDDO
41  zrecv(:) = -1
42 
43  icounts(:) = jp_memkeys
44 #ifdef SFX_MPI
45  CALL mpl_gatherv(zsend(:), kroot=1, krecvcounts=icounts(:), &
46  &precvbuf=zrecv, cdstring='GETMEMSTAT:')
47 #endif
48 
49  IF (imyproc == 1) THEN
50  WRITE(kout,9000) trim(cdlabel)
51 9000 FORMAT(/,"Memory Utilization Information (in bytes) : ",a,/,79("="),//,&
52  & "Node Max heapsize Max resident Current heap Max stack I/O-paging #",/,&
53  & "==== ============ ============ ============ ============ ============",//)
54  ioffset = 0
55  DO i=1,inproc
56  imemvals(:) = zrecv(ioffset+1:ioffset+jp_memkeys)
57  WRITE(kout,'(I4,5(3X,I12))') i,imemvals(:)
58  ioffset = ioffset + jp_memkeys
59  ENDDO
60  WRITE(kout,'(/,a,/)') 'End of Memory Utilization Information'
61  ENDIF
62 
63  DEALLOCATE(zsend)
64  DEALLOCATE(zrecv)
65  DEALLOCATE(icounts)
66 
67  CALL getheapstat(kout, cdlabel)
68 ENDIF
69 END SUBROUTINE getmemstat
ERROR in a
Definition: ecsort_shared.h:90
integer, parameter jpim
Definition: parkind1.F90:13
subroutine getheapstat(KOUT, CDLABEL)
Definition: getheapstat.F90:2
integer, parameter jprb
Definition: parkind1.F90:32
subroutine getmemstat(KOUT, CDLABEL)
Definition: getmemstat.F90:2
integer, parameter jpib
Definition: parkind1.F90:14
subroutine getmemvals(N, KEY, KVAL)
Definition: getmemvals.F90:2