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

Last change on this file since 3449 was 3049, checked in by Giersch, 6 years ago

Revision history corrected

  • Property svn:keywords set to Id
File size: 10.9 KB
RevLine 
[1682]1!> @file check_for_restart.f90
[2000]2!------------------------------------------------------------------------------!
[2696]3! This file is part of the PALM model system.
[1036]4!
[2000]5! PALM is free software: you can redistribute it and/or modify it under the
6! terms of the GNU General Public License as published by the Free Software
7! Foundation, either version 3 of the License, or (at your option) any later
8! version.
[1036]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!
[2718]17! Copyright 1997-2018 Leibniz Universitaet Hannover
[2000]18!------------------------------------------------------------------------------!
[1036]19!
[247]20! Current revisions:
[1]21! -----------------
[2001]22!
[3049]23!
[1321]24! Former revisions:
25! -----------------
26! $Id: check_for_restart.f90 3049 2018-05-29 13:52:36Z suehring $
[3045]27! Error messages revised
28!
[3049]29! 3045 2018-05-28 07:55:41Z Giersch
30! Error messages revised
31!
[3045]32! 2718 2018-01-02 08:49:38Z maronga
[2716]33! Corrected "Former revisions" section
34!
35! 2696 2017-12-14 17:12:51Z kanani
36! Change in file header (GPL part)
37!
38! 2298 2017-06-29 09:28:18Z raasch
[2298]39! type of write_binary changed from CHARACTER to LOGICAL
40!
41! 2101 2017-01-05 16:42:31Z suehring
[1321]42!
[2001]43! 2000 2016-08-20 18:09:15Z knoop
44! Forced header and separation lines into 80 columns
45!
[1798]46! 1797 2016-03-21 16:50:28Z raasch
47! check accounts for nesting mode now
48!
[1683]49! 1682 2015-10-07 23:56:08Z knoop
50! Code annotations made doxygen readable
51!
[1510]52! 1509 2014-12-16 08:56:46Z heinze
53! bugfix: prevent infinite loop in case of automatic restarts
54!
[1469]55! 1468 2014-09-24 14:06:57Z maronga
56! Added support for unscheduled job termination using the flag files
57! DO_STOP_NOW and DO_RESTART_NOW
58!
[1354]59! 1353 2014-04-08 15:21:23Z heinze
60! REAL constants provided with KIND-attribute
61!
[1321]62! 1320 2014-03-20 08:40:49Z raasch
[1320]63! ONLY-attribute added to USE-statements,
64! kind-parameters added to all INTEGER and REAL declaration statements,
65! kinds are defined in new module kinds,
66! revision history before 2012 removed,
67! comment fields (!:) to be used for variable explanations added to
68! all variable declaration statements
[1]69!
[1037]70! 1036 2012-10-22 13:43:42Z raasch
71! code put under GPL (PALM 3.9)
72!
[1033]73! 1032 2012-10-21 13:03:21Z letzel
74! minor reformatting
75!
[1]76! Revision 1.1  1998/03/18 20:06:51  raasch
77! Initial revision
78!
79!
80! Description:
81! ------------
[1682]82!> Set stop flag, if restart is neccessary because of expiring cpu-time or
83!> if it is forced by user
[1]84!------------------------------------------------------------------------------!
[1682]85 SUBROUTINE check_for_restart
86 
[1]87
[1320]88    USE control_parameters,                                                    &
89        ONLY:  coupling_mode, dt_restart, end_time, message_string,            &
90               run_description_header, simulated_time, terminate_coupled,      &
91               terminate_coupled_remote, terminate_run,                        &
92               termination_time_needed, time_restart,                          &
93               time_since_reference_point, write_binary
[1797]94
[1320]95    USE kinds
[1797]96
[1]97    USE pegrid
98
[1797]99    USE pmc_interface,                                                         &
100        ONLY:  comm_world_nesting, cpl_id, nested_run
101
[1]102    IMPLICIT NONE
103
[1797]104    INTEGER ::  global_communicator       !< global communicator to be used here
[1]105
[1797]106    LOGICAL ::  terminate_run_l           !<
107    LOGICAL ::  do_stop_now = .FALSE.     !<
108    LOGICAL ::  do_restart_now = .FALSE.  !<
[1]109
[1682]110    REAL(wp) ::  remaining_time !<
[1]111
[1320]112
[1]113!
114!-- Check remaining CPU-time
115    CALL local_tremain( remaining_time )
116
117!
118!-- If necessary set a flag to stop the model run
119    terminate_run_l = .FALSE.
[2298]120    IF ( remaining_time <= termination_time_needed  .AND.  write_binary )  THEN
[1]121
122       terminate_run_l = .TRUE.
123    ENDIF
124
[1797]125!
126!-- Set the global communicator to be used (depends on the mode in which PALM is
127!-- running)
128    IF ( nested_run )  THEN
129       global_communicator = comm_world_nesting
130    ELSE
131       global_communicator = comm2d
132    ENDIF
133
[1]134#if defined( __parallel )
135!
136!-- Make a logical OR for all processes. Stop the model run if at least
[1797]137!-- one process has reached the time limit.
138    IF ( collective_wait )  CALL MPI_BARRIER( global_communicator, ierr )
139    CALL MPI_ALLREDUCE( terminate_run_l, terminate_run, 1, MPI_LOGICAL,     &
140                        MPI_LOR, global_communicator, ierr )
[1]141#else
142    terminate_run = terminate_run_l
143#endif
144
145!
146!-- Output that job will be terminated
147    IF ( terminate_run  .AND.  myid == 0 )  THEN
[1320]148       WRITE( message_string, * ) 'run will be terminated because it is ',     &
[3046]149                       'running out of job cpu limit & ',                      &
150                       'remaining time:         ', remaining_time, ' s &',     &
[274]151                       'termination time needed:', termination_time_needed, ' s'
[247]152       CALL message( 'check_for_restart', 'PA0163', 0, 1, 0, 6, 0 )
[1]153    ENDIF
154
155!
[108]156!-- In case of coupled runs inform the remote model of the termination
157!-- and its reason, provided the remote model has not already been
158!-- informed of another termination reason (terminate_coupled > 0) before,
159!-- or vice versa (terminate_coupled_remote > 0).
[1320]160    IF ( terminate_run .AND. TRIM( coupling_mode ) /= 'uncoupled'  .AND.       &
[110]161         terminate_coupled == 0  .AND.  terminate_coupled_remote == 0 )  THEN
162
[108]163       terminate_coupled = 3
[1468]164
[222]165#if defined( __parallel )
[667]166       IF ( myid == 0 ) THEN
[1032]167          CALL MPI_SENDRECV( terminate_coupled,        1, MPI_INTEGER,         &
168                             target_id, 0,                                     &
169                             terminate_coupled_remote, 1, MPI_INTEGER,         &
170                             target_id, 0,                                     &
[667]171                             comm_inter, status, ierr )
172       ENDIF
[1320]173       CALL MPI_BCAST( terminate_coupled_remote, 1, MPI_INTEGER, 0, comm2d,    &
[1032]174                       ierr )
[222]175#endif
[108]176    ENDIF
177
[1468]178
[108]179!
[1468]180!-- Check if a flag file exists that forces a termination of the model
181    IF ( myid == 0 )  THEN
182       INQUIRE(FILE="DO_STOP_NOW", EXIST=do_stop_now)
183       INQUIRE(FILE="DO_RESTART_NOW", EXIST=do_restart_now)
184
185       IF ( do_stop_now .OR. do_restart_now )  THEN
186
187          terminate_run_l = .TRUE.
188
189          WRITE( message_string, * ) 'run will be terminated because user ',   &
[2298]190                                  'forced a job finalization using a flag',    &
[1468]191                                  'file:',                                     &
[3046]192                                  '&DO_STOP_NOW: ', do_stop_now,               &
193                                  '&DO_RESTART_NOW: ', do_restart_now 
[1468]194          CALL message( 'check_for_restart', 'PA0398', 0, 0, 0, 6, 0 )
195
196       ENDIF
197    ENDIF
198
199
200#if defined( __parallel )
201!
[1797]202!-- Make a logical OR for all processes. Stop the model run if a flag file has
203!-- been detected above.
204    IF ( collective_wait )  CALL MPI_BARRIER( global_communicator, ierr )
[1468]205    CALL MPI_ALLREDUCE( terminate_run_l, terminate_run, 1, MPI_LOGICAL,        &
[1797]206                        MPI_LOR, global_communicator, ierr )
[1468]207#else
208    terminate_run = terminate_run_l
209#endif
210
211!
212!-- In case of coupled runs inform the remote model of the termination
213!-- and its reason, provided the remote model has not already been
214!-- informed of another termination reason (terminate_coupled > 0) before,
215!-- or vice versa (terminate_coupled_remote > 0).
216    IF ( terminate_run .AND. coupling_mode /= 'uncoupled' .AND.                &
217         terminate_coupled == 0 .AND.  terminate_coupled_remote == 0 )  THEN
218
219       terminate_coupled = 6
220
221#if defined( __parallel )
222       IF ( myid == 0 ) THEN
223          CALL MPI_SENDRECV( terminate_coupled,        1, MPI_INTEGER,      &
224                             target_id,  0,                                 &
225                             terminate_coupled_remote, 1, MPI_INTEGER,      &
226                             target_id,  0,                                 &
227                             comm_inter, status, ierr )   
228       ENDIF
229       CALL MPI_BCAST( terminate_coupled_remote, 1, MPI_INTEGER, 0,         &
230                       comm2d, ierr ) 
231#endif
232
233    ENDIF
234
235!
236!-- Set the stop flag also, if restart is forced by user settings
237    IF ( time_restart /= 9999999.9_wp  .AND.                                   &
[291]238         time_restart < time_since_reference_point )  THEN
239
[1]240!
241!--    Restart is not neccessary, if the end time of the run (given by
242!--    the user) has been reached
243       IF ( simulated_time < end_time )  THEN
244          terminate_run = .TRUE.
245!
246!--       Increment restart time, if forced by user, otherwise set restart
247!--       time to default (no user restart)
[1353]248          IF ( dt_restart /= 9999999.9_wp )  THEN
[1]249             time_restart = time_restart + dt_restart
250          ELSE
[1353]251             time_restart = 9999999.9_wp
[1]252          ENDIF
253
[1320]254          WRITE( message_string, * ) 'run will be terminated due to user ',    &
[3045]255                                  'settings of ',                              &
256                                  'restart_time / dt_restart, ',               &
257                                  'new restart time is: ', time_restart, ' s' 
[274]258          CALL message( 'check_for_restart', 'PA0164', 0, 0, 0, 6, 0 )
[247]259 
[108]260!
261!--       In case of coupled runs inform the remote model of the termination
262!--       and its reason, provided the remote model has not already been
263!--       informed of another termination reason (terminate_coupled > 0) before,
264!--       or vice versa (terminate_coupled_remote > 0).
[1320]265          IF ( coupling_mode /= 'uncoupled' .AND. terminate_coupled == 0       &
[206]266               .AND.  terminate_coupled_remote == 0 )  THEN
[110]267
[1353]268             IF ( dt_restart /= 9999999.9_wp )  THEN
[108]269                terminate_coupled = 4
270             ELSE
271                terminate_coupled = 5
272             ENDIF
[222]273#if defined( __parallel )
[667]274             IF ( myid == 0 ) THEN
[1032]275                CALL MPI_SENDRECV( terminate_coupled,        1, MPI_INTEGER,   &
276                                   target_id,  0,                              &
277                                   terminate_coupled_remote, 1, MPI_INTEGER,   &
278                                   target_id,  0,                              &
[667]279                                   comm_inter, status, ierr )   
280             ENDIF
[1320]281             CALL MPI_BCAST( terminate_coupled_remote, 1, MPI_INTEGER, 0,      &
[1032]282                             comm2d, ierr ) 
[222]283#endif
[108]284          ENDIF
285       ELSE
[1353]286          time_restart = 9999999.9_wp
[1]287       ENDIF
288    ENDIF
289
290!
291!-- If the run is stopped, set a flag file which is necessary to initiate
[1468]292!-- the start of a continuation run, except if the user forced to stop the
293!-- run without restart
[1797]294    IF ( terminate_run  .AND.  myid == 0  .AND.  cpl_id == 1  .AND.            &
295         .NOT. do_stop_now)  THEN
[1]296
297       OPEN ( 90, FILE='CONTINUE_RUN', FORM='FORMATTED' )
298       WRITE ( 90, '(A)' )  TRIM( run_description_header )
299       CLOSE ( 90 )
300
301    ENDIF
302
303
304 END SUBROUTINE check_for_restart
Note: See TracBrowser for help on using the repository browser.