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

Last change on this file since 1328 was 1321, checked in by raasch, 11 years ago

last commit documented

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