Merge lp:~nickpapior/siesta/4.0-json-time into lp:~albertog/siesta/4.0-json-time

Proposed by Nick Papior
Status: Merged
Approved by: Alberto Garcia
Approved revision: 559
Merged at revision: 559
Proposed branch: lp:~nickpapior/siesta/4.0-json-time
Merge into: lp:~albertog/siesta/4.0-json-time
Diff against target: 136 lines (+29/-40)
2 files modified
Src/timer_tree.f90 (+28/-39)
version.info (+1/-1)
To merge this branch: bzr merge lp:~nickpapior/siesta/4.0-json-time
Reviewer Review Type Date Requested Status
Alberto Garcia Approve
Review via email: mp+337934@code.launchpad.net

Description of the change

Small changes and removed unnecessary arguments.

These are merely suggestions to remove some of the logic.

I.e. before two (optional) flags where passed, one to decide whether JSON should be written, and another to specify the unit.

It may make more sense to:
If JSON unit is passed, then write. Else, don't write JSON.

Also, used m_io for unit retrieval.

To post a comment you must log in.
Revision history for this message
Alberto Garcia (albertog) wrote :

Approved, but you were too quick about the border cases, and you had extra braces.
We avoid the m_io dependency for now.

review: Approve
Revision history for this message
Nick Papior (nickpapior) wrote :

Ok, thanks for fixing my mistakes.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Src/timer_tree.f90'
2--- Src/timer_tree.f90 2018-02-12 15:41:16 +0000
3+++ Src/timer_tree.f90 2018-02-19 08:20:19 +0000
4@@ -254,11 +254,11 @@
5 !------------------------------------------------
6 subroutine timer_report_global()
7
8+ use m_io, only: io_assign, io_close
9+
10 integer :: i, js_lun
11 type(times_t), pointer :: qd
12
13- logical :: json_output
14-
15 p => global_section
16 ! Assign to the global section the sum of the times
17 ! of its children
18@@ -269,47 +269,46 @@
19 enddo
20 p%data%totTime = globaltime + 1.0e-6_dp
21
22- json_output = .true.
23- call get_unit_number(js_lun)
24- open(unit=js_lun,file="time.json",form="formatted", &
25- action="write",position="rewind")
26+ ! Open JSON
27+ call io_assign(js_lun)
28+ open(unit=js_lun, file="time.json", form="formatted", &
29+ action="write",position="rewind")
30
31 write(*,"(/,a20,T30,a6,a12,a8)") "Section","Calls","Walltime","%"
32
33- write(js_lun,*) '{'
34- call walk_tree(p,0,json=json_output,js_lun=js_lun)
35- write(js_lun,*) '}'
36- if (json_output) close(js_lun)
37+ call walk_tree(p,0, js_lun=js_lun)
38+
39+ call io_close(js_lun)
40
41 end subroutine timer_report_global
42
43 !------------------------------------------------
44- recursive subroutine walk_tree(p,level,maxlevel,json,js_lun)
45+ recursive subroutine walk_tree(p,level,maxlevel,js_lun)
46 type(section_t), intent(in),target :: p
47 integer, intent(in) :: level
48 integer, intent(in), optional:: maxlevel
49- logical, intent(in), optional:: json
50 integer, intent(in), optional:: js_lun
51
52 integer :: i
53- character(len=40) fmtstr, fmt_json, fmt_json_head
54+ character(len=64) fmtstr, fmt_json, fmt_json_head
55 logical :: json_output
56
57- json_output = .false.
58- if (present(json)) then
59- json_output = json
60- if (.not. present(js_lun)) then
61- call die("Need a js_lun for json timer output")
62- endif
63- endif
64+ ! Determine whether we should output JSON
65+ ! If the unit is there, we output to JSON as well
66+ json_output = present(js_lun)
67+
68 if (present(maxlevel)) then
69 if (level > maxlevel) RETURN
70- endif
71+ end if
72+
73+ if ( json_output ) then
74+ write(js_lun,*) '{'
75+ end if
76+
77 pd => p%data
78 write(fmtstr,"(a,i0,a1,a)") "(", level+1, "x", ",a20,T30,i6,f12.3,f8.2)"
79
80- write(*,fmtstr) pd%name, pd%nCalls, &
81- pd%totTime, 100*pd%totTime/globaltime
82+ write(*,fmtstr) pd%name, pd%nCalls, pd%totTime, 100*pd%totTime/globaltime
83 if (json_output) then
84 write(fmt_json,"(a,i0,a1,a)") "(",2*level+1,"x",",a,i0,a,f12.3,a,f8.2)"
85 write(fmt_json_head,"(a,i0,a)") "(", 2*level+1, "x,a)"
86@@ -317,11 +316,11 @@
87 '"' // trim(pd%name) // '": { "_calls": ', pd%nCalls, &
88 ', "_time": ', pd%totTime, &
89 ', "_%": ', 100*pd%totTime/globaltime
90- endif
91+ end if
92 if (p%nchildren /= 0) then
93 if (json_output) write(js_lun,"(a)") ","
94 do i=1,p%nchildren
95- call walk_tree(p%child(i),level+1,maxlevel,json,js_lun)
96+ call walk_tree(p%child(i),level+1,maxlevel, js_lun)
97 if (json_output) then
98 if (i < p%nchildren) then
99 write(js_lun,fmt="(a)") ','
100@@ -336,6 +335,10 @@
101 if (json_output) write(js_lun,fmt="(a)",advance="no") "}"
102 endif
103
104+ if ( json_output ) then
105+ write(js_lun,*) '}'
106+ end if
107+
108 end subroutine walk_tree
109
110 !------------------------------------------------
111@@ -396,18 +399,4 @@
112 endif
113 end subroutine current_time
114
115-subroutine get_unit_number(lun)
116-integer, intent(out) :: lun
117-
118-logical :: used
119-integer :: iostat
120-
121-do lun= 10, 99
122- inquire(unit=lun, opened=used, iostat=iostat)
123- if (iostat .ne. 0) used = .true.
124- if (.not. used) return
125-enddo
126-call die("Cannot get unit for timer output")
127-end subroutine get_unit_number
128-
129 end module m_timer_tree
130
131=== modified file 'version.info'
132--- version.info 2018-02-15 15:45:23 +0000
133+++ version.info 2018-02-19 08:20:19 +0000
134@@ -1,3 +1,3 @@
135-siesta-4.0--555--json-time-3
136+siesta-4.0--555--json-time-3--npa-1
137
138

Subscribers

People subscribed via source and target branches

to all changes: