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