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
17 use debug_oct_m
18 use global_oct_m
19 use io_oct_m
21 use mpi_oct_m
24
25 implicit none
26
27 private
28
29 public &
40
41 integer, parameter, public :: MAX_INFO_LEN = 256
42
43
44 !-------------------------------------------------------------------
45
48 type, abstract :: event_info_t
49 private
50 contains
51 procedure(event_info_get_info), deferred :: get_info
52 end type event_info_t
53
54 abstract interface
55
56 function event_info_get_info(this) result(result)
57 import event_info_t
58 import max_info_len
59 class(event_info_t), intent(in) :: this
60 character(len=MAX_INFO_LEN) :: result
61 end function event_info_get_info
62
63 end interface
64
65 !-------------------------------------------------------------------
66
69 type, extends(event_info_t) :: event_function_call_t
70 character(len=MAX_INFO_LEN) :: function_name
71 character(len=ALGO_LABEL_LEN) :: op_label
72 contains
73 procedure :: get_info => event_function_call_get_info
75
76 interface event_function_call_t
77 procedure :: event_function_call_constructor
78 end interface event_function_call_t
79
80 !-------------------------------------------------------------------
81
85 character(len=MAX_INFO_LEN) :: name
86 character(len=MAX_INFO_LEN) :: detail
87 class(iteration_counter_t), allocatable :: iteration
88 character(len=MAX_INFO_LEN) :: action
89 contains
90 procedure :: get_info => event_iteration_update_get_info
92
94 procedure :: event_iteration_update_constructor
95 end interface event_iteration_update_t
96
97 !-------------------------------------------------------------------
98
101 type, extends(event_info_t) :: event_marker_t
102 character(len=MAX_INFO_LEN) :: text
103 contains
104 procedure :: get_info => event_marker_get_info
105 end type event_marker_t
106
107 interface event_marker_t
108 procedure :: event_marker_constructor
109 end interface event_marker_t
110
111 !-------------------------------------------------------------------
112
115 type :: event_handle_t
116 integer, public :: enter_ID
117 end type event_handle_t
118
119 interface event_handle_t
120 procedure :: event_handle_constructor
121 end interface event_handle_t
122
123 !-------------------------------------------------------------------
124
126 integer iunit
127 integer event_id
128
129contains
130
131
132 function event_handle_constructor(id) result(handle)
133 integer, intent(in) :: id
134 type(event_handle_t) :: handle
137
138 handle%enter_ID = id
139
141 end function event_handle_constructor
142 !-------------------------------------------------------------------
143
144 function event_function_call_constructor(name, op) result(event)
145 character(*), intent(in) :: name
146 type(algorithmic_operation_t), intent(in), optional :: op
147 type(event_function_call_t) :: event
148
150
151 event%function_name = name
152
153 if (present(op)) then
154 event%op_label = op%label
155 else
156 event%op_label = "NULL"
157 end if
158
161
162
163 function event_function_call_get_info(this) result(info)
164 class(event_function_call_t), intent(in) :: this
165 character(len=MAX_INFO_LEN) :: info
166
169 info = "type: function_call | function: " // trim(this%function_name)
170 if (this%op_label /= "NULL") then
171 info = trim(info) // " | operation: " // trim(this%op_label)
172 end if
173
176
177 !-------------------------------------------------------------------
178
179 function event_iteration_update_constructor(name, detail, iteration, action) result(event)
180 character(*), intent(in) :: name
181 character(*), intent(in) :: detail
182 class(iteration_counter_t), intent(in) :: iteration
183 character(len=*), intent(in) :: action
184 type(event_iteration_update_t) :: event
187
188 event%iteration = iteration
189 event%name = name
190 event%detail = detail
191 event%action = action
192
195
196
197 function event_iteration_update_get_info(this) result(info)
198 class(event_iteration_update_t), intent(in) :: this
199 character(len=MAX_INFO_LEN) :: info
202
203 write(info, '("type: clock_update | clock_name: ",a," | clock_detail: ",a," | clock: ",E15.5," | action: ",a)') &
204 trim(this%name), trim(this%detail), this%iteration%value(), trim(this%action)
205
208
209 !-------------------------------------------------------------------
211 function event_marker_constructor(text) result(event)
212 character(*), intent(in) :: text
213 type(event_marker_t) :: event
214
217 event%text = text
218
220 end function event_marker_constructor
221
222
223 function event_marker_get_info(this) result(info)
224 class(event_marker_t), intent(in) :: this
225 character(len=MAX_INFO_LEN) :: info
226
229 write(info, '("type: marker | text: ",a)') trim(this%text)
230
232 end function event_marker_get_info
233
234 !-------------------------------------------------------------------
235
236 subroutine multisystem_debug_init(filename, namespace, group)
237 character(*), intent(in) :: filename
238 type(namespace_t), intent(in) :: namespace
239 type(mpi_grp_t), intent(in) :: group
240
241 push_sub(multisystem_debug_init)
242
243 mpi_grp = group
244
245 event_id = 0
246 if (debug%propagation_graph .and. mpi_grp%rank == 0) then
247 iunit = io_open(filename, namespace, action="write", status="unknown")
248 end if
249
251 end subroutine multisystem_debug_init
252
253 subroutine multisystem_debug_end()
254
255 push_sub(multisystem_debug_end)
256
257 if (debug%propagation_graph .and. mpi_grp%rank == 0) then
258 call io_close(iunit)
259 end if
260
261 pop_sub(multisystem_debug_end)
262 end subroutine multisystem_debug_end
264
265 subroutine multisystem_debug_write_marker(system_namespace, event)
266
267 class(namespace_t), intent(in), optional :: system_namespace
268 class(event_info_t), intent(in) :: event
269
270 character(len = MAX_NAMESPACE_LEN) :: system_name
271
273
274 if (debug%propagation_graph .and. mpi_grp%rank == 0) then
275
276 if (present(system_namespace)) then
277 system_name = '.'//trim(system_namespace%get())
278 if (system_name == '.') system_name = ''
279 else
280 system_name = 'KEEP'
281 end if
282
283 write(iunit, '("MARKER: ",I10," | system: ",a,"| ",a)' , advance='yes') event_id, &
284 trim(system_name), trim(event%get_info())
285 event_id = event_id + 1
286
287 end if
288
290
291 end subroutine multisystem_debug_write_marker
292
293 function multisystem_debug_write_event_in(system_namespace, event, extra, system_iteration, algo_iteration, &
294 interaction_iteration, partner_iteration, requested_iteration) result(handle)
295 class(namespace_t), intent(in), optional :: system_namespace
296 class(event_info_t), intent(in) :: event
297 character(*), optional :: extra
298 class(iteration_counter_t), intent(in), optional :: system_iteration
299 class(iteration_counter_t), intent(in), optional :: algo_iteration
300 class(iteration_counter_t), intent(in), optional :: interaction_iteration
301 class(iteration_counter_t), intent(in), optional :: partner_iteration
302 class(iteration_counter_t), intent(in), optional :: requested_iteration
303 type(event_handle_t) :: handle
304
305 character(len = MAX_NAMESPACE_LEN) :: system_name
306
308
309 if (debug%propagation_graph .and. mpi_grp%rank == 0) then
310
311 if (present(system_namespace)) then
312 system_name = '.'//trim(system_namespace%get())
313 if (system_name == '.') system_name = ''
314 else
315 system_name = 'KEEP'
316 end if
317
318 handle = event_handle_t(event_id)
319
320 write(iunit, '("IN step: ",I10," | system: ",a,"| ",a)' , advance='no') event_id, trim(system_name), trim(event%get_info())
321
322 if (present(extra)) then
323 write(iunit, '(" | ",a)' , advance='no') trim(extra)
324 end if
325
326 if (present(system_iteration)) then
327 write(iunit, '(" | system_clock:", E15.5)' , advance='no') system_iteration%value()
328 end if
329
330 if (present(algo_iteration)) then
331 write(iunit, '(" | prop_clock:", E15.5)' , advance='no') algo_iteration%value()
332 end if
333
334 if (present(interaction_iteration)) then
335 write(iunit, '(" | interaction_clock:", E15.5)' , advance='no') interaction_iteration%value()
336 end if
338 if (present(partner_iteration)) then
339 write(iunit, '(" | partner_clock:", E15.5)' , advance='no') partner_iteration%value()
340 end if
341
342 if (present(requested_iteration)) then
343 write(iunit, '(" | requested_clock:", E15.5)' , advance='no') requested_iteration%value()
344 end if
345
346 write(iunit, '()' , advance='yes')
347
348 event_id = event_id + 1
350 end if
351
354
355 subroutine multisystem_debug_write_event_out(handle, extra, update, system_iteration, algo_iteration, &
356 interaction_iteration, partner_iteration, requested_iteration)
357 class(event_handle_t), intent(in) :: handle
358 character(*), optional :: extra
359 logical, optional :: update
360 class(iteration_counter_t), intent(in), optional :: system_iteration
361 class(iteration_counter_t), intent(in), optional :: algo_iteration
362 class(iteration_counter_t), intent(in), optional :: interaction_iteration
363 class(iteration_counter_t), intent(in), optional :: partner_iteration
364 class(iteration_counter_t), intent(in), optional :: requested_iteration
365
366 character(17) :: update_string
367
369
370 if (debug%propagation_graph .and. mpi_grp%rank == 0) then
371
372 if (present(update)) then
373 if (update) then
374 update_string = " | updated: true"
375 else
376 update_string = " | updated: false"
377 end if
378 else
379 update_string = ""
380 end if
381
382 write(iunit, '("OUT step: ",I10," | closes: ",I10)', advance='no') &
383 event_id, handle%enter_ID
384
385 if (present(update)) then
386 if (update) then
387 write(iunit, '(" | updated: true")', advance='no')
388 else
389 write(iunit, '(" | updated: false")', advance='no')
390 end if
391 end if
392
393 if (present(extra)) then
394 write(iunit, '(" | ",a)' , advance='no') trim(extra)
395 end if
396
397 if (present(system_iteration)) then
398 write(iunit, '(" | system_clock:", E15.5)' , advance='no') system_iteration%value()
399 end if
400
401 if (present(algo_iteration)) then
402 write(iunit, '(" | prop_clock:", E15.5)' , advance='no') algo_iteration%value()
403 end if
404
405 if (present(interaction_iteration)) then
406 write(iunit, '(" | interaction_clock:", E15.5)' , advance='no') interaction_iteration%value()
407 end if
408
409 if (present(partner_iteration)) then
410 write(iunit, '(" | partner_clock:", E15.5)' , advance='no') partner_iteration%value()
411 end if
412
413 if (present(requested_iteration)) then
414 write(iunit, '(" | requested_clock:", E15.5)' , advance='no') requested_iteration%value()
415 end if
416
417 write(iunit, '()' , advance='yes')
418
419 event_id = event_id + 1
420
421 end if
422
423
426
subroutine info()
Definition: em_resp.F90:1087
This module implements the basic elements defining algorithms.
Definition: algorithm.F90:132
type(debug_t), save, public debug
Definition: debug.F90:142
Definition: io.F90:105
subroutine, public io_close(iunit, grp)
Definition: io.F90:459
integer function, public io_open(file, namespace, action, status, form, position, die, recl, grp)
Definition: io.F90:386
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:154
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:132
handle to keep track of in- out- events
abstract class to specify events in the algorithm execution