1 | !> @file src/control.f90 |
---|
2 | !------------------------------------------------------------------------------! |
---|
3 | ! This file is part of the PALM model system. |
---|
4 | ! |
---|
5 | ! PALM is free software: you can redistribute it and/or modify it under the |
---|
6 | ! terms of the GNU General Public License as published by the Free Software |
---|
7 | ! Foundation, either version 3 of the License, or (at your option) any later |
---|
8 | ! version. |
---|
9 | ! |
---|
10 | ! PALM is distributed in the hope that it will be useful, but WITHOUT ANY |
---|
11 | ! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
---|
12 | ! A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
---|
13 | ! |
---|
14 | ! You should have received a copy of the GNU General Public License along with |
---|
15 | ! PALM. If not, see <http://www.gnu.org/licenses/>. |
---|
16 | ! |
---|
17 | ! Copyright 2017-2018 Leibniz Universitaet Hannover |
---|
18 | ! Copyright 2017-2018 Deutscher Wetterdienst Offenbach |
---|
19 | !------------------------------------------------------------------------------! |
---|
20 | ! |
---|
21 | ! Current revisions: |
---|
22 | ! ----------------- |
---|
23 | ! |
---|
24 | ! |
---|
25 | ! Former revisions: |
---|
26 | ! ----------------- |
---|
27 | ! $Id: control.f90 3183 2018-07-27 14:25:55Z knoop $ |
---|
28 | ! Added version and copyright output |
---|
29 | ! |
---|
30 | ! |
---|
31 | ! 3182 2018-07-27 13:36:03Z suehring |
---|
32 | ! Initial revision |
---|
33 | ! |
---|
34 | ! |
---|
35 | ! |
---|
36 | ! Authors: |
---|
37 | ! -------- |
---|
38 | ! @author Eckhard Kadasch |
---|
39 | ! |
---|
40 | ! Description: |
---|
41 | ! ------------ |
---|
42 | !> The control module provides routines for timing INIFOR and writing runtime |
---|
43 | !> feedback to the terminal and a log file. |
---|
44 | !------------------------------------------------------------------------------! |
---|
45 | MODULE control |
---|
46 | |
---|
47 | USE defs, & |
---|
48 | ONLY: LNAME, dp, VERSION, COPYRIGHT |
---|
49 | |
---|
50 | USE util, & |
---|
51 | ONLY: real_to_str, real_to_str_f |
---|
52 | |
---|
53 | IMPLICIT NONE |
---|
54 | |
---|
55 | CHARACTER (LEN=5000) :: message = '' |
---|
56 | |
---|
57 | CONTAINS |
---|
58 | |
---|
59 | SUBROUTINE report(routine, message) |
---|
60 | |
---|
61 | CHARACTER(LEN=*), INTENT(IN) :: routine |
---|
62 | CHARACTER(LEN=*), INTENT(IN) :: message |
---|
63 | INTEGER :: u |
---|
64 | LOGICAL, SAVE :: is_first_run = .TRUE. |
---|
65 | |
---|
66 | PRINT *, "inifor: " // TRIM(message) // " [ " // TRIM(routine) // " ]" |
---|
67 | |
---|
68 | IF (is_first_run) THEN |
---|
69 | OPEN( NEWUNIT=u, FILE='inifor.log', STATUS='replace' ) |
---|
70 | is_first_run = .FALSE. |
---|
71 | ELSE |
---|
72 | OPEN( NEWUNIT=u, FILE='inifor.log', POSITION='append', STATUS='old' ) |
---|
73 | END IF |
---|
74 | |
---|
75 | WRITE(u, *) TRIM(message) // " [ " // TRIM(routine) // " ]" |
---|
76 | |
---|
77 | CLOSE(u) |
---|
78 | |
---|
79 | END SUBROUTINE report |
---|
80 | |
---|
81 | |
---|
82 | SUBROUTINE warn(routine, message) |
---|
83 | |
---|
84 | CHARACTER(LEN=*), INTENT(IN) :: routine |
---|
85 | CHARACTER(LEN=*), INTENT(IN) :: message |
---|
86 | |
---|
87 | CALL report(routine, "WARNING: " // TRIM(message)) |
---|
88 | |
---|
89 | END SUBROUTINE warn |
---|
90 | |
---|
91 | |
---|
92 | SUBROUTINE abort(routine, message) |
---|
93 | |
---|
94 | CHARACTER(LEN=*), INTENT(IN) :: routine |
---|
95 | CHARACTER(LEN=*), INTENT(IN) :: message |
---|
96 | |
---|
97 | CALL report(routine, "ERROR: " // TRIM(message) // " Stopping.") |
---|
98 | STOP |
---|
99 | |
---|
100 | END SUBROUTINE abort |
---|
101 | |
---|
102 | |
---|
103 | SUBROUTINE print_version() |
---|
104 | PRINT *, "INIFOR " // VERSION |
---|
105 | PRINT *, COPYRIGHT |
---|
106 | END SUBROUTINE print_version |
---|
107 | |
---|
108 | |
---|
109 | SUBROUTINE run_control(mode, budget) |
---|
110 | |
---|
111 | CHARACTER(LEN=*), INTENT(IN) :: mode, budget |
---|
112 | REAL(dp), SAVE :: t0, t1 |
---|
113 | REAL(dp), SAVE :: t_comp=0.0_dp, & |
---|
114 | t_alloc=0.0_dp, & |
---|
115 | t_init=0.0_dp, & |
---|
116 | t_read=0.0_dp, & |
---|
117 | t_total=0.0_dp, & |
---|
118 | t_write=0.0_dp |
---|
119 | CHARACTER(LEN=*), PARAMETER :: fmt='(F6.2)' |
---|
120 | |
---|
121 | |
---|
122 | SELECT CASE(TRIM(mode)) |
---|
123 | |
---|
124 | CASE('init') |
---|
125 | CALL CPU_TIME(t0) |
---|
126 | |
---|
127 | CASE('time') |
---|
128 | |
---|
129 | CALL CPU_TIME(t1) |
---|
130 | |
---|
131 | SELECT CASE(TRIM(budget)) |
---|
132 | |
---|
133 | CASE('alloc') |
---|
134 | t_alloc = t_alloc + t1 - t0 |
---|
135 | |
---|
136 | CASE('init') |
---|
137 | t_init = t_init + t1 - t0 |
---|
138 | |
---|
139 | CASE('read') |
---|
140 | t_read = t_read + t1 - t0 |
---|
141 | |
---|
142 | CASE('write') |
---|
143 | t_write = t_write + t1 - t0 |
---|
144 | |
---|
145 | CASE('comp') |
---|
146 | t_comp = t_comp + t1 - t0 |
---|
147 | |
---|
148 | CASE DEFAULT |
---|
149 | CALL abort('run_control', "Time Budget '" // TRIM(mode) // "' is not supported.") |
---|
150 | |
---|
151 | END SELECT |
---|
152 | |
---|
153 | t0 = t1 |
---|
154 | |
---|
155 | CASE('report') |
---|
156 | t_total = t_init + t_read + t_write + t_comp |
---|
157 | |
---|
158 | CALL report('run_control', " *** CPU time ***") |
---|
159 | |
---|
160 | CALL report('run_control', "Initialization: " // real_to_str(t_init) // & |
---|
161 | " s (" // TRIM(real_to_str(100*t_init/t_total, fmt)) // " %)") |
---|
162 | |
---|
163 | CALL report('run_control', "(De-)Allocation:" // real_to_str(t_alloc) // & |
---|
164 | " s (" // TRIM(real_to_str(100*t_alloc/t_total, fmt)) // " %)") |
---|
165 | |
---|
166 | CALL report('run_control', "Reading data: " // real_to_str(t_read) // & |
---|
167 | " s (" // TRIM(real_to_str(100*t_read/t_total, fmt)) // " %)") |
---|
168 | |
---|
169 | CALL report('run_control', "Writing data: " // real_to_str(t_write) // & |
---|
170 | " s (" // TRIM(real_to_str(100*t_write/t_total, fmt)) // " %)") |
---|
171 | |
---|
172 | CALL report('run_control', "Computation: " // real_to_str(t_comp) // & |
---|
173 | " s (" // TRIM(real_to_str(100*t_comp/t_total, fmt)) // " %)") |
---|
174 | |
---|
175 | CALL report('run_control', "Total: " // real_to_str(t_total) // & |
---|
176 | " s (" // TRIM(real_to_str(100*t_total/t_total, fmt)) // " %)") |
---|
177 | |
---|
178 | CASE DEFAULT |
---|
179 | CALL abort('run_control', "Mode '" // TRIM(mode) // "' is not supported.") |
---|
180 | |
---|
181 | END SELECT |
---|
182 | |
---|
183 | END SUBROUTINE run_control |
---|
184 | |
---|
185 | END MODULE |
---|
186 | |
---|