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

Last change on this file since 1034 was 1033, checked in by letzel, 12 years ago

last commit documented

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