SURFEX v8.1
General documentation of Surfex
getheapstat.F90
Go to the documentation of this file.
1 SUBROUTINE getheapstat(KOUT, CDLABEL)
2 
3 USE parkind1 ,ONLY : jpim ,jprb ,jpib
4 #ifdef SFX_MPI
5 USE mpl_module
6 #endif
7 #ifdef NAG
8 USE f90_unix_env, ONLY: getenv
9 #endif
10 
11 IMPLICIT NONE
12 
13 INTEGER(KIND=JPIM), INTENT(IN) :: KOUT
14 CHARACTER(LEN=*), INTENT(IN) :: CDLABEL
15 INTEGER(KIND=JPIM) :: I, IMYPROC, INPROC, IRET, IOFFSET, II
16 INTEGER(KIND=JPIM), PARAMETER :: JP_NPROFILE = 9 ! pls. consult ifsaux/utilities/getcurheap.c
17 INTEGER(KIND=JPIM), PARAMETER :: ISIZE = jp_nprofile+1
18 INTEGER(KIND=JPIB) ILIMIT(isize)
19 INTEGER(KIND=JPIB) ICNT(isize)
20 REAL(KIND=JPRB), ALLOCATABLE :: ZSEND(:), ZRECV(:)
21 INTEGER(KIND=JPIM), ALLOCATABLE :: ICOUNTS(:)
22 CHARACTER(LEN=1) CLENV
23 CHARACTER(LEN=80) CLTEXT(0:4)
24 
25 CALL get_environment_variable("EC_PROFILE_HEAP", clenv) ! turn OFF by export EC_PROFILE_HEAP=0
26 
27 IF (kout >= 0 .AND. clenv /= '0') THEN
28 #ifdef SFX_MPI
29  imyproc = mpl_myrank()
30  inproc = mpl_nproc()
31 #else
32  imyproc = 0
33  inproc = 1
34 #endif
35  DO i=1,isize
36  ilimit(i) = i ! power of 10's ; pls. consult ifsaux/utilities/getcurheap.c
37  ENDDO
38 
39  ALLOCATE(zsend(isize))
40  ALLOCATE(zrecv(isize * inproc))
41  ALLOCATE(icounts(inproc))
42 
43  cltext(0) = "free()/DEALLOCATE -hits per byte range"
44  cltext(1) = "malloc()/ALLOCATE -hits per byte range"
45  cltext(2) = "Outstanding malloc()/ALLOCATE -hits per byte range"
46  cltext(3) = "Outstanding amount of malloc()/ALLOCATE -bytes per byte range"
47  cltext(4) = "Average amount of outstanding malloc()/ALLOCATE -bytes per byte range"
48 
49  DO ii=0,4
50  icnt(:) = 0
51  CALL profile_heap_get(icnt, isize, ii, iret)
52 
53  zsend(:) = 0
54  DO i=1,iret
55  zsend(i) = icnt(i)
56  ENDDO
57  zrecv(:) = -1
58 
59  icounts(:) = isize
60 #ifdef SFX_MPI
61  CALL mpl_gatherv(zsend(:), kroot=1, krecvcounts=icounts(:), &
62  &precvbuf=zrecv, cdstring='GETHEAPSTAT:')
63 #endif
64 
65  IF (imyproc == 1) THEN
66 ! Not more than 132 columns, please :-)
67  WRITE(kout,9000) trim(cltext(ii)),trim(cdlabel), "Node", &
68  & (ilimit(i),i=1,min(jp_nprofile,9)), "Larger"
69 9000 FORMAT(/,"Heap Utilization Profile (",a,"): ",a,&
70  &/,126("="),&
71  &//,(a4,2x,9(:,2x,4x,"< 10^",i1),:,2x,a10))
72  WRITE(kout,9001)
73 9001 FORMAT(4("="),2x,10(2x,10("="))/)
74  ioffset = 0
75  DO i=1,inproc
76  icnt(:) = zrecv(ioffset+1:ioffset+isize)
77  WRITE(kout,'(i4,2x,(10(:,2x,i10)))') i,icnt(:)
78  ioffset = ioffset + isize
79  ENDDO
80  ENDIF
81  ENDDO
82 
83  IF (imyproc == 1) THEN
84  WRITE(kout,'(/,a,/)') 'End of Heap Utilization Profile'
85  ENDIF
86 
87  DEALLOCATE(zsend)
88  DEALLOCATE(zrecv)
89  DEALLOCATE(icounts)
90 ENDIF
91 END SUBROUTINE getheapstat
ERROR in a
Definition: ecsort_shared.h:90
integer, parameter jpim
Definition: parkind1.F90:13
subroutine getheapstat(KOUT, CDLABEL)
Definition: getheapstat.F90:2
void profile_heap_get(ll_t val[], const int *Nval, const int *Icase, int *nret)
Definition: getcurheap.c:260
integer, parameter jprb
Definition: parkind1.F90:32
integer, parameter jpib
Definition: parkind1.F90:14