[2696] | 1 | !> @file src/control.f90 |
---|
| 2 | !------------------------------------------------------------------------------! |
---|
[2718] | 3 | ! This file is part of the PALM model system. |
---|
[2696] | 4 | ! |
---|
[2718] | 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 |
---|
[2696] | 8 | ! version. |
---|
| 9 | ! |
---|
[2718] | 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. |
---|
[2696] | 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 | ! |
---|
[2718] | 17 | ! Copyright 2017-2018 Leibniz Universitaet Hannover |
---|
| 18 | ! Copyright 2017-2018 Deutscher Wetterdienst Offenbach |
---|
[2696] | 19 | !------------------------------------------------------------------------------! |
---|
| 20 | ! |
---|
| 21 | ! Current revisions: |
---|
| 22 | ! ----------------- |
---|
| 23 | ! |
---|
| 24 | ! |
---|
| 25 | ! Former revisions: |
---|
| 26 | ! ----------------- |
---|
| 27 | ! $Id: control.f90 3395 2018-10-22 17:32:49Z gronemeier $ |
---|
[3395] | 28 | ! Suppress debugging messages unless --debug option is given |
---|
| 29 | ! |
---|
| 30 | ! |
---|
| 31 | ! 3183 2018-07-27 14:25:55Z suehring |
---|
[3183] | 32 | ! Added version and copyright output |
---|
| 33 | ! |
---|
| 34 | ! |
---|
| 35 | ! 3182 2018-07-27 13:36:03Z suehring |
---|
[2696] | 36 | ! Initial revision |
---|
| 37 | ! |
---|
| 38 | ! |
---|
| 39 | ! |
---|
| 40 | ! Authors: |
---|
| 41 | ! -------- |
---|
| 42 | ! @author Eckhard Kadasch |
---|
| 43 | ! |
---|
| 44 | ! Description: |
---|
| 45 | ! ------------ |
---|
| 46 | !> The control module provides routines for timing INIFOR and writing runtime |
---|
| 47 | !> feedback to the terminal and a log file. |
---|
| 48 | !------------------------------------------------------------------------------! |
---|
| 49 | MODULE control |
---|
| 50 | |
---|
| 51 | USE defs, & |
---|
[3182] | 52 | ONLY: LNAME, dp, VERSION, COPYRIGHT |
---|
[2696] | 53 | |
---|
| 54 | USE util, & |
---|
| 55 | ONLY: real_to_str, real_to_str_f |
---|
| 56 | |
---|
| 57 | IMPLICIT NONE |
---|
| 58 | |
---|
| 59 | CHARACTER (LEN=5000) :: message = '' |
---|
| 60 | |
---|
| 61 | CONTAINS |
---|
| 62 | |
---|
[3395] | 63 | SUBROUTINE report(routine, message, debug) |
---|
[2696] | 64 | |
---|
[3395] | 65 | CHARACTER(LEN=*), INTENT(IN) :: routine |
---|
| 66 | CHARACTER(LEN=*), INTENT(IN) :: message |
---|
| 67 | LOGICAL, OPTIONAL, INTENT(IN) :: debug |
---|
| 68 | INTEGER :: u |
---|
| 69 | LOGICAL, SAVE :: is_first_run = .TRUE. |
---|
| 70 | LOGICAL :: suppress_message |
---|
[2696] | 71 | |
---|
| 72 | |
---|
| 73 | IF (is_first_run) THEN |
---|
| 74 | OPEN( NEWUNIT=u, FILE='inifor.log', STATUS='replace' ) |
---|
| 75 | is_first_run = .FALSE. |
---|
| 76 | ELSE |
---|
| 77 | OPEN( NEWUNIT=u, FILE='inifor.log', POSITION='append', STATUS='old' ) |
---|
| 78 | END IF |
---|
| 79 | |
---|
| 80 | |
---|
[3395] | 81 | suppress_message = .FALSE. |
---|
| 82 | IF (PRESENT(debug)) THEN |
---|
| 83 | IF (.NOT. debug) suppress_message = .TRUE. |
---|
| 84 | END IF |
---|
| 85 | |
---|
| 86 | IF (.NOT. suppress_message) THEN |
---|
| 87 | PRINT *, "inifor: " // TRIM(message) // " [ " // TRIM(routine) // " ]" |
---|
| 88 | WRITE(u, *) TRIM(message) // " [ " // TRIM(routine) // " ]" |
---|
| 89 | END IF |
---|
| 90 | |
---|
[2696] | 91 | CLOSE(u) |
---|
| 92 | |
---|
| 93 | END SUBROUTINE report |
---|
| 94 | |
---|
| 95 | |
---|
| 96 | SUBROUTINE warn(routine, message) |
---|
| 97 | |
---|
| 98 | CHARACTER(LEN=*), INTENT(IN) :: routine |
---|
| 99 | CHARACTER(LEN=*), INTENT(IN) :: message |
---|
| 100 | |
---|
| 101 | CALL report(routine, "WARNING: " // TRIM(message)) |
---|
| 102 | |
---|
| 103 | END SUBROUTINE warn |
---|
| 104 | |
---|
| 105 | |
---|
| 106 | SUBROUTINE abort(routine, message) |
---|
| 107 | |
---|
| 108 | CHARACTER(LEN=*), INTENT(IN) :: routine |
---|
| 109 | CHARACTER(LEN=*), INTENT(IN) :: message |
---|
| 110 | |
---|
| 111 | CALL report(routine, "ERROR: " // TRIM(message) // " Stopping.") |
---|
| 112 | STOP |
---|
| 113 | |
---|
| 114 | END SUBROUTINE abort |
---|
| 115 | |
---|
| 116 | |
---|
[3182] | 117 | SUBROUTINE print_version() |
---|
| 118 | PRINT *, "INIFOR " // VERSION |
---|
| 119 | PRINT *, COPYRIGHT |
---|
| 120 | END SUBROUTINE print_version |
---|
| 121 | |
---|
| 122 | |
---|
[2696] | 123 | SUBROUTINE run_control(mode, budget) |
---|
| 124 | |
---|
| 125 | CHARACTER(LEN=*), INTENT(IN) :: mode, budget |
---|
| 126 | REAL(dp), SAVE :: t0, t1 |
---|
| 127 | REAL(dp), SAVE :: t_comp=0.0_dp, & |
---|
| 128 | t_alloc=0.0_dp, & |
---|
| 129 | t_init=0.0_dp, & |
---|
| 130 | t_read=0.0_dp, & |
---|
| 131 | t_total=0.0_dp, & |
---|
| 132 | t_write=0.0_dp |
---|
| 133 | CHARACTER(LEN=*), PARAMETER :: fmt='(F6.2)' |
---|
| 134 | |
---|
| 135 | |
---|
| 136 | SELECT CASE(TRIM(mode)) |
---|
| 137 | |
---|
| 138 | CASE('init') |
---|
| 139 | CALL CPU_TIME(t0) |
---|
| 140 | |
---|
| 141 | CASE('time') |
---|
| 142 | |
---|
| 143 | CALL CPU_TIME(t1) |
---|
| 144 | |
---|
| 145 | SELECT CASE(TRIM(budget)) |
---|
| 146 | |
---|
| 147 | CASE('alloc') |
---|
| 148 | t_alloc = t_alloc + t1 - t0 |
---|
| 149 | |
---|
| 150 | CASE('init') |
---|
| 151 | t_init = t_init + t1 - t0 |
---|
| 152 | |
---|
| 153 | CASE('read') |
---|
| 154 | t_read = t_read + t1 - t0 |
---|
| 155 | |
---|
| 156 | CASE('write') |
---|
| 157 | t_write = t_write + t1 - t0 |
---|
| 158 | |
---|
| 159 | CASE('comp') |
---|
| 160 | t_comp = t_comp + t1 - t0 |
---|
| 161 | |
---|
| 162 | CASE DEFAULT |
---|
| 163 | CALL abort('run_control', "Time Budget '" // TRIM(mode) // "' is not supported.") |
---|
| 164 | |
---|
| 165 | END SELECT |
---|
| 166 | |
---|
| 167 | t0 = t1 |
---|
| 168 | |
---|
| 169 | CASE('report') |
---|
| 170 | t_total = t_init + t_read + t_write + t_comp |
---|
| 171 | |
---|
| 172 | CALL report('run_control', " *** CPU time ***") |
---|
| 173 | |
---|
| 174 | CALL report('run_control', "Initialization: " // real_to_str(t_init) // & |
---|
| 175 | " s (" // TRIM(real_to_str(100*t_init/t_total, fmt)) // " %)") |
---|
| 176 | |
---|
| 177 | CALL report('run_control', "(De-)Allocation:" // real_to_str(t_alloc) // & |
---|
| 178 | " s (" // TRIM(real_to_str(100*t_alloc/t_total, fmt)) // " %)") |
---|
| 179 | |
---|
| 180 | CALL report('run_control', "Reading data: " // real_to_str(t_read) // & |
---|
| 181 | " s (" // TRIM(real_to_str(100*t_read/t_total, fmt)) // " %)") |
---|
| 182 | |
---|
| 183 | CALL report('run_control', "Writing data: " // real_to_str(t_write) // & |
---|
| 184 | " s (" // TRIM(real_to_str(100*t_write/t_total, fmt)) // " %)") |
---|
| 185 | |
---|
| 186 | CALL report('run_control', "Computation: " // real_to_str(t_comp) // & |
---|
| 187 | " s (" // TRIM(real_to_str(100*t_comp/t_total, fmt)) // " %)") |
---|
| 188 | |
---|
| 189 | CALL report('run_control', "Total: " // real_to_str(t_total) // & |
---|
| 190 | " s (" // TRIM(real_to_str(100*t_total/t_total, fmt)) // " %)") |
---|
| 191 | |
---|
| 192 | CASE DEFAULT |
---|
| 193 | CALL abort('run_control', "Mode '" // TRIM(mode) // "' is not supported.") |
---|
| 194 | |
---|
| 195 | END SELECT |
---|
| 196 | |
---|
| 197 | END SUBROUTINE run_control |
---|
| 198 | |
---|
| 199 | END MODULE |
---|
| 200 | |
---|