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

Last change on this file since 1320 was 1320, checked in by raasch, 10 years ago

ONLY-attribute added to USE-statements,
kind-parameters added to all INTEGER and REAL declaration statements,
kinds are defined in new module kinds,
old module precision_kind is removed,
revision history before 2012 removed,
comment fields (!:) to be used for variable explanations added to all variable declaration statements

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