1 | SUBROUTINE check_for_restart |
---|
2 | |
---|
3 | !--------------------------------------------------------------------------------! |
---|
4 | ! This file is part of PALM. |
---|
5 | ! |
---|
6 | ! PALM is free software: you can redistribute it and/or modify it under the terms |
---|
7 | ! of the GNU General Public License as published by the Free Software Foundation, |
---|
8 | ! either version 3 of the License, or (at your option) any later version. |
---|
9 | ! |
---|
10 | ! PALM is distributed in the hope that it will be useful, but WITHOUT ANY |
---|
11 | ! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
---|
12 | ! A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
---|
13 | ! |
---|
14 | ! You should have received a copy of the GNU General Public License along with |
---|
15 | ! PALM. If not, see <http://www.gnu.org/licenses/>. |
---|
16 | ! |
---|
17 | ! Copyright 1997-2014 Leibniz Universitaet Hannover |
---|
18 | !--------------------------------------------------------------------------------! |
---|
19 | ! |
---|
20 | ! Current revisions: |
---|
21 | ! ----------------- |
---|
22 | ! |
---|
23 | ! |
---|
24 | ! Former revisions: |
---|
25 | ! ----------------- |
---|
26 | ! $Id: check_for_restart.f90 1354 2014-04-08 15:22:57Z witha $ |
---|
27 | ! |
---|
28 | ! 1353 2014-04-08 15:21:23Z heinze |
---|
29 | ! REAL constants provided with KIND-attribute |
---|
30 | ! |
---|
31 | ! 1320 2014-03-20 08:40:49Z raasch |
---|
32 | ! ONLY-attribute added to USE-statements, |
---|
33 | ! kind-parameters added to all INTEGER and REAL declaration statements, |
---|
34 | ! kinds are defined in new module kinds, |
---|
35 | ! revision history before 2012 removed, |
---|
36 | ! comment fields (!:) to be used for variable explanations added to |
---|
37 | ! all variable declaration statements |
---|
38 | ! |
---|
39 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
40 | ! code put under GPL (PALM 3.9) |
---|
41 | ! |
---|
42 | ! 1032 2012-10-21 13:03:21Z letzel |
---|
43 | ! minor reformatting |
---|
44 | ! |
---|
45 | ! Revision 1.1 1998/03/18 20:06:51 raasch |
---|
46 | ! Initial revision |
---|
47 | ! |
---|
48 | ! |
---|
49 | ! Description: |
---|
50 | ! ------------ |
---|
51 | ! Set stop flag, if restart is neccessary because of expiring cpu-time or |
---|
52 | ! if it is forced by user |
---|
53 | !------------------------------------------------------------------------------! |
---|
54 | |
---|
55 | USE control_parameters, & |
---|
56 | ONLY: coupling_mode, dt_restart, end_time, message_string, & |
---|
57 | run_description_header, simulated_time, terminate_coupled, & |
---|
58 | terminate_coupled_remote, terminate_run, & |
---|
59 | termination_time_needed, time_restart, & |
---|
60 | time_since_reference_point, write_binary |
---|
61 | USE kinds |
---|
62 | USE pegrid |
---|
63 | |
---|
64 | IMPLICIT NONE |
---|
65 | |
---|
66 | |
---|
67 | LOGICAL :: terminate_run_l !: |
---|
68 | |
---|
69 | REAL(wp) :: remaining_time !: |
---|
70 | |
---|
71 | |
---|
72 | ! |
---|
73 | !-- Check remaining CPU-time |
---|
74 | CALL local_tremain( remaining_time ) |
---|
75 | |
---|
76 | ! |
---|
77 | !-- If necessary set a flag to stop the model run |
---|
78 | terminate_run_l = .FALSE. |
---|
79 | IF ( remaining_time <= termination_time_needed .AND. & |
---|
80 | write_binary(1:4) == 'true' ) THEN |
---|
81 | |
---|
82 | terminate_run_l = .TRUE. |
---|
83 | ENDIF |
---|
84 | |
---|
85 | #if defined( __parallel ) |
---|
86 | ! |
---|
87 | !-- Make a logical OR for all processes. Stop the model run if at least |
---|
88 | !-- one processor has reached the time limit. |
---|
89 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
90 | CALL MPI_ALLREDUCE( terminate_run_l, terminate_run, 1, MPI_LOGICAL, & |
---|
91 | MPI_LOR, comm2d, ierr ) |
---|
92 | #else |
---|
93 | terminate_run = terminate_run_l |
---|
94 | #endif |
---|
95 | |
---|
96 | ! |
---|
97 | !-- Output that job will be terminated |
---|
98 | IF ( terminate_run .AND. myid == 0 ) THEN |
---|
99 | WRITE( message_string, * ) 'run will be terminated because it is ', & |
---|
100 | 'running out of job cpu limit & ', & |
---|
101 | 'remaining time: ', remaining_time, ' s', & |
---|
102 | 'termination time needed:', termination_time_needed, ' s' |
---|
103 | CALL message( 'check_for_restart', 'PA0163', 0, 1, 0, 6, 0 ) |
---|
104 | ENDIF |
---|
105 | |
---|
106 | ! |
---|
107 | !-- In case of coupled runs inform the remote model of the termination |
---|
108 | !-- and its reason, provided the remote model has not already been |
---|
109 | !-- informed of another termination reason (terminate_coupled > 0) before, |
---|
110 | !-- or vice versa (terminate_coupled_remote > 0). |
---|
111 | IF ( terminate_run .AND. TRIM( coupling_mode ) /= 'uncoupled' .AND. & |
---|
112 | terminate_coupled == 0 .AND. terminate_coupled_remote == 0 ) THEN |
---|
113 | |
---|
114 | terminate_coupled = 3 |
---|
115 | #if defined( __parallel ) |
---|
116 | IF ( myid == 0 ) THEN |
---|
117 | CALL MPI_SENDRECV( terminate_coupled, 1, MPI_INTEGER, & |
---|
118 | target_id, 0, & |
---|
119 | terminate_coupled_remote, 1, MPI_INTEGER, & |
---|
120 | target_id, 0, & |
---|
121 | comm_inter, status, ierr ) |
---|
122 | ENDIF |
---|
123 | CALL MPI_BCAST( terminate_coupled_remote, 1, MPI_INTEGER, 0, comm2d, & |
---|
124 | ierr ) |
---|
125 | #endif |
---|
126 | ENDIF |
---|
127 | |
---|
128 | ! |
---|
129 | !-- Set the stop flag also, if restart is forced by user |
---|
130 | IF ( time_restart /= 9999999.9_wp .AND. & |
---|
131 | time_restart < time_since_reference_point ) THEN |
---|
132 | |
---|
133 | ! |
---|
134 | !-- Restart is not neccessary, if the end time of the run (given by |
---|
135 | !-- the user) has been reached |
---|
136 | IF ( simulated_time < end_time ) THEN |
---|
137 | terminate_run = .TRUE. |
---|
138 | ! |
---|
139 | !-- Increment restart time, if forced by user, otherwise set restart |
---|
140 | !-- time to default (no user restart) |
---|
141 | IF ( dt_restart /= 9999999.9_wp ) THEN |
---|
142 | time_restart = time_restart + dt_restart |
---|
143 | ELSE |
---|
144 | time_restart = 9999999.9_wp |
---|
145 | ENDIF |
---|
146 | |
---|
147 | WRITE( message_string, * ) 'run will be terminated due to user ', & |
---|
148 | 'settings of', & |
---|
149 | '&restart_time / dt_restart', & |
---|
150 | '&new restart time is: ', time_restart, ' s' |
---|
151 | CALL message( 'check_for_restart', 'PA0164', 0, 0, 0, 6, 0 ) |
---|
152 | |
---|
153 | ! |
---|
154 | !-- In case of coupled runs inform the remote model of the termination |
---|
155 | !-- and its reason, provided the remote model has not already been |
---|
156 | !-- informed of another termination reason (terminate_coupled > 0) before, |
---|
157 | !-- or vice versa (terminate_coupled_remote > 0). |
---|
158 | IF ( coupling_mode /= 'uncoupled' .AND. terminate_coupled == 0 & |
---|
159 | .AND. terminate_coupled_remote == 0 ) THEN |
---|
160 | |
---|
161 | IF ( dt_restart /= 9999999.9_wp ) THEN |
---|
162 | terminate_coupled = 4 |
---|
163 | ELSE |
---|
164 | terminate_coupled = 5 |
---|
165 | ENDIF |
---|
166 | #if defined( __parallel ) |
---|
167 | IF ( myid == 0 ) THEN |
---|
168 | CALL MPI_SENDRECV( terminate_coupled, 1, MPI_INTEGER, & |
---|
169 | target_id, 0, & |
---|
170 | terminate_coupled_remote, 1, MPI_INTEGER, & |
---|
171 | target_id, 0, & |
---|
172 | comm_inter, status, ierr ) |
---|
173 | ENDIF |
---|
174 | CALL MPI_BCAST( terminate_coupled_remote, 1, MPI_INTEGER, 0, & |
---|
175 | comm2d, ierr ) |
---|
176 | #endif |
---|
177 | ENDIF |
---|
178 | ELSE |
---|
179 | time_restart = 9999999.9_wp |
---|
180 | ENDIF |
---|
181 | ENDIF |
---|
182 | |
---|
183 | ! |
---|
184 | !-- If the run is stopped, set a flag file which is necessary to initiate |
---|
185 | !-- the start of a continuation run |
---|
186 | IF ( terminate_run .AND. myid == 0 ) THEN |
---|
187 | |
---|
188 | OPEN ( 90, FILE='CONTINUE_RUN', FORM='FORMATTED' ) |
---|
189 | WRITE ( 90, '(A)' ) TRIM( run_description_header ) |
---|
190 | CLOSE ( 90 ) |
---|
191 | |
---|
192 | ENDIF |
---|
193 | |
---|
194 | |
---|
195 | END SUBROUTINE check_for_restart |
---|