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

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