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

Last change on this file since 325 was 291, checked in by raasch, 16 years ago

changes for coupling with independent precursor runs; z_i calculation with Sullivan criterion

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