[1682] | 1 | !> @file check_for_restart.f90 |
---|
[2000] | 2 | !------------------------------------------------------------------------------! |
---|
[2696] | 3 | ! This file is part of the PALM model system. |
---|
[1036] | 4 | ! |
---|
[2000] | 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. |
---|
[1036] | 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 | ! |
---|
[3655] | 17 | ! Copyright 1997-2019 Leibniz Universitaet Hannover |
---|
[2000] | 18 | !------------------------------------------------------------------------------! |
---|
[1036] | 19 | ! |
---|
[247] | 20 | ! Current revisions: |
---|
[1] | 21 | ! ----------------- |
---|
[2001] | 22 | ! |
---|
[3049] | 23 | ! |
---|
[1321] | 24 | ! Former revisions: |
---|
| 25 | ! ----------------- |
---|
| 26 | ! $Id: check_for_restart.f90 4182 2019-08-22 15:20:23Z monakurppa $ |
---|
[4182] | 27 | ! Corrected "Former revisions" section |
---|
| 28 | ! |
---|
| 29 | ! 3655 2019-01-07 16:51:22Z knoop |
---|
[3045] | 30 | ! Error messages revised |
---|
[2716] | 31 | ! |
---|
[4182] | 32 | ! Revision 1.1 1998/03/18 20:06:51 raasch |
---|
| 33 | ! Initial revision |
---|
| 34 | ! |
---|
| 35 | ! |
---|
[1] | 36 | ! Description: |
---|
| 37 | ! ------------ |
---|
[1682] | 38 | !> Set stop flag, if restart is neccessary because of expiring cpu-time or |
---|
| 39 | !> if it is forced by user |
---|
[1] | 40 | !------------------------------------------------------------------------------! |
---|
[1682] | 41 | SUBROUTINE check_for_restart |
---|
| 42 | |
---|
[1] | 43 | |
---|
[1320] | 44 | USE control_parameters, & |
---|
| 45 | ONLY: coupling_mode, dt_restart, end_time, message_string, & |
---|
| 46 | run_description_header, simulated_time, terminate_coupled, & |
---|
| 47 | terminate_coupled_remote, terminate_run, & |
---|
| 48 | termination_time_needed, time_restart, & |
---|
| 49 | time_since_reference_point, write_binary |
---|
[1797] | 50 | |
---|
[1320] | 51 | USE kinds |
---|
[1797] | 52 | |
---|
[1] | 53 | USE pegrid |
---|
| 54 | |
---|
[1797] | 55 | USE pmc_interface, & |
---|
| 56 | ONLY: comm_world_nesting, cpl_id, nested_run |
---|
| 57 | |
---|
[1] | 58 | IMPLICIT NONE |
---|
| 59 | |
---|
[1797] | 60 | INTEGER :: global_communicator !< global communicator to be used here |
---|
[1] | 61 | |
---|
[1797] | 62 | LOGICAL :: terminate_run_l !< |
---|
| 63 | LOGICAL :: do_stop_now = .FALSE. !< |
---|
| 64 | LOGICAL :: do_restart_now = .FALSE. !< |
---|
[1] | 65 | |
---|
[1682] | 66 | REAL(wp) :: remaining_time !< |
---|
[1] | 67 | |
---|
[1320] | 68 | |
---|
[1] | 69 | ! |
---|
| 70 | !-- Check remaining CPU-time |
---|
| 71 | CALL local_tremain( remaining_time ) |
---|
| 72 | |
---|
| 73 | ! |
---|
| 74 | !-- If necessary set a flag to stop the model run |
---|
| 75 | terminate_run_l = .FALSE. |
---|
[2298] | 76 | IF ( remaining_time <= termination_time_needed .AND. write_binary ) THEN |
---|
[1] | 77 | |
---|
| 78 | terminate_run_l = .TRUE. |
---|
| 79 | ENDIF |
---|
| 80 | |
---|
[1797] | 81 | ! |
---|
| 82 | !-- Set the global communicator to be used (depends on the mode in which PALM is |
---|
| 83 | !-- running) |
---|
| 84 | IF ( nested_run ) THEN |
---|
| 85 | global_communicator = comm_world_nesting |
---|
| 86 | ELSE |
---|
| 87 | global_communicator = comm2d |
---|
| 88 | ENDIF |
---|
| 89 | |
---|
[1] | 90 | #if defined( __parallel ) |
---|
| 91 | ! |
---|
| 92 | !-- Make a logical OR for all processes. Stop the model run if at least |
---|
[1797] | 93 | !-- one process has reached the time limit. |
---|
| 94 | IF ( collective_wait ) CALL MPI_BARRIER( global_communicator, ierr ) |
---|
| 95 | CALL MPI_ALLREDUCE( terminate_run_l, terminate_run, 1, MPI_LOGICAL, & |
---|
| 96 | MPI_LOR, global_communicator, ierr ) |
---|
[1] | 97 | #else |
---|
| 98 | terminate_run = terminate_run_l |
---|
| 99 | #endif |
---|
| 100 | |
---|
| 101 | ! |
---|
| 102 | !-- Output that job will be terminated |
---|
| 103 | IF ( terminate_run .AND. myid == 0 ) THEN |
---|
[1320] | 104 | WRITE( message_string, * ) 'run will be terminated because it is ', & |
---|
[3046] | 105 | 'running out of job cpu limit & ', & |
---|
| 106 | 'remaining time: ', remaining_time, ' s &', & |
---|
[274] | 107 | 'termination time needed:', termination_time_needed, ' s' |
---|
[247] | 108 | CALL message( 'check_for_restart', 'PA0163', 0, 1, 0, 6, 0 ) |
---|
[1] | 109 | ENDIF |
---|
| 110 | |
---|
| 111 | ! |
---|
[108] | 112 | !-- In case of coupled runs inform the remote model of the termination |
---|
| 113 | !-- and its reason, provided the remote model has not already been |
---|
| 114 | !-- informed of another termination reason (terminate_coupled > 0) before, |
---|
| 115 | !-- or vice versa (terminate_coupled_remote > 0). |
---|
[1320] | 116 | IF ( terminate_run .AND. TRIM( coupling_mode ) /= 'uncoupled' .AND. & |
---|
[110] | 117 | terminate_coupled == 0 .AND. terminate_coupled_remote == 0 ) THEN |
---|
| 118 | |
---|
[108] | 119 | terminate_coupled = 3 |
---|
[1468] | 120 | |
---|
[222] | 121 | #if defined( __parallel ) |
---|
[667] | 122 | IF ( myid == 0 ) THEN |
---|
[1032] | 123 | CALL MPI_SENDRECV( terminate_coupled, 1, MPI_INTEGER, & |
---|
| 124 | target_id, 0, & |
---|
| 125 | terminate_coupled_remote, 1, MPI_INTEGER, & |
---|
| 126 | target_id, 0, & |
---|
[667] | 127 | comm_inter, status, ierr ) |
---|
| 128 | ENDIF |
---|
[1320] | 129 | CALL MPI_BCAST( terminate_coupled_remote, 1, MPI_INTEGER, 0, comm2d, & |
---|
[1032] | 130 | ierr ) |
---|
[222] | 131 | #endif |
---|
[108] | 132 | ENDIF |
---|
| 133 | |
---|
[1468] | 134 | |
---|
[108] | 135 | ! |
---|
[1468] | 136 | !-- Check if a flag file exists that forces a termination of the model |
---|
| 137 | IF ( myid == 0 ) THEN |
---|
| 138 | INQUIRE(FILE="DO_STOP_NOW", EXIST=do_stop_now) |
---|
| 139 | INQUIRE(FILE="DO_RESTART_NOW", EXIST=do_restart_now) |
---|
| 140 | |
---|
| 141 | IF ( do_stop_now .OR. do_restart_now ) THEN |
---|
| 142 | |
---|
| 143 | terminate_run_l = .TRUE. |
---|
| 144 | |
---|
| 145 | WRITE( message_string, * ) 'run will be terminated because user ', & |
---|
[2298] | 146 | 'forced a job finalization using a flag', & |
---|
[1468] | 147 | 'file:', & |
---|
[3046] | 148 | '&DO_STOP_NOW: ', do_stop_now, & |
---|
| 149 | '&DO_RESTART_NOW: ', do_restart_now |
---|
[1468] | 150 | CALL message( 'check_for_restart', 'PA0398', 0, 0, 0, 6, 0 ) |
---|
| 151 | |
---|
| 152 | ENDIF |
---|
| 153 | ENDIF |
---|
| 154 | |
---|
| 155 | |
---|
| 156 | #if defined( __parallel ) |
---|
| 157 | ! |
---|
[1797] | 158 | !-- Make a logical OR for all processes. Stop the model run if a flag file has |
---|
| 159 | !-- been detected above. |
---|
| 160 | IF ( collective_wait ) CALL MPI_BARRIER( global_communicator, ierr ) |
---|
[1468] | 161 | CALL MPI_ALLREDUCE( terminate_run_l, terminate_run, 1, MPI_LOGICAL, & |
---|
[1797] | 162 | MPI_LOR, global_communicator, ierr ) |
---|
[1468] | 163 | #else |
---|
| 164 | terminate_run = terminate_run_l |
---|
| 165 | #endif |
---|
| 166 | |
---|
| 167 | ! |
---|
| 168 | !-- In case of coupled runs inform the remote model of the termination |
---|
| 169 | !-- and its reason, provided the remote model has not already been |
---|
| 170 | !-- informed of another termination reason (terminate_coupled > 0) before, |
---|
| 171 | !-- or vice versa (terminate_coupled_remote > 0). |
---|
| 172 | IF ( terminate_run .AND. coupling_mode /= 'uncoupled' .AND. & |
---|
| 173 | terminate_coupled == 0 .AND. terminate_coupled_remote == 0 ) THEN |
---|
| 174 | |
---|
| 175 | terminate_coupled = 6 |
---|
| 176 | |
---|
| 177 | #if defined( __parallel ) |
---|
| 178 | IF ( myid == 0 ) THEN |
---|
| 179 | CALL MPI_SENDRECV( terminate_coupled, 1, MPI_INTEGER, & |
---|
| 180 | target_id, 0, & |
---|
| 181 | terminate_coupled_remote, 1, MPI_INTEGER, & |
---|
| 182 | target_id, 0, & |
---|
| 183 | comm_inter, status, ierr ) |
---|
| 184 | ENDIF |
---|
| 185 | CALL MPI_BCAST( terminate_coupled_remote, 1, MPI_INTEGER, 0, & |
---|
| 186 | comm2d, ierr ) |
---|
| 187 | #endif |
---|
| 188 | |
---|
| 189 | ENDIF |
---|
| 190 | |
---|
| 191 | ! |
---|
| 192 | !-- Set the stop flag also, if restart is forced by user settings |
---|
| 193 | IF ( time_restart /= 9999999.9_wp .AND. & |
---|
[291] | 194 | time_restart < time_since_reference_point ) THEN |
---|
| 195 | |
---|
[1] | 196 | ! |
---|
| 197 | !-- Restart is not neccessary, if the end time of the run (given by |
---|
| 198 | !-- the user) has been reached |
---|
| 199 | IF ( simulated_time < end_time ) THEN |
---|
| 200 | terminate_run = .TRUE. |
---|
| 201 | ! |
---|
| 202 | !-- Increment restart time, if forced by user, otherwise set restart |
---|
| 203 | !-- time to default (no user restart) |
---|
[1353] | 204 | IF ( dt_restart /= 9999999.9_wp ) THEN |
---|
[1] | 205 | time_restart = time_restart + dt_restart |
---|
| 206 | ELSE |
---|
[1353] | 207 | time_restart = 9999999.9_wp |
---|
[1] | 208 | ENDIF |
---|
| 209 | |
---|
[1320] | 210 | WRITE( message_string, * ) 'run will be terminated due to user ', & |
---|
[3045] | 211 | 'settings of ', & |
---|
| 212 | 'restart_time / dt_restart, ', & |
---|
| 213 | 'new restart time is: ', time_restart, ' s' |
---|
[274] | 214 | CALL message( 'check_for_restart', 'PA0164', 0, 0, 0, 6, 0 ) |
---|
[247] | 215 | |
---|
[108] | 216 | ! |
---|
| 217 | !-- In case of coupled runs inform the remote model of the termination |
---|
| 218 | !-- and its reason, provided the remote model has not already been |
---|
| 219 | !-- informed of another termination reason (terminate_coupled > 0) before, |
---|
| 220 | !-- or vice versa (terminate_coupled_remote > 0). |
---|
[1320] | 221 | IF ( coupling_mode /= 'uncoupled' .AND. terminate_coupled == 0 & |
---|
[206] | 222 | .AND. terminate_coupled_remote == 0 ) THEN |
---|
[110] | 223 | |
---|
[1353] | 224 | IF ( dt_restart /= 9999999.9_wp ) THEN |
---|
[108] | 225 | terminate_coupled = 4 |
---|
| 226 | ELSE |
---|
| 227 | terminate_coupled = 5 |
---|
| 228 | ENDIF |
---|
[222] | 229 | #if defined( __parallel ) |
---|
[667] | 230 | IF ( myid == 0 ) THEN |
---|
[1032] | 231 | CALL MPI_SENDRECV( terminate_coupled, 1, MPI_INTEGER, & |
---|
| 232 | target_id, 0, & |
---|
| 233 | terminate_coupled_remote, 1, MPI_INTEGER, & |
---|
| 234 | target_id, 0, & |
---|
[667] | 235 | comm_inter, status, ierr ) |
---|
| 236 | ENDIF |
---|
[1320] | 237 | CALL MPI_BCAST( terminate_coupled_remote, 1, MPI_INTEGER, 0, & |
---|
[1032] | 238 | comm2d, ierr ) |
---|
[222] | 239 | #endif |
---|
[108] | 240 | ENDIF |
---|
| 241 | ELSE |
---|
[1353] | 242 | time_restart = 9999999.9_wp |
---|
[1] | 243 | ENDIF |
---|
| 244 | ENDIF |
---|
| 245 | |
---|
| 246 | ! |
---|
| 247 | !-- If the run is stopped, set a flag file which is necessary to initiate |
---|
[1468] | 248 | !-- the start of a continuation run, except if the user forced to stop the |
---|
| 249 | !-- run without restart |
---|
[1797] | 250 | IF ( terminate_run .AND. myid == 0 .AND. cpl_id == 1 .AND. & |
---|
| 251 | .NOT. do_stop_now) THEN |
---|
[1] | 252 | |
---|
| 253 | OPEN ( 90, FILE='CONTINUE_RUN', FORM='FORMATTED' ) |
---|
| 254 | WRITE ( 90, '(A)' ) TRIM( run_description_header ) |
---|
| 255 | CLOSE ( 90 ) |
---|
| 256 | |
---|
| 257 | ENDIF |
---|
| 258 | |
---|
| 259 | |
---|
| 260 | END SUBROUTINE check_for_restart |
---|