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