[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 2718 2018-01-02 08:49:38Z hellstea $ |
---|
| 28 | ! Initial revision |
---|
| 29 | ! |
---|
| 30 | ! |
---|
| 31 | ! |
---|
| 32 | ! Authors: |
---|
| 33 | ! -------- |
---|
| 34 | ! @author Eckhard Kadasch |
---|
| 35 | ! |
---|
| 36 | ! Description: |
---|
| 37 | ! ------------ |
---|
| 38 | !> The control module provides routines for timing INIFOR and writing runtime |
---|
| 39 | !> feedback to the terminal and a log file. |
---|
| 40 | !------------------------------------------------------------------------------! |
---|
| 41 | MODULE control |
---|
| 42 | |
---|
| 43 | USE defs, & |
---|
| 44 | ONLY: LNAME, dp |
---|
| 45 | |
---|
| 46 | USE util, & |
---|
| 47 | ONLY: real_to_str, real_to_str_f |
---|
| 48 | |
---|
| 49 | IMPLICIT NONE |
---|
| 50 | |
---|
| 51 | CHARACTER (LEN=5000) :: message = '' |
---|
| 52 | |
---|
| 53 | CONTAINS |
---|
| 54 | |
---|
| 55 | SUBROUTINE report(routine, message) |
---|
| 56 | |
---|
| 57 | CHARACTER(LEN=*), INTENT(IN) :: routine |
---|
| 58 | CHARACTER(LEN=*), INTENT(IN) :: message |
---|
| 59 | INTEGER :: u |
---|
| 60 | LOGICAL, SAVE :: is_first_run = .TRUE. |
---|
| 61 | |
---|
| 62 | PRINT *, "inifor: " // TRIM(message) // " [ " // TRIM(routine) // " ]" |
---|
| 63 | |
---|
| 64 | IF (is_first_run) THEN |
---|
| 65 | OPEN( NEWUNIT=u, FILE='inifor.log', STATUS='replace' ) |
---|
| 66 | is_first_run = .FALSE. |
---|
| 67 | ELSE |
---|
| 68 | OPEN( NEWUNIT=u, FILE='inifor.log', POSITION='append', STATUS='old' ) |
---|
| 69 | END IF |
---|
| 70 | |
---|
| 71 | WRITE(u, *) TRIM(message) // " [ " // TRIM(routine) // " ]" |
---|
| 72 | |
---|
| 73 | CLOSE(u) |
---|
| 74 | |
---|
| 75 | END SUBROUTINE report |
---|
| 76 | |
---|
| 77 | |
---|
| 78 | SUBROUTINE warn(routine, message) |
---|
| 79 | |
---|
| 80 | CHARACTER(LEN=*), INTENT(IN) :: routine |
---|
| 81 | CHARACTER(LEN=*), INTENT(IN) :: message |
---|
| 82 | |
---|
| 83 | CALL report(routine, "WARNING: " // TRIM(message)) |
---|
| 84 | |
---|
| 85 | END SUBROUTINE warn |
---|
| 86 | |
---|
| 87 | |
---|
| 88 | SUBROUTINE abort(routine, message) |
---|
| 89 | |
---|
| 90 | CHARACTER(LEN=*), INTENT(IN) :: routine |
---|
| 91 | CHARACTER(LEN=*), INTENT(IN) :: message |
---|
| 92 | |
---|
| 93 | CALL report(routine, "ERROR: " // TRIM(message) // " Stopping.") |
---|
| 94 | STOP |
---|
| 95 | |
---|
| 96 | END SUBROUTINE abort |
---|
| 97 | |
---|
| 98 | |
---|
| 99 | SUBROUTINE run_control(mode, budget) |
---|
| 100 | |
---|
| 101 | CHARACTER(LEN=*), INTENT(IN) :: mode, budget |
---|
| 102 | REAL(dp), SAVE :: t0, t1 |
---|
| 103 | REAL(dp), SAVE :: t_comp=0.0_dp, & |
---|
| 104 | t_alloc=0.0_dp, & |
---|
| 105 | t_init=0.0_dp, & |
---|
| 106 | t_read=0.0_dp, & |
---|
| 107 | t_total=0.0_dp, & |
---|
| 108 | t_write=0.0_dp |
---|
| 109 | CHARACTER(LEN=*), PARAMETER :: fmt='(F6.2)' |
---|
| 110 | |
---|
| 111 | |
---|
| 112 | SELECT CASE(TRIM(mode)) |
---|
| 113 | |
---|
| 114 | CASE('init') |
---|
| 115 | CALL CPU_TIME(t0) |
---|
| 116 | |
---|
| 117 | CASE('time') |
---|
| 118 | |
---|
| 119 | CALL CPU_TIME(t1) |
---|
| 120 | |
---|
| 121 | SELECT CASE(TRIM(budget)) |
---|
| 122 | |
---|
| 123 | CASE('alloc') |
---|
| 124 | t_alloc = t_alloc + t1 - t0 |
---|
| 125 | |
---|
| 126 | CASE('init') |
---|
| 127 | t_init = t_init + t1 - t0 |
---|
| 128 | |
---|
| 129 | CASE('read') |
---|
| 130 | t_read = t_read + t1 - t0 |
---|
| 131 | |
---|
| 132 | CASE('write') |
---|
| 133 | t_write = t_write + t1 - t0 |
---|
| 134 | |
---|
| 135 | CASE('comp') |
---|
| 136 | t_comp = t_comp + t1 - t0 |
---|
| 137 | |
---|
| 138 | CASE DEFAULT |
---|
| 139 | CALL abort('run_control', "Time Budget '" // TRIM(mode) // "' is not supported.") |
---|
| 140 | |
---|
| 141 | END SELECT |
---|
| 142 | |
---|
| 143 | t0 = t1 |
---|
| 144 | |
---|
| 145 | CASE('report') |
---|
| 146 | t_total = t_init + t_read + t_write + t_comp |
---|
| 147 | |
---|
| 148 | CALL report('run_control', " *** CPU time ***") |
---|
| 149 | |
---|
| 150 | CALL report('run_control', "Initialization: " // real_to_str(t_init) // & |
---|
| 151 | " s (" // TRIM(real_to_str(100*t_init/t_total, fmt)) // " %)") |
---|
| 152 | |
---|
| 153 | CALL report('run_control', "(De-)Allocation:" // real_to_str(t_alloc) // & |
---|
| 154 | " s (" // TRIM(real_to_str(100*t_alloc/t_total, fmt)) // " %)") |
---|
| 155 | |
---|
| 156 | CALL report('run_control', "Reading data: " // real_to_str(t_read) // & |
---|
| 157 | " s (" // TRIM(real_to_str(100*t_read/t_total, fmt)) // " %)") |
---|
| 158 | |
---|
| 159 | CALL report('run_control', "Writing data: " // real_to_str(t_write) // & |
---|
| 160 | " s (" // TRIM(real_to_str(100*t_write/t_total, fmt)) // " %)") |
---|
| 161 | |
---|
| 162 | CALL report('run_control', "Computation: " // real_to_str(t_comp) // & |
---|
| 163 | " s (" // TRIM(real_to_str(100*t_comp/t_total, fmt)) // " %)") |
---|
| 164 | |
---|
| 165 | CALL report('run_control', "Total: " // real_to_str(t_total) // & |
---|
| 166 | " s (" // TRIM(real_to_str(100*t_total/t_total, fmt)) // " %)") |
---|
| 167 | |
---|
| 168 | CASE DEFAULT |
---|
| 169 | CALL abort('run_control', "Mode '" // TRIM(mode) // "' is not supported.") |
---|
| 170 | |
---|
| 171 | END SELECT |
---|
| 172 | |
---|
| 173 | END SUBROUTINE run_control |
---|
| 174 | |
---|
| 175 | END MODULE |
---|
| 176 | |
---|