Octopus
multisystem_debug.F90
Go to the documentation of this file.
1!! Copyright (C) 2021 M. Lueders
2!!
3!! This Source Code Form is subject to the terms of the Mozilla Public
4!! License, v. 2.0. If a copy of the MPL was not distributed with this
5!! file, You can obtain one at https://mozilla.org/MPL/2.0/.
6!!
7
8#include "global.h"
9
18 use debug_oct_m
19 use global_oct_m
20 use io_oct_m
22 use mpi_oct_m
25
26 implicit none
27
28 private
29
30 public &
41
42 integer, parameter, public :: MAX_INFO_LEN = 256
43
44
45 !-------------------------------------------------------------------
46
49 type, abstract :: event_info_t
50 private
51 contains
52 procedure(event_info_get_info), deferred :: get_info
53 end type event_info_t
54
55 abstract interface
56
57 function event_info_get_info(this) result(result)
58 import event_info_t
59 import max_info_len
60 class(event_info_t), intent(in) :: this
61 character(len=MAX_INFO_LEN) :: result
62 end function event_info_get_info
63
64 end interface
65
66 !-------------------------------------------------------------------
67
70 type, extends(event_info_t) :: event_function_call_t
71 private
72 character(len=MAX_INFO_LEN) :: function_name
73 character(len=ALGO_LABEL_LEN) :: op_label
74 contains
75 procedure :: get_info => event_function_call_get_info
77
78 interface event_function_call_t
79 procedure :: event_function_call_constructor
80 end interface event_function_call_t
81
82 !-------------------------------------------------------------------
83
87 private
88 character(len=MAX_INFO_LEN) :: name
89 character(len=MAX_INFO_LEN) :: detail
90 class(iteration_counter_t), allocatable :: iteration
91 character(len=MAX_INFO_LEN) :: action
92 contains
93 procedure :: get_info => event_iteration_update_get_info
95
97 procedure :: event_iteration_update_constructor
98 end interface event_iteration_update_t
99
100 !-------------------------------------------------------------------
101
104 type, extends(event_info_t) :: event_marker_t
105 private
106 character(len=MAX_INFO_LEN) :: text
107 contains
108 procedure :: get_info => event_marker_get_info
109 end type event_marker_t
110
112 procedure :: event_marker_constructor
113 end interface event_marker_t
114
115 !-------------------------------------------------------------------
116
119 type :: event_handle_t
120 private
121 integer, public :: enter_ID
122 end type event_handle_t
123
124 interface event_handle_t
125 procedure :: event_handle_constructor
126 end interface event_handle_t
127
128 !-------------------------------------------------------------------
129
130 type(mpi_grp_t) :: mpi_grp
131 integer iunit
132 integer event_ID
133
134contains
135
136
137 function event_handle_constructor(id) result(handle)
138 integer, intent(in) :: id
139 type(event_handle_t) :: handle
140
142
143 handle%enter_ID = id
146 end function event_handle_constructor
147 !-------------------------------------------------------------------
148
149 function event_function_call_constructor(name, op) result(event)
150 character(*), intent(in) :: name
151 type(algorithmic_operation_t), intent(in), optional :: op
153
155
156 event%function_name = name
157
158 if (present(op)) then
159 event%op_label = op%label
160 else
161 event%op_label = "NULL"
162 end if
163
166
168 function event_function_call_get_info(this) result(info)
169 class(event_function_call_t), intent(in) :: this
170 character(len=MAX_INFO_LEN) :: info
171
173
174 info = "type: function_call | function: " // trim(this%function_name)
175 if (this%op_label /= "NULL") then
176 info = trim(info) // " | operation: " // trim(this%op_label)
177 end if
178
182 !-------------------------------------------------------------------
184 function event_iteration_update_constructor(name, detail, iteration, action) result(event)
185 character(*), intent(in) :: name
186 character(*), intent(in) :: detail
187 class(iteration_counter_t), intent(in) :: iteration
188 character(len=*), intent(in) :: action
189 type(event_iteration_update_t) :: event
190
192
193 event%iteration = iteration
194 event%name = name
195 event%detail = detail
196 event%action = action
197
200
202 function event_iteration_update_get_info(this) result(info)
203 class(event_iteration_update_t), intent(in) :: this
204 character(len=MAX_INFO_LEN) :: info
205
207
208 write(info, '("type: clock_update | clock_name: ",a," | clock_detail: ",a," | clock: ",E15.5," | action: ",a)') &
209 trim(this%name), trim(this%detail), this%iteration%value(), trim(this%action)
210
213
214 !-------------------------------------------------------------------
215
216 function event_marker_constructor(text) result(event)
217 character(*), intent(in) :: text
218 type(event_marker_t) :: event
219
221
222 event%text = text
223
228 function event_marker_get_info(this) result(info)
229 class(event_marker_t), intent(in) :: this
230 character(len=MAX_INFO_LEN) :: info
231
233
234 write(info, '("type: marker | text: ",a)') trim(this%text)
235
237 end function event_marker_get_info
238
239 !-------------------------------------------------------------------
240
241 subroutine multisystem_debug_init(filename, namespace, group)
242 character(*), intent(in) :: filename
243 type(namespace_t), intent(in) :: namespace
244 type(mpi_grp_t), intent(in) :: group
245
246 push_sub(multisystem_debug_init)
247
248 mpi_grp = group
249
250 event_id = 0
251 if (debug%propagation_graph .and. mpi_grp%is_root()) then
252 iunit = io_open(filename, namespace, action="write", status="unknown")
253 end if
254
256 end subroutine multisystem_debug_init
257
258 subroutine multisystem_debug_end()
259
260 push_sub(multisystem_debug_end)
261
262 if (debug%propagation_graph .and. mpi_grp%is_root()) then
263 call io_close(iunit)
264 end if
265
266 pop_sub(multisystem_debug_end)
267 end subroutine multisystem_debug_end
268
269
270 subroutine multisystem_debug_write_marker(system_namespace, event)
271
272 class(namespace_t), intent(in), optional :: system_namespace
273 class(event_info_t), intent(in) :: event
274
275 character(len = MAX_NAMESPACE_LEN) :: system_name
276
278
279 if (debug%propagation_graph .and. mpi_grp%is_root()) then
280
281 if (present(system_namespace)) then
282 system_name = '.'//trim(system_namespace%get())
283 if (system_name == '.') system_name = ''
284 else
285 system_name = 'KEEP'
286 end if
287
288 write(iunit, '("MARKER: ",I10," | system: ",a,"| ",a)' , advance='yes') event_id, &
289 trim(system_name), trim(event%get_info())
290 event_id = event_id + 1
291
292 end if
293
295
296 end subroutine multisystem_debug_write_marker
298 function multisystem_debug_write_event_in(system_namespace, event, extra, system_iteration, algo_iteration, &
299 interaction_iteration, partner_iteration, requested_iteration) result(handle)
300 class(namespace_t), intent(in), optional :: system_namespace
301 class(event_info_t), intent(in) :: event
302 character(*), optional :: extra
303 class(iteration_counter_t), intent(in), optional :: system_iteration
304 class(iteration_counter_t), intent(in), optional :: algo_iteration
305 class(iteration_counter_t), intent(in), optional :: interaction_iteration
306 class(iteration_counter_t), intent(in), optional :: partner_iteration
307 class(iteration_counter_t), intent(in), optional :: requested_iteration
308 type(event_handle_t) :: handle
309
310 character(len = MAX_NAMESPACE_LEN) :: system_name
313
314 if (debug%propagation_graph .and. mpi_grp%is_root()) then
315
316 if (present(system_namespace)) then
317 system_name = '.'//trim(system_namespace%get())
318 if (system_name == '.') system_name = ''
319 else
320 system_name = 'KEEP'
321 end if
322
323 handle = event_handle_t(event_id)
324
325 write(iunit, '("IN step: ",I10," | system: ",a,"| ",a)' , advance='no') event_id, trim(system_name), trim(event%get_info())
326
327 if (present(extra)) then
328 write(iunit, '(" | ",a)' , advance='no') trim(extra)
329 end if
330
331 if (present(system_iteration)) then
332 write(iunit, '(" | system_clock:", E15.5)' , advance='no') system_iteration%value()
333 end if
334
335 if (present(algo_iteration)) then
336 write(iunit, '(" | algo_clock:", E15.5)' , advance='no') algo_iteration%value()
337 end if
338
339 if (present(interaction_iteration)) then
340 write(iunit, '(" | interaction_clock:", E15.5)' , advance='no') interaction_iteration%value()
341 end if
342
343 if (present(partner_iteration)) then
344 write(iunit, '(" | partner_clock:", E15.5)' , advance='no') partner_iteration%value()
345 end if
346
347 if (present(requested_iteration)) then
348 write(iunit, '(" | requested_clock:", E15.5)' , advance='no') requested_iteration%value()
349 end if
350
351 write(iunit, '()' , advance='yes')
352
353 event_id = event_id + 1
354
355 end if
356
359
360 subroutine multisystem_debug_write_event_out(handle, extra, update, system_iteration, algo_iteration, &
361 interaction_iteration, partner_iteration, requested_iteration)
362 class(event_handle_t), intent(in) :: handle
363 character(*), optional :: extra
364 logical, optional :: update
365 class(iteration_counter_t), intent(in), optional :: system_iteration
366 class(iteration_counter_t), intent(in), optional :: algo_iteration
367 class(iteration_counter_t), intent(in), optional :: interaction_iteration
368 class(iteration_counter_t), intent(in), optional :: partner_iteration
369 class(iteration_counter_t), intent(in), optional :: requested_iteration
370
371 character(17) :: update_string
372
374
375 if (debug%propagation_graph .and. mpi_grp%is_root()) then
376
377 if (present(update)) then
378 if (update) then
379 update_string = " | updated: true"
380 else
381 update_string = " | updated: false"
382 end if
383 else
384 update_string = ""
385 end if
386
387 write(iunit, '("OUT step: ",I10," | closes: ",I10)', advance='no') &
388 event_id, handle%enter_ID
389
390 if (present(update)) then
391 if (update) then
392 write(iunit, '(" | updated: true")', advance='no')
393 else
394 write(iunit, '(" | updated: false")', advance='no')
395 end if
396 end if
397
398 if (present(extra)) then
399 write(iunit, '(" | ",a)' , advance='no') trim(extra)
400 end if
401
402 if (present(system_iteration)) then
403 write(iunit, '(" | system_clock:", E15.5)' , advance='no') system_iteration%value()
404 end if
405
406 if (present(algo_iteration)) then
407 write(iunit, '(" | prop_clock:", E15.5)' , advance='no') algo_iteration%value()
408 end if
409
410 if (present(interaction_iteration)) then
411 write(iunit, '(" | interaction_clock:", E15.5)' , advance='no') interaction_iteration%value()
412 end if
413
414 if (present(partner_iteration)) then
415 write(iunit, '(" | partner_clock:", E15.5)' , advance='no') partner_iteration%value()
416 end if
417
418 if (present(requested_iteration)) then
419 write(iunit, '(" | requested_clock:", E15.5)' , advance='no') requested_iteration%value()
420 end if
421
422 write(iunit, '()' , advance='yes')
423
424 event_id = event_id + 1
425
426 end if
427
428
431
subroutine info()
Definition: em_resp.F90:1093
This module implements the basic elements defining algorithms.
Definition: algorithm.F90:143
type(debug_t), save, public debug
Definition: debug.F90:158
Definition: io.F90:116
subroutine, public io_close(iunit, grp)
Definition: io.F90:467
integer function, public io_open(file, namespace, action, status, form, position, die, recl, grp)
Definition: io.F90:402
This module implements the multisystem debug functionality.
type(event_marker_t) function event_marker_constructor(text)
type(event_function_call_t) function event_function_call_constructor(name, op)
character(len=max_info_len) function event_function_call_get_info(this)
subroutine, public multisystem_debug_write_marker(system_namespace, event)
character(len=max_info_len) function event_iteration_update_get_info(this)
type(event_iteration_update_t) function event_iteration_update_constructor(name, detail, iteration, action)
type(event_handle_t) function, public multisystem_debug_write_event_in(system_namespace, event, extra, system_iteration, algo_iteration, interaction_iteration, partner_iteration, requested_iteration)
subroutine, public multisystem_debug_init(filename, namespace, group)
type(event_handle_t) function event_handle_constructor(id)
subroutine, public multisystem_debug_write_event_out(handle, extra, update, system_iteration, algo_iteration, interaction_iteration, partner_iteration, requested_iteration)
character(len=max_info_len) function event_marker_get_info(this)
subroutine, public multisystem_debug_end()
Descriptor of one algorithmic operation.
Definition: algorithm.F90:165
This class implements the iteration counter used by the multisystem algorithms. As any iteration coun...
This is defined even when running serial.
Definition: mpi.F90:144
handle to keep track of in- out- events
abstract class to specify events in the algorithm execution