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

Last change on this file since 1434 was 1354, checked in by heinze, 11 years ago

last commit documented

  • Property svn:keywords set to Id
File size: 7.2 KB
RevLine 
[1]1 SUBROUTINE check_for_restart
2
[1036]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!
[1310]17! Copyright 1997-2014 Leibniz Universitaet Hannover
[1036]18!--------------------------------------------------------------------------------!
19!
[247]20! Current revisions:
[1]21! -----------------
[1354]22!
23!
[1321]24! Former revisions:
25! -----------------
26! $Id: check_for_restart.f90 1354 2014-04-08 15:22:57Z keck $
27!
[1354]28! 1353 2014-04-08 15:21:23Z heinze
29! REAL constants provided with KIND-attribute
30!
[1321]31! 1320 2014-03-20 08:40:49Z raasch
[1320]32! ONLY-attribute added to USE-statements,
33! kind-parameters added to all INTEGER and REAL declaration statements,
34! kinds are defined in new module kinds,
35! revision history before 2012 removed,
36! comment fields (!:) to be used for variable explanations added to
37! all variable declaration statements
[1]38!
[1037]39! 1036 2012-10-22 13:43:42Z raasch
40! code put under GPL (PALM 3.9)
41!
[1033]42! 1032 2012-10-21 13:03:21Z letzel
43! minor reformatting
44!
[1]45! Revision 1.1  1998/03/18 20:06:51  raasch
46! Initial revision
47!
48!
49! Description:
50! ------------
51! Set stop flag, if restart is neccessary because of expiring cpu-time or
52! if it is forced by user
53!------------------------------------------------------------------------------!
54
[1320]55    USE control_parameters,                                                    &
56        ONLY:  coupling_mode, dt_restart, end_time, message_string,            &
57               run_description_header, simulated_time, terminate_coupled,      &
58               terminate_coupled_remote, terminate_run,                        &
59               termination_time_needed, time_restart,                          &
60               time_since_reference_point, write_binary
61    USE kinds
[1]62    USE pegrid
63
64    IMPLICIT NONE
65
66
[1320]67    LOGICAL :: terminate_run_l  !:
[1]68
[1320]69    REAL(wp) ::  remaining_time !:
[1]70
[1320]71
[1]72!
73!-- Check remaining CPU-time
74    CALL local_tremain( remaining_time )
75
76!
77!-- If necessary set a flag to stop the model run
78    terminate_run_l = .FALSE.
[1320]79    IF ( remaining_time <= termination_time_needed  .AND.                      &
[1]80         write_binary(1:4) == 'true' )  THEN
81
82       terminate_run_l = .TRUE.
83    ENDIF
84
85#if defined( __parallel )
86!
87!-- Make a logical OR for all processes. Stop the model run if at least
88!-- one processor has reached the time limit.
[622]89    IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
[1320]90    CALL MPI_ALLREDUCE( terminate_run_l, terminate_run, 1, MPI_LOGICAL,        &
[1]91                        MPI_LOR, comm2d, ierr )
92#else
93    terminate_run = terminate_run_l
94#endif
95
96!
97!-- Output that job will be terminated
98    IF ( terminate_run  .AND.  myid == 0 )  THEN
[1320]99       WRITE( message_string, * ) 'run will be terminated because it is ',     &
100                       'running out of job cpu limit & ',                      &
101                       'remaining time:         ', remaining_time, ' s',       &
[274]102                       'termination time needed:', termination_time_needed, ' s'
[247]103       CALL message( 'check_for_restart', 'PA0163', 0, 1, 0, 6, 0 )
[1]104    ENDIF
105
106!
[108]107!-- In case of coupled runs inform the remote model of the termination
108!-- and its reason, provided the remote model has not already been
109!-- informed of another termination reason (terminate_coupled > 0) before,
110!-- or vice versa (terminate_coupled_remote > 0).
[1320]111    IF ( terminate_run .AND. TRIM( coupling_mode ) /= 'uncoupled'  .AND.       &
[110]112         terminate_coupled == 0  .AND.  terminate_coupled_remote == 0 )  THEN
113
[108]114       terminate_coupled = 3
[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
128!
[1]129!-- Set the stop flag also, if restart is forced by user
[1353]130    IF ( time_restart /= 9999999.9_wp  .AND.                                      &
[291]131         time_restart < time_since_reference_point )  THEN
132
[1]133!
134!--    Restart is not neccessary, if the end time of the run (given by
135!--    the user) has been reached
136       IF ( simulated_time < end_time )  THEN
137          terminate_run = .TRUE.
138!
139!--       Increment restart time, if forced by user, otherwise set restart
140!--       time to default (no user restart)
[1353]141          IF ( dt_restart /= 9999999.9_wp )  THEN
[1]142             time_restart = time_restart + dt_restart
143          ELSE
[1353]144             time_restart = 9999999.9_wp
[1]145          ENDIF
146
[1320]147          WRITE( message_string, * ) 'run will be terminated due to user ',    &
148                                  'settings of',                               &
149                                  '&restart_time / dt_restart',                &
[274]150                                  '&new restart time is: ', time_restart, ' s' 
151          CALL message( 'check_for_restart', 'PA0164', 0, 0, 0, 6, 0 )
[247]152 
[108]153!
154!--       In case of coupled runs inform the remote model of the termination
155!--       and its reason, provided the remote model has not already been
156!--       informed of another termination reason (terminate_coupled > 0) before,
157!--       or vice versa (terminate_coupled_remote > 0).
[1320]158          IF ( coupling_mode /= 'uncoupled' .AND. terminate_coupled == 0       &
[206]159               .AND.  terminate_coupled_remote == 0 )  THEN
[110]160
[1353]161             IF ( dt_restart /= 9999999.9_wp )  THEN
[108]162                terminate_coupled = 4
163             ELSE
164                terminate_coupled = 5
165             ENDIF
[222]166#if defined( __parallel )
[667]167             IF ( myid == 0 ) THEN
[1032]168                CALL MPI_SENDRECV( terminate_coupled,        1, MPI_INTEGER,   &
169                                   target_id,  0,                              &
170                                   terminate_coupled_remote, 1, MPI_INTEGER,   &
171                                   target_id,  0,                              &
[667]172                                   comm_inter, status, ierr )   
173             ENDIF
[1320]174             CALL MPI_BCAST( terminate_coupled_remote, 1, MPI_INTEGER, 0,      &
[1032]175                             comm2d, ierr ) 
[222]176#endif
[108]177          ENDIF
178       ELSE
[1353]179          time_restart = 9999999.9_wp
[1]180       ENDIF
181    ENDIF
182
183!
184!-- If the run is stopped, set a flag file which is necessary to initiate
185!-- the start of a continuation run
186    IF ( terminate_run  .AND.  myid == 0 )  THEN
187
188       OPEN ( 90, FILE='CONTINUE_RUN', FORM='FORMATTED' )
189       WRITE ( 90, '(A)' )  TRIM( run_description_header )
190       CLOSE ( 90 )
191
192    ENDIF
193
194
195 END SUBROUTINE check_for_restart
Note: See TracBrowser for help on using the repository browser.