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

Last change on this file since 623 was 623, checked in by raasch, 14 years ago

last commit documented

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