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-2020 Leibniz Universitaet Hannover |
---|
18 | !------------------------------------------------------------------------------! |
---|
19 | ! |
---|
20 | ! Current revisions: |
---|
21 | ! ----------------- |
---|
22 | ! |
---|
23 | ! |
---|
24 | ! Former revisions: |
---|
25 | ! ----------------- |
---|
26 | ! $Id: local_stop.f90 4564 2020-06-12 14:03:36Z suehring $ |
---|
27 | ! Vertical nesting method of Huq et al. (2019) removed |
---|
28 | ! |
---|
29 | ! 4444 2020-03-05 15:59:50Z raasch |
---|
30 | ! bugfix: misplaced cpp-directive moved |
---|
31 | ! |
---|
32 | ! 4360 2020-01-07 11:25:50Z suehring |
---|
33 | ! Corrected "Former revisions" section |
---|
34 | ! |
---|
35 | ! 3655 2019-01-07 16:51:22Z knoop |
---|
36 | ! Added an empty output string to stop keywords to clean up job protocol |
---|
37 | ! |
---|
38 | ! Revision 1.1 2002/12/19 15:46:23 raasch |
---|
39 | ! Initial revision |
---|
40 | ! |
---|
41 | ! |
---|
42 | ! Description: |
---|
43 | ! ------------ |
---|
44 | !> Stop program execution |
---|
45 | !------------------------------------------------------------------------------! |
---|
46 | SUBROUTINE local_stop |
---|
47 | |
---|
48 | #if defined( __parallel ) |
---|
49 | |
---|
50 | USE control_parameters, & |
---|
51 | ONLY: abort_mode, coupling_mode, coupling_mode_remote, dt_restart, & |
---|
52 | stop_dt, terminate_coupled, terminate_coupled_remote, & |
---|
53 | terminate_run, time_restart |
---|
54 | |
---|
55 | USE pegrid |
---|
56 | |
---|
57 | USE pmc_interface, & |
---|
58 | ONLY: nested_run |
---|
59 | |
---|
60 | |
---|
61 | IF ( coupling_mode == 'uncoupled' ) THEN |
---|
62 | |
---|
63 | IF ( nested_run ) THEN |
---|
64 | ! |
---|
65 | !-- Workaround: If any of the nested model crashes, it aborts the whole |
---|
66 | !-- run with MPI_ABORT, regardless of the reason given by abort_mode |
---|
67 | CALL MPI_ABORT( MPI_COMM_WORLD, 9999, ierr ) |
---|
68 | ELSE |
---|
69 | IF ( abort_mode == 1 ) THEN |
---|
70 | CALL MPI_FINALIZE( ierr ) |
---|
71 | STOP 1 |
---|
72 | ELSEIF ( abort_mode == 2 ) THEN |
---|
73 | CALL MPI_ABORT( comm2d, 9999, ierr ) |
---|
74 | ELSEIF ( abort_mode == 3 ) THEN |
---|
75 | CALL MPI_ABORT( MPI_COMM_WORLD, 9999, ierr ) |
---|
76 | ENDIF |
---|
77 | ENDIF |
---|
78 | |
---|
79 | ELSE |
---|
80 | |
---|
81 | SELECT CASE ( terminate_coupled_remote ) |
---|
82 | |
---|
83 | CASE ( 0 ) |
---|
84 | IF ( myid == 0 ) THEN |
---|
85 | PRINT*, '+++ local_stop:' |
---|
86 | PRINT*, ' local model "', TRIM( coupling_mode ), & |
---|
87 | '" stops now' |
---|
88 | ENDIF |
---|
89 | ! |
---|
90 | !-- Inform the remote model of the termination and its reason, provided |
---|
91 | !-- the remote model has not already been informed of another |
---|
92 | !-- termination reason (terminate_coupled > 0) before. |
---|
93 | IF ( terminate_coupled == 0 ) THEN |
---|
94 | terminate_coupled = 1 |
---|
95 | IF ( myid == 0 ) THEN |
---|
96 | CALL MPI_SENDRECV( & |
---|
97 | terminate_coupled, 1, MPI_INTEGER, target_id, 0, & |
---|
98 | terminate_coupled_remote, 1, MPI_INTEGER, target_id, 0, & |
---|
99 | comm_inter, status, ierr ) |
---|
100 | ENDIF |
---|
101 | CALL MPI_BCAST( terminate_coupled_remote, 1, MPI_REAL, 0, comm2d, ierr) |
---|
102 | ENDIF |
---|
103 | CALL MPI_FINALIZE( ierr ) |
---|
104 | STOP 1 |
---|
105 | |
---|
106 | CASE ( 1 ) |
---|
107 | IF ( myid == 0 ) THEN |
---|
108 | PRINT*, '+++ local_stop:' |
---|
109 | PRINT*, ' remote model "', TRIM( coupling_mode_remote ), & |
---|
110 | '" stopped' |
---|
111 | ENDIF |
---|
112 | CALL MPI_FINALIZE( ierr ) |
---|
113 | STOP 1 |
---|
114 | |
---|
115 | CASE ( 2 ) |
---|
116 | IF ( myid == 0 ) THEN |
---|
117 | PRINT*, '+++ local_stop:' |
---|
118 | PRINT*, ' remote model "', TRIM( coupling_mode_remote ), & |
---|
119 | '" terminated' |
---|
120 | PRINT*, ' with stop_dt = .T.' |
---|
121 | ENDIF |
---|
122 | stop_dt = .TRUE. |
---|
123 | |
---|
124 | CASE ( 3 ) |
---|
125 | IF ( myid == 0 ) THEN |
---|
126 | PRINT*, '+++ local_stop:' |
---|
127 | PRINT*, ' remote model "', TRIM( coupling_mode_remote ), & |
---|
128 | '" terminated' |
---|
129 | PRINT*, ' with terminate_run = .T. (CPU-time limit)' |
---|
130 | ENDIF |
---|
131 | terminate_run = .TRUE. |
---|
132 | |
---|
133 | CASE ( 4 ) |
---|
134 | IF ( myid == 0 ) THEN |
---|
135 | PRINT*, '+++ local_stop:' |
---|
136 | PRINT*, ' remote model "', TRIM( coupling_mode_remote ), & |
---|
137 | '" terminated' |
---|
138 | PRINT*, ' with terminate_run = .T. (restart)' |
---|
139 | ENDIF |
---|
140 | terminate_run = .TRUE. |
---|
141 | time_restart = time_restart + dt_restart |
---|
142 | |
---|
143 | CASE ( 5 ) |
---|
144 | IF ( myid == 0 ) THEN |
---|
145 | PRINT*, '+++ local_stop:' |
---|
146 | PRINT*, ' remote model "', TRIM( coupling_mode_remote ), & |
---|
147 | '" terminated' |
---|
148 | PRINT*, ' with terminate_run = .T. (single restart)' |
---|
149 | ENDIF |
---|
150 | terminate_run = .TRUE. |
---|
151 | time_restart = 9999999.9_wp |
---|
152 | |
---|
153 | END SELECT |
---|
154 | |
---|
155 | ENDIF |
---|
156 | |
---|
157 | #else |
---|
158 | |
---|
159 | STOP 1 |
---|
160 | |
---|
161 | #endif |
---|
162 | |
---|
163 | END SUBROUTINE local_stop |
---|