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

Last change on this file since 4180 was 4180, checked in by scharf, 5 years ago

removed comments in 'Former revisions' section that are older than 01.01.2019

  • Property svn:keywords set to Id
File size: 9.5 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!
[3655]17! Copyright 1997-2019 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 4180 2019-08-21 14:37:54Z scharf $
[3045]27! Error messages revised
28!
[2716]29!
[1]30! Description:
31! ------------
[1682]32!> Set stop flag, if restart is neccessary because of expiring cpu-time or
33!> if it is forced by user
[1]34!------------------------------------------------------------------------------!
[1682]35 SUBROUTINE check_for_restart
36 
[1]37
[1320]38    USE control_parameters,                                                    &
39        ONLY:  coupling_mode, dt_restart, end_time, message_string,            &
40               run_description_header, simulated_time, terminate_coupled,      &
41               terminate_coupled_remote, terminate_run,                        &
42               termination_time_needed, time_restart,                          &
43               time_since_reference_point, write_binary
[1797]44
[1320]45    USE kinds
[1797]46
[1]47    USE pegrid
48
[1797]49    USE pmc_interface,                                                         &
50        ONLY:  comm_world_nesting, cpl_id, nested_run
51
[1]52    IMPLICIT NONE
53
[1797]54    INTEGER ::  global_communicator       !< global communicator to be used here
[1]55
[1797]56    LOGICAL ::  terminate_run_l           !<
57    LOGICAL ::  do_stop_now = .FALSE.     !<
58    LOGICAL ::  do_restart_now = .FALSE.  !<
[1]59
[1682]60    REAL(wp) ::  remaining_time !<
[1]61
[1320]62
[1]63!
64!-- Check remaining CPU-time
65    CALL local_tremain( remaining_time )
66
67!
68!-- If necessary set a flag to stop the model run
69    terminate_run_l = .FALSE.
[2298]70    IF ( remaining_time <= termination_time_needed  .AND.  write_binary )  THEN
[1]71
72       terminate_run_l = .TRUE.
73    ENDIF
74
[1797]75!
76!-- Set the global communicator to be used (depends on the mode in which PALM is
77!-- running)
78    IF ( nested_run )  THEN
79       global_communicator = comm_world_nesting
80    ELSE
81       global_communicator = comm2d
82    ENDIF
83
[1]84#if defined( __parallel )
85!
86!-- Make a logical OR for all processes. Stop the model run if at least
[1797]87!-- one process has reached the time limit.
88    IF ( collective_wait )  CALL MPI_BARRIER( global_communicator, ierr )
89    CALL MPI_ALLREDUCE( terminate_run_l, terminate_run, 1, MPI_LOGICAL,     &
90                        MPI_LOR, global_communicator, ierr )
[1]91#else
92    terminate_run = terminate_run_l
93#endif
94
95!
96!-- Output that job will be terminated
97    IF ( terminate_run  .AND.  myid == 0 )  THEN
[1320]98       WRITE( message_string, * ) 'run will be terminated because it is ',     &
[3046]99                       'running out of job cpu limit & ',                      &
100                       'remaining time:         ', remaining_time, ' s &',     &
[274]101                       'termination time needed:', termination_time_needed, ' s'
[247]102       CALL message( 'check_for_restart', 'PA0163', 0, 1, 0, 6, 0 )
[1]103    ENDIF
104
105!
[108]106!-- In case of coupled runs inform the remote model of the termination
107!-- and its reason, provided the remote model has not already been
108!-- informed of another termination reason (terminate_coupled > 0) before,
109!-- or vice versa (terminate_coupled_remote > 0).
[1320]110    IF ( terminate_run .AND. TRIM( coupling_mode ) /= 'uncoupled'  .AND.       &
[110]111         terminate_coupled == 0  .AND.  terminate_coupled_remote == 0 )  THEN
112
[108]113       terminate_coupled = 3
[1468]114
[222]115#if defined( __parallel )
[667]116       IF ( myid == 0 ) THEN
[1032]117          CALL MPI_SENDRECV( terminate_coupled,        1, MPI_INTEGER,         &
118                             target_id, 0,                                     &
119                             terminate_coupled_remote, 1, MPI_INTEGER,         &
120                             target_id, 0,                                     &
[667]121                             comm_inter, status, ierr )
122       ENDIF
[1320]123       CALL MPI_BCAST( terminate_coupled_remote, 1, MPI_INTEGER, 0, comm2d,    &
[1032]124                       ierr )
[222]125#endif
[108]126    ENDIF
127
[1468]128
[108]129!
[1468]130!-- Check if a flag file exists that forces a termination of the model
131    IF ( myid == 0 )  THEN
132       INQUIRE(FILE="DO_STOP_NOW", EXIST=do_stop_now)
133       INQUIRE(FILE="DO_RESTART_NOW", EXIST=do_restart_now)
134
135       IF ( do_stop_now .OR. do_restart_now )  THEN
136
137          terminate_run_l = .TRUE.
138
139          WRITE( message_string, * ) 'run will be terminated because user ',   &
[2298]140                                  'forced a job finalization using a flag',    &
[1468]141                                  'file:',                                     &
[3046]142                                  '&DO_STOP_NOW: ', do_stop_now,               &
143                                  '&DO_RESTART_NOW: ', do_restart_now 
[1468]144          CALL message( 'check_for_restart', 'PA0398', 0, 0, 0, 6, 0 )
145
146       ENDIF
147    ENDIF
148
149
150#if defined( __parallel )
151!
[1797]152!-- Make a logical OR for all processes. Stop the model run if a flag file has
153!-- been detected above.
154    IF ( collective_wait )  CALL MPI_BARRIER( global_communicator, ierr )
[1468]155    CALL MPI_ALLREDUCE( terminate_run_l, terminate_run, 1, MPI_LOGICAL,        &
[1797]156                        MPI_LOR, global_communicator, ierr )
[1468]157#else
158    terminate_run = terminate_run_l
159#endif
160
161!
162!-- In case of coupled runs inform the remote model of the termination
163!-- and its reason, provided the remote model has not already been
164!-- informed of another termination reason (terminate_coupled > 0) before,
165!-- or vice versa (terminate_coupled_remote > 0).
166    IF ( terminate_run .AND. coupling_mode /= 'uncoupled' .AND.                &
167         terminate_coupled == 0 .AND.  terminate_coupled_remote == 0 )  THEN
168
169       terminate_coupled = 6
170
171#if defined( __parallel )
172       IF ( myid == 0 ) THEN
173          CALL MPI_SENDRECV( terminate_coupled,        1, MPI_INTEGER,      &
174                             target_id,  0,                                 &
175                             terminate_coupled_remote, 1, MPI_INTEGER,      &
176                             target_id,  0,                                 &
177                             comm_inter, status, ierr )   
178       ENDIF
179       CALL MPI_BCAST( terminate_coupled_remote, 1, MPI_INTEGER, 0,         &
180                       comm2d, ierr ) 
181#endif
182
183    ENDIF
184
185!
186!-- Set the stop flag also, if restart is forced by user settings
187    IF ( time_restart /= 9999999.9_wp  .AND.                                   &
[291]188         time_restart < time_since_reference_point )  THEN
189
[1]190!
191!--    Restart is not neccessary, if the end time of the run (given by
192!--    the user) has been reached
193       IF ( simulated_time < end_time )  THEN
194          terminate_run = .TRUE.
195!
196!--       Increment restart time, if forced by user, otherwise set restart
197!--       time to default (no user restart)
[1353]198          IF ( dt_restart /= 9999999.9_wp )  THEN
[1]199             time_restart = time_restart + dt_restart
200          ELSE
[1353]201             time_restart = 9999999.9_wp
[1]202          ENDIF
203
[1320]204          WRITE( message_string, * ) 'run will be terminated due to user ',    &
[3045]205                                  'settings of ',                              &
206                                  'restart_time / dt_restart, ',               &
207                                  'new restart time is: ', time_restart, ' s' 
[274]208          CALL message( 'check_for_restart', 'PA0164', 0, 0, 0, 6, 0 )
[247]209 
[108]210!
211!--       In case of coupled runs inform the remote model of the termination
212!--       and its reason, provided the remote model has not already been
213!--       informed of another termination reason (terminate_coupled > 0) before,
214!--       or vice versa (terminate_coupled_remote > 0).
[1320]215          IF ( coupling_mode /= 'uncoupled' .AND. terminate_coupled == 0       &
[206]216               .AND.  terminate_coupled_remote == 0 )  THEN
[110]217
[1353]218             IF ( dt_restart /= 9999999.9_wp )  THEN
[108]219                terminate_coupled = 4
220             ELSE
221                terminate_coupled = 5
222             ENDIF
[222]223#if defined( __parallel )
[667]224             IF ( myid == 0 ) THEN
[1032]225                CALL MPI_SENDRECV( terminate_coupled,        1, MPI_INTEGER,   &
226                                   target_id,  0,                              &
227                                   terminate_coupled_remote, 1, MPI_INTEGER,   &
228                                   target_id,  0,                              &
[667]229                                   comm_inter, status, ierr )   
230             ENDIF
[1320]231             CALL MPI_BCAST( terminate_coupled_remote, 1, MPI_INTEGER, 0,      &
[1032]232                             comm2d, ierr ) 
[222]233#endif
[108]234          ENDIF
235       ELSE
[1353]236          time_restart = 9999999.9_wp
[1]237       ENDIF
238    ENDIF
239
240!
241!-- If the run is stopped, set a flag file which is necessary to initiate
[1468]242!-- the start of a continuation run, except if the user forced to stop the
243!-- run without restart
[1797]244    IF ( terminate_run  .AND.  myid == 0  .AND.  cpl_id == 1  .AND.            &
245         .NOT. do_stop_now)  THEN
[1]246
247       OPEN ( 90, FILE='CONTINUE_RUN', FORM='FORMATTED' )
248       WRITE ( 90, '(A)' )  TRIM( run_description_header )
249       CLOSE ( 90 )
250
251    ENDIF
252
253
254 END SUBROUTINE check_for_restart
Note: See TracBrowser for help on using the repository browser.