source: palm/trunk/SOURCE/check_for_restart.f90 @ 1468

Last change on this file since 1468 was 1468, checked in by maronga, 10 years ago

New flag files allow to force unscheduled termination/restarts of batch jobs, progress output is made for batch runs, small adjustments for lxce6 and lccrayh/lccrayb

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