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