1 | SUBROUTINE check_for_restart |
---|
2 | |
---|
3 | !------------------------------------------------------------------------------! |
---|
4 | ! Current revisions: |
---|
5 | ! ----------------- |
---|
6 | ! |
---|
7 | ! |
---|
8 | ! Former revisions: |
---|
9 | ! ----------------- |
---|
10 | ! $Id: check_for_restart.f90 668 2010-12-23 13:22:58Z 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, ierr) |
---|
106 | #endif |
---|
107 | ENDIF |
---|
108 | |
---|
109 | ! |
---|
110 | !-- Set the stop flag also, if restart is forced by user |
---|
111 | IF ( time_restart /= 9999999.9 .AND. & |
---|
112 | time_restart < time_since_reference_point ) THEN |
---|
113 | |
---|
114 | ! |
---|
115 | !-- Restart is not neccessary, if the end time of the run (given by |
---|
116 | !-- the user) has been reached |
---|
117 | IF ( simulated_time < end_time ) THEN |
---|
118 | terminate_run = .TRUE. |
---|
119 | ! |
---|
120 | !-- Increment restart time, if forced by user, otherwise set restart |
---|
121 | !-- time to default (no user restart) |
---|
122 | IF ( dt_restart /= 9999999.9 ) THEN |
---|
123 | time_restart = time_restart + dt_restart |
---|
124 | ELSE |
---|
125 | time_restart = 9999999.9 |
---|
126 | ENDIF |
---|
127 | |
---|
128 | WRITE( message_string, * ) 'run will be terminated due to user ', & |
---|
129 | 'settings of', & |
---|
130 | '&restart_time / dt_restart', & |
---|
131 | '&new restart time is: ', time_restart, ' s' |
---|
132 | CALL message( 'check_for_restart', 'PA0164', 0, 0, 0, 6, 0 ) |
---|
133 | |
---|
134 | ! |
---|
135 | !-- In case of coupled runs inform the remote model of the termination |
---|
136 | !-- and its reason, provided the remote model has not already been |
---|
137 | !-- informed of another termination reason (terminate_coupled > 0) before, |
---|
138 | !-- or vice versa (terminate_coupled_remote > 0). |
---|
139 | IF ( coupling_mode /= 'uncoupled' .AND. terminate_coupled == 0 & |
---|
140 | .AND. terminate_coupled_remote == 0 ) THEN |
---|
141 | |
---|
142 | IF ( dt_restart /= 9999999.9 ) THEN |
---|
143 | terminate_coupled = 4 |
---|
144 | ELSE |
---|
145 | terminate_coupled = 5 |
---|
146 | ENDIF |
---|
147 | #if defined( __parallel ) |
---|
148 | IF ( myid == 0 ) THEN |
---|
149 | CALL MPI_SENDRECV( terminate_coupled, 1, MPI_INTEGER, & |
---|
150 | target_id, 0, & |
---|
151 | terminate_coupled_remote, 1, MPI_INTEGER, & |
---|
152 | target_id, 0, & |
---|
153 | comm_inter, status, ierr ) |
---|
154 | ENDIF |
---|
155 | CALL MPI_BCAST( terminate_coupled_remote, 1, MPI_INTEGER, 0, comm2d, ierr) |
---|
156 | |
---|
157 | #endif |
---|
158 | ENDIF |
---|
159 | ELSE |
---|
160 | time_restart = 9999999.9 |
---|
161 | ENDIF |
---|
162 | ENDIF |
---|
163 | |
---|
164 | ! |
---|
165 | !-- If the run is stopped, set a flag file which is necessary to initiate |
---|
166 | !-- the start of a continuation run |
---|
167 | IF ( terminate_run .AND. myid == 0 ) THEN |
---|
168 | |
---|
169 | OPEN ( 90, FILE='CONTINUE_RUN', FORM='FORMATTED' ) |
---|
170 | WRITE ( 90, '(A)' ) TRIM( run_description_header ) |
---|
171 | CLOSE ( 90 ) |
---|
172 | |
---|
173 | ENDIF |
---|
174 | |
---|
175 | |
---|
176 | END SUBROUTINE check_for_restart |
---|