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

Last change on this file since 3025 was 2718, checked in by maronga, 7 years ago

deleting of deprecated files; headers updated where needed

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