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