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()