[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 | ! |
---|
| 17 | ! Copyright 1997-2012 Leibniz University Hannover |
---|
| 18 | !--------------------------------------------------------------------------------! |
---|
| 19 | ! |
---|
[247] | 20 | ! Current revisions: |
---|
[1] | 21 | ! ----------------- |
---|
[1033] | 22 | ! |
---|
[1] | 23 | ! |
---|
| 24 | ! Former revisions: |
---|
| 25 | ! ----------------- |
---|
[3] | 26 | ! $Id: check_for_restart.f90 1037 2012-10-22 14:10:22Z hoffmann $ |
---|
[110] | 27 | ! |
---|
[1037] | 28 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
| 29 | ! code put under GPL (PALM 3.9) |
---|
| 30 | ! |
---|
[1033] | 31 | ! 1032 2012-10-21 13:03:21Z letzel |
---|
| 32 | ! minor reformatting |
---|
| 33 | ! |
---|
[668] | 34 | ! 667 2010-12-23 12:06:00Z suehring/gryschka |
---|
| 35 | ! Exchange of terminate_coupled between ocean and atmosphere by PE0 |
---|
| 36 | ! |
---|
[623] | 37 | ! 622 2010-12-10 08:08:13Z raasch |
---|
| 38 | ! optional barriers included in order to speed up collective operations |
---|
| 39 | ! |
---|
[392] | 40 | ! 291 2009-04-16 12:07:26Z raasch |
---|
| 41 | ! Coupling with independent precursor runs. |
---|
| 42 | ! Output of messages replaced by message handling routine |
---|
| 43 | ! |
---|
[226] | 44 | ! 222 2009-01-12 16:04:16Z letzel |
---|
| 45 | ! Implementation of an MPI-1 coupling: replaced myid with target_id |
---|
| 46 | ! Bugfix for nonparallel execution |
---|
| 47 | ! |
---|
[110] | 48 | ! 108 2007-08-24 15:10:38Z letzel |
---|
| 49 | ! modifications to terminate coupled runs |
---|
| 50 | ! |
---|
[3] | 51 | ! RCS Log replace by Id keyword, revision history cleaned up |
---|
| 52 | ! |
---|
[1] | 53 | ! Revision 1.11 2007/02/11 12:55:13 raasch |
---|
| 54 | ! Informative output to the job protocol |
---|
| 55 | ! |
---|
| 56 | ! Revision 1.1 1998/03/18 20:06:51 raasch |
---|
| 57 | ! Initial revision |
---|
| 58 | ! |
---|
| 59 | ! |
---|
| 60 | ! Description: |
---|
| 61 | ! ------------ |
---|
| 62 | ! Set stop flag, if restart is neccessary because of expiring cpu-time or |
---|
| 63 | ! if it is forced by user |
---|
| 64 | !------------------------------------------------------------------------------! |
---|
| 65 | |
---|
| 66 | USE pegrid |
---|
| 67 | USE control_parameters |
---|
| 68 | |
---|
| 69 | IMPLICIT NONE |
---|
| 70 | |
---|
| 71 | |
---|
| 72 | LOGICAL :: terminate_run_l |
---|
| 73 | REAL :: remaining_time |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | ! |
---|
| 77 | !-- Check remaining CPU-time |
---|
| 78 | CALL local_tremain( remaining_time ) |
---|
| 79 | |
---|
| 80 | ! |
---|
| 81 | !-- If necessary set a flag to stop the model run |
---|
| 82 | terminate_run_l = .FALSE. |
---|
| 83 | IF ( remaining_time <= termination_time_needed .AND. & |
---|
| 84 | write_binary(1:4) == 'true' ) THEN |
---|
| 85 | |
---|
| 86 | terminate_run_l = .TRUE. |
---|
| 87 | ENDIF |
---|
| 88 | |
---|
| 89 | #if defined( __parallel ) |
---|
| 90 | ! |
---|
| 91 | !-- Make a logical OR for all processes. Stop the model run if at least |
---|
| 92 | !-- one processor has reached the time limit. |
---|
[622] | 93 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
[1] | 94 | CALL MPI_ALLREDUCE( terminate_run_l, terminate_run, 1, MPI_LOGICAL, & |
---|
| 95 | MPI_LOR, comm2d, ierr ) |
---|
| 96 | #else |
---|
| 97 | terminate_run = terminate_run_l |
---|
| 98 | #endif |
---|
| 99 | |
---|
| 100 | ! |
---|
| 101 | !-- Output that job will be terminated |
---|
| 102 | IF ( terminate_run .AND. myid == 0 ) THEN |
---|
[274] | 103 | WRITE( message_string, * ) 'run will be terminated because it is ', & |
---|
| 104 | 'running out of job cpu limit & ', & |
---|
| 105 | 'remaining time: ', remaining_time, ' s', & |
---|
| 106 | 'termination time needed:', termination_time_needed, ' s' |
---|
[247] | 107 | CALL message( 'check_for_restart', 'PA0163', 0, 1, 0, 6, 0 ) |
---|
[1] | 108 | ENDIF |
---|
| 109 | |
---|
| 110 | ! |
---|
[108] | 111 | !-- In case of coupled runs inform the remote model of the termination |
---|
| 112 | !-- and its reason, provided the remote model has not already been |
---|
| 113 | !-- informed of another termination reason (terminate_coupled > 0) before, |
---|
| 114 | !-- or vice versa (terminate_coupled_remote > 0). |
---|
[110] | 115 | IF ( terminate_run .AND. TRIM( coupling_mode ) /= 'uncoupled' .AND. & |
---|
| 116 | terminate_coupled == 0 .AND. terminate_coupled_remote == 0 ) THEN |
---|
| 117 | |
---|
[108] | 118 | terminate_coupled = 3 |
---|
[222] | 119 | #if defined( __parallel ) |
---|
[667] | 120 | IF ( myid == 0 ) THEN |
---|
[1032] | 121 | CALL MPI_SENDRECV( terminate_coupled, 1, MPI_INTEGER, & |
---|
| 122 | target_id, 0, & |
---|
| 123 | terminate_coupled_remote, 1, MPI_INTEGER, & |
---|
| 124 | target_id, 0, & |
---|
[667] | 125 | comm_inter, status, ierr ) |
---|
| 126 | ENDIF |
---|
[1032] | 127 | CALL MPI_BCAST( terminate_coupled_remote, 1, MPI_INTEGER, 0, comm2d, & |
---|
| 128 | ierr ) |
---|
[222] | 129 | #endif |
---|
[108] | 130 | ENDIF |
---|
| 131 | |
---|
| 132 | ! |
---|
[1] | 133 | !-- Set the stop flag also, if restart is forced by user |
---|
[291] | 134 | IF ( time_restart /= 9999999.9 .AND. & |
---|
| 135 | time_restart < time_since_reference_point ) THEN |
---|
| 136 | |
---|
[1] | 137 | ! |
---|
| 138 | !-- Restart is not neccessary, if the end time of the run (given by |
---|
| 139 | !-- the user) has been reached |
---|
| 140 | IF ( simulated_time < end_time ) THEN |
---|
| 141 | terminate_run = .TRUE. |
---|
| 142 | ! |
---|
| 143 | !-- Increment restart time, if forced by user, otherwise set restart |
---|
| 144 | !-- time to default (no user restart) |
---|
| 145 | IF ( dt_restart /= 9999999.9 ) THEN |
---|
| 146 | time_restart = time_restart + dt_restart |
---|
| 147 | ELSE |
---|
| 148 | time_restart = 9999999.9 |
---|
| 149 | ENDIF |
---|
| 150 | |
---|
[247] | 151 | WRITE( message_string, * ) 'run will be terminated due to user ', & |
---|
[274] | 152 | 'settings of', & |
---|
| 153 | '&restart_time / dt_restart', & |
---|
| 154 | '&new restart time is: ', time_restart, ' s' |
---|
| 155 | CALL message( 'check_for_restart', 'PA0164', 0, 0, 0, 6, 0 ) |
---|
[247] | 156 | |
---|
[108] | 157 | ! |
---|
| 158 | !-- In case of coupled runs inform the remote model of the termination |
---|
| 159 | !-- and its reason, provided the remote model has not already been |
---|
| 160 | !-- informed of another termination reason (terminate_coupled > 0) before, |
---|
| 161 | !-- or vice versa (terminate_coupled_remote > 0). |
---|
[206] | 162 | IF ( coupling_mode /= 'uncoupled' .AND. terminate_coupled == 0 & |
---|
| 163 | .AND. terminate_coupled_remote == 0 ) THEN |
---|
[110] | 164 | |
---|
[108] | 165 | IF ( dt_restart /= 9999999.9 ) THEN |
---|
| 166 | terminate_coupled = 4 |
---|
| 167 | ELSE |
---|
| 168 | terminate_coupled = 5 |
---|
| 169 | ENDIF |
---|
[222] | 170 | #if defined( __parallel ) |
---|
[667] | 171 | IF ( myid == 0 ) THEN |
---|
[1032] | 172 | CALL MPI_SENDRECV( terminate_coupled, 1, MPI_INTEGER, & |
---|
| 173 | target_id, 0, & |
---|
| 174 | terminate_coupled_remote, 1, MPI_INTEGER, & |
---|
| 175 | target_id, 0, & |
---|
[667] | 176 | comm_inter, status, ierr ) |
---|
| 177 | ENDIF |
---|
[1032] | 178 | CALL MPI_BCAST( terminate_coupled_remote, 1, MPI_INTEGER, 0, & |
---|
| 179 | comm2d, ierr ) |
---|
[222] | 180 | #endif |
---|
[108] | 181 | ENDIF |
---|
| 182 | ELSE |
---|
[1] | 183 | time_restart = 9999999.9 |
---|
| 184 | ENDIF |
---|
| 185 | ENDIF |
---|
| 186 | |
---|
| 187 | ! |
---|
| 188 | !-- If the run is stopped, set a flag file which is necessary to initiate |
---|
| 189 | !-- the start of a continuation run |
---|
| 190 | IF ( terminate_run .AND. myid == 0 ) THEN |
---|
| 191 | |
---|
| 192 | OPEN ( 90, FILE='CONTINUE_RUN', FORM='FORMATTED' ) |
---|
| 193 | WRITE ( 90, '(A)' ) TRIM( run_description_header ) |
---|
| 194 | CLOSE ( 90 ) |
---|
| 195 | |
---|
| 196 | ENDIF |
---|
| 197 | |
---|
| 198 | |
---|
| 199 | END SUBROUTINE check_for_restart |
---|