[1] | 1 | SUBROUTINE check_for_restart |
---|
| 2 | |
---|
[1036] | 3 | !--------------------------------------------------------------------------------! |
---|
| 4 | ! This file is part of PALM. |
---|
| 5 | ! |
---|
| 6 | ! PALM is free software: you can redistribute it and/or modify it under the terms |
---|
| 7 | ! of the GNU General Public License as published by the Free Software Foundation, |
---|
| 8 | ! either version 3 of the License, or (at your option) any later 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 | ! |
---|
[1310] | 17 | ! Copyright 1997-2014 Leibniz Universitaet Hannover |
---|
[1036] | 18 | !--------------------------------------------------------------------------------! |
---|
| 19 | ! |
---|
[247] | 20 | ! Current revisions: |
---|
[1] | 21 | ! ----------------- |
---|
[1320] | 22 | ! ONLY-attribute added to USE-statements, |
---|
| 23 | ! kind-parameters added to all INTEGER and REAL declaration statements, |
---|
| 24 | ! kinds are defined in new module kinds, |
---|
| 25 | ! revision history before 2012 removed, |
---|
| 26 | ! comment fields (!:) to be used for variable explanations added to |
---|
| 27 | ! all variable declaration statements |
---|
[1] | 28 | ! |
---|
| 29 | ! Former revisions: |
---|
| 30 | ! ----------------- |
---|
[3] | 31 | ! $Id: check_for_restart.f90 1320 2014-03-20 08:40:49Z raasch $ |
---|
[110] | 32 | ! |
---|
[1037] | 33 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
| 34 | ! code put under GPL (PALM 3.9) |
---|
| 35 | ! |
---|
[1033] | 36 | ! 1032 2012-10-21 13:03:21Z letzel |
---|
| 37 | ! minor reformatting |
---|
| 38 | ! |
---|
[1] | 39 | ! Revision 1.1 1998/03/18 20:06:51 raasch |
---|
| 40 | ! Initial revision |
---|
| 41 | ! |
---|
| 42 | ! |
---|
| 43 | ! Description: |
---|
| 44 | ! ------------ |
---|
| 45 | ! Set stop flag, if restart is neccessary because of expiring cpu-time or |
---|
| 46 | ! if it is forced by user |
---|
| 47 | !------------------------------------------------------------------------------! |
---|
| 48 | |
---|
[1320] | 49 | USE control_parameters, & |
---|
| 50 | ONLY: coupling_mode, dt_restart, end_time, message_string, & |
---|
| 51 | run_description_header, simulated_time, terminate_coupled, & |
---|
| 52 | terminate_coupled_remote, terminate_run, & |
---|
| 53 | termination_time_needed, time_restart, & |
---|
| 54 | time_since_reference_point, write_binary |
---|
| 55 | USE kinds |
---|
[1] | 56 | USE pegrid |
---|
| 57 | |
---|
| 58 | IMPLICIT NONE |
---|
| 59 | |
---|
| 60 | |
---|
[1320] | 61 | LOGICAL :: terminate_run_l !: |
---|
[1] | 62 | |
---|
[1320] | 63 | REAL(wp) :: remaining_time !: |
---|
[1] | 64 | |
---|
[1320] | 65 | |
---|
[1] | 66 | ! |
---|
| 67 | !-- Check remaining CPU-time |
---|
| 68 | CALL local_tremain( remaining_time ) |
---|
| 69 | |
---|
| 70 | ! |
---|
| 71 | !-- If necessary set a flag to stop the model run |
---|
| 72 | terminate_run_l = .FALSE. |
---|
[1320] | 73 | IF ( remaining_time <= termination_time_needed .AND. & |
---|
[1] | 74 | write_binary(1:4) == 'true' ) THEN |
---|
| 75 | |
---|
| 76 | terminate_run_l = .TRUE. |
---|
| 77 | ENDIF |
---|
| 78 | |
---|
| 79 | #if defined( __parallel ) |
---|
| 80 | ! |
---|
| 81 | !-- Make a logical OR for all processes. Stop the model run if at least |
---|
| 82 | !-- one processor has reached the time limit. |
---|
[622] | 83 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
[1320] | 84 | CALL MPI_ALLREDUCE( terminate_run_l, terminate_run, 1, MPI_LOGICAL, & |
---|
[1] | 85 | MPI_LOR, comm2d, ierr ) |
---|
| 86 | #else |
---|
| 87 | terminate_run = terminate_run_l |
---|
| 88 | #endif |
---|
| 89 | |
---|
| 90 | ! |
---|
| 91 | !-- Output that job will be terminated |
---|
| 92 | IF ( terminate_run .AND. myid == 0 ) THEN |
---|
[1320] | 93 | WRITE( message_string, * ) 'run will be terminated because it is ', & |
---|
| 94 | 'running out of job cpu limit & ', & |
---|
| 95 | 'remaining time: ', remaining_time, ' s', & |
---|
[274] | 96 | 'termination time needed:', termination_time_needed, ' s' |
---|
[247] | 97 | CALL message( 'check_for_restart', 'PA0163', 0, 1, 0, 6, 0 ) |
---|
[1] | 98 | ENDIF |
---|
| 99 | |
---|
| 100 | ! |
---|
[108] | 101 | !-- In case of coupled runs inform the remote model of the termination |
---|
| 102 | !-- and its reason, provided the remote model has not already been |
---|
| 103 | !-- informed of another termination reason (terminate_coupled > 0) before, |
---|
| 104 | !-- or vice versa (terminate_coupled_remote > 0). |
---|
[1320] | 105 | IF ( terminate_run .AND. TRIM( coupling_mode ) /= 'uncoupled' .AND. & |
---|
[110] | 106 | terminate_coupled == 0 .AND. terminate_coupled_remote == 0 ) THEN |
---|
| 107 | |
---|
[108] | 108 | terminate_coupled = 3 |
---|
[222] | 109 | #if defined( __parallel ) |
---|
[667] | 110 | IF ( myid == 0 ) THEN |
---|
[1032] | 111 | CALL MPI_SENDRECV( terminate_coupled, 1, MPI_INTEGER, & |
---|
| 112 | target_id, 0, & |
---|
| 113 | terminate_coupled_remote, 1, MPI_INTEGER, & |
---|
| 114 | target_id, 0, & |
---|
[667] | 115 | comm_inter, status, ierr ) |
---|
| 116 | ENDIF |
---|
[1320] | 117 | CALL MPI_BCAST( terminate_coupled_remote, 1, MPI_INTEGER, 0, comm2d, & |
---|
[1032] | 118 | ierr ) |
---|
[222] | 119 | #endif |
---|
[108] | 120 | ENDIF |
---|
| 121 | |
---|
| 122 | ! |
---|
[1] | 123 | !-- Set the stop flag also, if restart is forced by user |
---|
[1320] | 124 | IF ( time_restart /= 9999999.9 .AND. & |
---|
[291] | 125 | time_restart < time_since_reference_point ) THEN |
---|
| 126 | |
---|
[1] | 127 | ! |
---|
| 128 | !-- Restart is not neccessary, if the end time of the run (given by |
---|
| 129 | !-- the user) has been reached |
---|
| 130 | IF ( simulated_time < end_time ) THEN |
---|
| 131 | terminate_run = .TRUE. |
---|
| 132 | ! |
---|
| 133 | !-- Increment restart time, if forced by user, otherwise set restart |
---|
| 134 | !-- time to default (no user restart) |
---|
| 135 | IF ( dt_restart /= 9999999.9 ) THEN |
---|
| 136 | time_restart = time_restart + dt_restart |
---|
| 137 | ELSE |
---|
| 138 | time_restart = 9999999.9 |
---|
| 139 | ENDIF |
---|
| 140 | |
---|
[1320] | 141 | WRITE( message_string, * ) 'run will be terminated due to user ', & |
---|
| 142 | 'settings of', & |
---|
| 143 | '&restart_time / dt_restart', & |
---|
[274] | 144 | '&new restart time is: ', time_restart, ' s' |
---|
| 145 | CALL message( 'check_for_restart', 'PA0164', 0, 0, 0, 6, 0 ) |
---|
[247] | 146 | |
---|
[108] | 147 | ! |
---|
| 148 | !-- In case of coupled runs inform the remote model of the termination |
---|
| 149 | !-- and its reason, provided the remote model has not already been |
---|
| 150 | !-- informed of another termination reason (terminate_coupled > 0) before, |
---|
| 151 | !-- or vice versa (terminate_coupled_remote > 0). |
---|
[1320] | 152 | IF ( coupling_mode /= 'uncoupled' .AND. terminate_coupled == 0 & |
---|
[206] | 153 | .AND. terminate_coupled_remote == 0 ) THEN |
---|
[110] | 154 | |
---|
[108] | 155 | IF ( dt_restart /= 9999999.9 ) THEN |
---|
| 156 | terminate_coupled = 4 |
---|
| 157 | ELSE |
---|
| 158 | terminate_coupled = 5 |
---|
| 159 | ENDIF |
---|
[222] | 160 | #if defined( __parallel ) |
---|
[667] | 161 | IF ( myid == 0 ) THEN |
---|
[1032] | 162 | CALL MPI_SENDRECV( terminate_coupled, 1, MPI_INTEGER, & |
---|
| 163 | target_id, 0, & |
---|
| 164 | terminate_coupled_remote, 1, MPI_INTEGER, & |
---|
| 165 | target_id, 0, & |
---|
[667] | 166 | comm_inter, status, ierr ) |
---|
| 167 | ENDIF |
---|
[1320] | 168 | CALL MPI_BCAST( terminate_coupled_remote, 1, MPI_INTEGER, 0, & |
---|
[1032] | 169 | comm2d, ierr ) |
---|
[222] | 170 | #endif |
---|
[108] | 171 | ENDIF |
---|
| 172 | ELSE |
---|
[1] | 173 | time_restart = 9999999.9 |
---|
| 174 | ENDIF |
---|
| 175 | ENDIF |
---|
| 176 | |
---|
| 177 | ! |
---|
| 178 | !-- If the run is stopped, set a flag file which is necessary to initiate |
---|
| 179 | !-- the start of a continuation run |
---|
| 180 | IF ( terminate_run .AND. myid == 0 ) THEN |
---|
| 181 | |
---|
| 182 | OPEN ( 90, FILE='CONTINUE_RUN', FORM='FORMATTED' ) |
---|
| 183 | WRITE ( 90, '(A)' ) TRIM( run_description_header ) |
---|
| 184 | CLOSE ( 90 ) |
---|
| 185 | |
---|
| 186 | ENDIF |
---|
| 187 | |
---|
| 188 | |
---|
| 189 | END SUBROUTINE check_for_restart |
---|