40 use json_module,
only : json_file
52 character(len=19),
allocatable :: rt_stats_id(:)
58 logical :: output_profile_
74 type(json_file),
intent(inout) :: params
80 this%enabled_, .false.)
82 'case.runtime_statistics.output_profile', &
83 this%output_profile_, .false.)
85 if (this%enabled_)
then
93 call this%elapsed_time_(i)%init()
96 call this%region_timestamp_%init(100)
107 if (
allocated(this%rt_stats_id))
then
108 deallocate(this%rt_stats_id)
111 if (
allocated(this%elapsed_time_))
then
112 do i = 1,
size(this%elapsed_time_)
113 call this%elapsed_time_(i)%free()
115 deallocate(this%elapsed_time_)
118 call this%region_timestamp_%free()
126 character(len=*) :: name
127 integer,
intent(in) :: region_id
130 if (.not. this%enabled_)
then
135 if (len_trim(this%rt_stats_id(region_id)) .eq. 0)
then
136 this%rt_stats_id(region_id) = trim(name)
138 if (trim(this%rt_stats_id(region_id)) .ne. trim(name))
then
139 call neko_error(
'Profile region renamed')
142 region_data%x = region_id
143 region_data%y = mpi_wtime()
144 call this%region_timestamp_%push(region_data)
146 call neko_error(
'Invalid profiling region id')
154 character(len=*) :: name
155 integer,
intent(in) :: region_id
156 real(kind=
dp) :: end_time, elapsed_time
159 if (.not. this%enabled_)
then
163 end_time = mpi_wtime()
165 if (trim(this%rt_stats_id(region_id)) .ne. trim(name))
then
166 call neko_error(
'Invalid profiler region closed (' // name //
', &
167 &expected: ' // trim(this%rt_stats_id(region_id)) //
')')
169 region_data = this%region_timestamp_%pop()
171 if (region_data%x .gt. 0)
then
172 elapsed_time = end_time - region_data%y
173 call this%elapsed_time_(region_data%x)%push(elapsed_time)
181 character(len=LOG_SIZE) :: log_buf
182 character(len=1250) :: hdr
183 real(kind=
dp) :: avg, std, sem, total
184 integer :: i, nsamples, ncols, nrows, col_idx
187 if (.not. this%enabled_)
then
191 call neko_log%section(
'Runtime statistics')
193 write(log_buf,
'(A,A,1x,A,1x,A)')
' ',&
194 ' Total time ',
' Avg. time ',
' Range +/-'
196 write(log_buf,
'(A)') &
197 '--------------------------------------------------------------------'
203 do i = 1,
size(this%elapsed_time_)
204 if (len_trim(this%rt_stats_id(i)) .gt. 0)
then
205 nsamples = this%elapsed_time_(i)%size()
207 hdr = trim(hdr) // trim(this%rt_stats_id(i)) //
', '
208 nrows =
max(nrows, nsamples)
209 if (nsamples .gt. 0)
then
210 select type (region_sample => this%elapsed_time_(i)%data)
211 type is (double precision)
212 total = sum(region_sample(1:nsamples))
213 call mpi_allreduce(mpi_in_place, total, 1, &
214 mpi_double_precision, mpi_sum,
neko_comm)
216 avg = total / nsamples
217 std = (total - avg)**2 / nsamples
218 sem = std /sqrt(
real(nsamples,
dp))
220 write(log_buf,
'(A, E15.7,1x,1x,E15.7,1x,1x,E15.7)') &
221 this%rt_stats_id(i), total, avg, 2.5758_dp * sem
229 if (this%output_profile_)
then
231 call profile_data%init(nrows, ncols)
232 do i = 1,
size(this%elapsed_time_)
233 if (len_trim(this%rt_stats_id(i)) .gt. 0)
then
234 nsamples = this%elapsed_time_(i)%size()
235 col_idx = col_idx + 1
236 if (nsamples .gt. 0)
then
237 select type (region_sample => this%elapsed_time_(i)%data)
238 type is (double precision)
239 profile_data%x(1:nsamples,col_idx) = &
240 region_sample(1:nsamples)
241 call mpi_allreduce(mpi_in_place, &
242 profile_data%x(1:nsamples,col_idx), nsamples, &
243 mpi_double_precision, mpi_sum,
neko_comm)
244 profile_data%x(1:nsamples, col_idx) = &
245 profile_data%x(1:nsamples, col_idx) /
pe_size
253 type(
file_t) :: profile_file
254 profile_file =
file_t(
'profile.csv')
255 call profile_file%set_header(hdr)
256 call profile_file%write(profile_data)
262 call profile_data%free()
Retrieves a parameter by name or assigns a provided default value. In the latter case also adds the m...
Retrieves a parameter by name or throws an error.
type(mpi_comm) neko_comm
MPI communicator.
integer pe_size
MPI size of communicator.
Module for file I/O operations.
Utilities for retrieving parameters from the case files.
type(log_t), public neko_log
Global log stream.
integer, parameter, public log_size
integer, parameter, public dp
subroutine runtime_stats_init(this, params)
Initialise runtime statistics.
subroutine runtime_stats_start_region(this, name, region_id)
Start measuring time for the region named name with id region_id.
subroutine runtime_stats_report(this)
Report runtime statistics for all recorded regions.
subroutine runtime_stats_free(this)
Destroy runtime statistics.
type(runtime_stats_t), public neko_rt_stats
integer rt_stats_max_regions
subroutine runtime_stats_end_region(this, name, region_id)
Compute elapsed time for the current region.
Implements a dynamic stack ADT.
A wrapper around a polymorphic generic_file_t that handles its init. This is essentially a factory fo...
Mixed integer-double precision 2-tuple based stack.
Double precision based stack.
Mixed integer ( ) double precision ( ) 2-tuple .