1 | !> @file local_stop.f90 |
---|
2 | !------------------------------------------------------------------------------! |
---|
3 | ! This file is part of the PALM model system. |
---|
4 | ! |
---|
5 | ! PALM is free software: you can redistribute it and/or modify it under the |
---|
6 | ! terms of the GNU General Public License as published by the Free Software |
---|
7 | ! Foundation, either version 3 of the License, or (at your option) any later |
---|
8 | ! 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-2018 Leibniz Universitaet Hannover |
---|
18 | !------------------------------------------------------------------------------! |
---|
19 | ! |
---|
20 | ! Current revisions: |
---|
21 | ! ----------------- |
---|
22 | ! |
---|
23 | ! |
---|
24 | ! Former revisions: |
---|
25 | ! ----------------- |
---|
26 | ! $Id: local_stop.f90 2718 2018-01-02 08:49:38Z scharf $ |
---|
27 | ! Corrected "Former revisions" section |
---|
28 | ! |
---|
29 | ! 2696 2017-12-14 17:12:51Z kanani |
---|
30 | ! Change in file header (GPL part) |
---|
31 | ! |
---|
32 | ! 2371 2017-08-24 13:01:17Z kanani |
---|
33 | ! Removed unnecessary USE of vertical_nesting_mod |
---|
34 | ! |
---|
35 | ! 2365 2017-08-21 14:59:59Z kanani |
---|
36 | ! Vertical nesting implemented (SadiqHuq) |
---|
37 | ! |
---|
38 | ! 2101 2017-01-05 16:42:31Z suehring |
---|
39 | ! |
---|
40 | ! 2000 2016-08-20 18:09:15Z knoop |
---|
41 | ! Forced header and separation lines into 80 columns |
---|
42 | ! |
---|
43 | ! 1804 2016-04-05 16:30:18Z maronga |
---|
44 | ! Removed code for parameter file check (__check) |
---|
45 | ! |
---|
46 | ! 1764 2016-02-28 12:45:19Z raasch |
---|
47 | ! abort with MPI_COMM_WORLD added, nested runs always abort with MPI_ABORT |
---|
48 | ! |
---|
49 | ! 1682 2015-10-07 23:56:08Z knoop |
---|
50 | ! Code annotations made doxygen readable |
---|
51 | ! |
---|
52 | ! 1353 2014-04-08 15:21:23Z heinze |
---|
53 | ! REAL constants provided with KIND-attribute |
---|
54 | ! |
---|
55 | ! 1320 2014-03-20 08:40:49Z raasch |
---|
56 | ! ONLY-attribute added to USE-statements, |
---|
57 | ! revision history before 2012 removed |
---|
58 | ! |
---|
59 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
60 | ! code put under GPL (PALM 3.9) |
---|
61 | ! |
---|
62 | ! 809 2012-01-30 13:32:58Z maronga |
---|
63 | ! Bugfix: replaced .AND. and .NOT. with && and ! in the preprocessor directives |
---|
64 | ! |
---|
65 | ! 807 2012-01-25 11:53:51Z maronga |
---|
66 | ! New cpp directive "__check" implemented which is used by check_namelist_files |
---|
67 | ! |
---|
68 | ! Revision 1.1 2002/12/19 15:46:23 raasch |
---|
69 | ! Initial revision |
---|
70 | ! |
---|
71 | ! |
---|
72 | ! Description: |
---|
73 | ! ------------ |
---|
74 | !> Stop program execution |
---|
75 | !------------------------------------------------------------------------------! |
---|
76 | SUBROUTINE local_stop |
---|
77 | |
---|
78 | |
---|
79 | USE control_parameters, & |
---|
80 | ONLY: abort_mode, coupling_mode, coupling_mode_remote, dt_restart, & |
---|
81 | stop_dt, terminate_coupled, terminate_coupled_remote, & |
---|
82 | terminate_run, time_restart |
---|
83 | |
---|
84 | USE pegrid |
---|
85 | |
---|
86 | USE pmc_interface, & |
---|
87 | ONLY: nested_run |
---|
88 | |
---|
89 | |
---|
90 | #if defined( __parallel ) |
---|
91 | IF ( coupling_mode == 'uncoupled' ) THEN |
---|
92 | IF ( nested_run ) THEN |
---|
93 | ! |
---|
94 | !-- Workaround: If any of the nested model crashes, it aborts the whole |
---|
95 | !-- run with MPI_ABORT, regardless of the reason given by abort_mode |
---|
96 | CALL MPI_ABORT( MPI_COMM_WORLD, 9999, ierr ) |
---|
97 | ELSE |
---|
98 | IF ( abort_mode == 1 ) THEN |
---|
99 | CALL MPI_FINALIZE( ierr ) |
---|
100 | STOP |
---|
101 | ELSEIF ( abort_mode == 2 ) THEN |
---|
102 | CALL MPI_ABORT( comm2d, 9999, ierr ) |
---|
103 | ELSEIF ( abort_mode == 3 ) THEN |
---|
104 | CALL MPI_ABORT( MPI_COMM_WORLD, 9999, ierr ) |
---|
105 | ENDIF |
---|
106 | ENDIF |
---|
107 | ELSEIF ( coupling_mode(1:8) == 'vnested_' ) THEN |
---|
108 | |
---|
109 | PRINT*, '+++ local_stop:' |
---|
110 | PRINT*, ' model "', TRIM( coupling_mode ), '" terminated' |
---|
111 | ! |
---|
112 | !-- Abort both coarse and fine grid |
---|
113 | CALL MPI_ABORT( MPI_COMM_WORLD, 9999, ierr ) |
---|
114 | ELSE |
---|
115 | |
---|
116 | SELECT CASE ( terminate_coupled_remote ) |
---|
117 | |
---|
118 | CASE ( 0 ) |
---|
119 | IF ( myid == 0 ) THEN |
---|
120 | PRINT*, '+++ local_stop:' |
---|
121 | PRINT*, ' local model "', TRIM( coupling_mode ), & |
---|
122 | '" stops now' |
---|
123 | ENDIF |
---|
124 | ! |
---|
125 | !-- Inform the remote model of the termination and its reason, provided |
---|
126 | !-- the remote model has not already been informed of another |
---|
127 | !-- termination reason (terminate_coupled > 0) before. |
---|
128 | IF ( terminate_coupled == 0 ) THEN |
---|
129 | terminate_coupled = 1 |
---|
130 | IF ( myid == 0 ) THEN |
---|
131 | CALL MPI_SENDRECV( & |
---|
132 | terminate_coupled, 1, MPI_INTEGER, target_id, 0, & |
---|
133 | terminate_coupled_remote, 1, MPI_INTEGER, target_id, 0, & |
---|
134 | comm_inter, status, ierr ) |
---|
135 | ENDIF |
---|
136 | CALL MPI_BCAST( terminate_coupled_remote, 1, MPI_REAL, 0, comm2d, ierr) |
---|
137 | ENDIF |
---|
138 | CALL MPI_FINALIZE( ierr ) |
---|
139 | STOP |
---|
140 | |
---|
141 | CASE ( 1 ) |
---|
142 | IF ( myid == 0 ) THEN |
---|
143 | PRINT*, '+++ local_stop:' |
---|
144 | PRINT*, ' remote model "', TRIM( coupling_mode_remote ), & |
---|
145 | '" stopped' |
---|
146 | ENDIF |
---|
147 | CALL MPI_FINALIZE( ierr ) |
---|
148 | STOP |
---|
149 | |
---|
150 | CASE ( 2 ) |
---|
151 | IF ( myid == 0 ) THEN |
---|
152 | PRINT*, '+++ local_stop:' |
---|
153 | PRINT*, ' remote model "', TRIM( coupling_mode_remote ), & |
---|
154 | '" terminated' |
---|
155 | PRINT*, ' with stop_dt = .T.' |
---|
156 | ENDIF |
---|
157 | stop_dt = .TRUE. |
---|
158 | |
---|
159 | CASE ( 3 ) |
---|
160 | IF ( myid == 0 ) THEN |
---|
161 | PRINT*, '+++ local_stop:' |
---|
162 | PRINT*, ' remote model "', TRIM( coupling_mode_remote ), & |
---|
163 | '" terminated' |
---|
164 | PRINT*, ' with terminate_run = .T. (CPU-time limit)' |
---|
165 | ENDIF |
---|
166 | terminate_run = .TRUE. |
---|
167 | |
---|
168 | CASE ( 4 ) |
---|
169 | IF ( myid == 0 ) THEN |
---|
170 | PRINT*, '+++ local_stop:' |
---|
171 | PRINT*, ' remote model "', TRIM( coupling_mode_remote ), & |
---|
172 | '" terminated' |
---|
173 | PRINT*, ' with terminate_run = .T. (restart)' |
---|
174 | ENDIF |
---|
175 | terminate_run = .TRUE. |
---|
176 | time_restart = time_restart + dt_restart |
---|
177 | |
---|
178 | CASE ( 5 ) |
---|
179 | IF ( myid == 0 ) THEN |
---|
180 | PRINT*, '+++ local_stop:' |
---|
181 | PRINT*, ' remote model "', TRIM( coupling_mode_remote ), & |
---|
182 | '" terminated' |
---|
183 | PRINT*, ' with terminate_run = .T. (single restart)' |
---|
184 | ENDIF |
---|
185 | terminate_run = .TRUE. |
---|
186 | time_restart = 9999999.9_wp |
---|
187 | |
---|
188 | END SELECT |
---|
189 | |
---|
190 | ENDIF |
---|
191 | |
---|
192 | #else |
---|
193 | |
---|
194 | STOP |
---|
195 | |
---|
196 | #endif |
---|
197 | |
---|
198 | END SUBROUTINE local_stop |
---|