33 use precisn,
only: longint, wp
34 use const_gbl,
only: stdout
48 integer(longint) :: total_local_memory = 0
49 integer(longint) :: available_local_memory = 0
50 integer(longint) :: cached_tracked_memory = 0
51 logical :: initialized = .false.
82 integer(longint),
intent(in) :: total_memory
84 this % total_local_memory = total_memory
85 this % available_local_memory = this % total_local_memory
86 this % initialized = .true.
87 this % available_local_memory = this % available_local_memory - this % cached_tracked_memory
101 integer(longint),
intent(in) :: total_memory
103 this % total_local_memory = total_memory
104 this % available_local_memory = this % total_local_memory
105 this % available_local_memory = this % available_local_memory - this % cached_tracked_memory
106 this % initialized = .true.
123 character(len=*),
intent(in) :: array_name
124 integer,
intent(in) :: elem_size,nelem,stat
125 integer(longint) :: total_mem
130 write (stdout,
"('Array : ',a)") array_name
131 write (stdout,
"('stat returned error ',i16,' when trying to allocate nelems ',i16,' of size ', i16)") &
132 stat, nelem, elem_size
134 stop
"[Memory manager] Memory allocation error"
138 total_mem = elem_size * nelem
142 this % cached_tracked_memory = this % cached_tracked_memory + total_mem
143 if (.not. this % initialized)
return
145 this % available_local_memory = this % available_local_memory - total_mem
148 if (this % available_local_memory < 0)
then
149 call this % print_memory_report()
150 write (stdout,
"('Array : ',a)") array_name
151 write (stdout,
"('Overrun allowed memory space when trying to allocate nelems ',i16,' of size ', 2i16,' vs',i16)") &
152 nelem, elem_size, total_mem, this % get_available_memory()
153 stop
"[Memory manager] Overrun space"
168 integer,
intent(in) :: elem_size, nelem
169 integer(longint) :: total_mem
172 total_mem = elem_size * nelem
174 this % cached_tracked_memory = this % cached_tracked_memory - total_mem
176 if (.not. this % initialized)
return
178 this % available_local_memory = this % available_local_memory + total_mem
181 if (this % available_local_memory > this % total_local_memory)
then
182 stop
"Memory mismatch"
215 real(wp),
intent(in) :: scale_
219 s = min(abs(scale_), 1.0_wp)
233 real(wp) :: mem_total, mem_avail, percentage
236 mem_total = real(this % total_local_memory) / real(1024**3)
239 mem_avail = real(this % available_local_memory) / real(1024**3)
242 percentage = mem_avail * 100.0 / mem_total
243 write (stdout,
"('Currently we have ',f18.8,'GB / ',f18.8,'GiB available')") mem_avail, mem_total
244 write (stdout,
"('Memory availability at ',f6.1,'%')") percentage