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

Last change on this file since 281 was 274, checked in by heinze, 16 years ago

Indentation of the message calls corrected

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