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

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

code has been put under the GNU General Public License (v3)

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