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 terms of the GNU General |
---|
6 | ! Public License as published by the Free Software Foundation, either version 3 of the License, or |
---|
7 | ! (at your option) any later version. |
---|
8 | ! |
---|
9 | ! PALM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the |
---|
10 | ! implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
---|
11 | ! Public License for more details. |
---|
12 | ! |
---|
13 | ! You should have received a copy of the GNU General Public License along with PALM. If not, see |
---|
14 | ! <http://www.gnu.org/licenses/>. |
---|
15 | ! |
---|
16 | ! Copyright 1997-2020 Leibniz Universitaet Hannover |
---|
17 | !--------------------------------------------------------------------------------------------------! |
---|
18 | ! |
---|
19 | ! Current revisions: |
---|
20 | ! ----------------- |
---|
21 | ! |
---|
22 | ! |
---|
23 | ! Former revisions: |
---|
24 | ! ----------------- |
---|
25 | ! $Id: local_stop.f90 4677 2020-09-14 07:55:28Z oliver.maas $ |
---|
26 | ! file re-formatted to follow the PALM coding standard |
---|
27 | ! |
---|
28 | ! 4564 2020-06-12 14:03:36Z raasch |
---|
29 | ! Vertical nesting method of Huq et al. (2019) removed |
---|
30 | ! |
---|
31 | ! 4444 2020-03-05 15:59:50Z raasch |
---|
32 | ! bugfix: misplaced cpp-directive moved |
---|
33 | ! |
---|
34 | ! 4360 2020-01-07 11:25:50Z suehring |
---|
35 | ! Corrected "Former revisions" section |
---|
36 | ! |
---|
37 | ! 3655 2019-01-07 16:51:22Z knoop |
---|
38 | ! Added an empty output string to stop keywords to clean up job protocol |
---|
39 | ! |
---|
40 | ! Revision 1.1 2002/12/19 15:46:23 raasch |
---|
41 | ! Initial revision |
---|
42 | ! |
---|
43 | ! |
---|
44 | ! Description: |
---|
45 | ! ------------ |
---|
46 | !> Stop program execution |
---|
47 | !--------------------------------------------------------------------------------------------------! |
---|
48 | SUBROUTINE local_stop |
---|
49 | |
---|
50 | #if defined( __parallel ) |
---|
51 | |
---|
52 | USE control_parameters, & |
---|
53 | ONLY: abort_mode, coupling_mode, coupling_mode_remote, dt_restart, stop_dt, & |
---|
54 | terminate_coupled, terminate_coupled_remote, terminate_run, time_restart |
---|
55 | |
---|
56 | USE pegrid |
---|
57 | |
---|
58 | USE pmc_interface, & |
---|
59 | ONLY: nested_run |
---|
60 | |
---|
61 | |
---|
62 | IF ( coupling_mode == 'uncoupled' ) THEN |
---|
63 | |
---|
64 | IF ( nested_run ) THEN |
---|
65 | ! |
---|
66 | !-- Workaround: If any of the nested model crashes, it aborts the whole run with MPI_ABORT, |
---|
67 | !-- regardless of the reason given by abort_mode |
---|
68 | CALL MPI_ABORT( MPI_COMM_WORLD, 9999, ierr ) |
---|
69 | ELSE |
---|
70 | IF ( abort_mode == 1 ) THEN |
---|
71 | CALL MPI_FINALIZE( ierr ) |
---|
72 | STOP 1 |
---|
73 | ELSEIF ( abort_mode == 2 ) THEN |
---|
74 | CALL MPI_ABORT( comm2d, 9999, ierr ) |
---|
75 | ELSEIF ( abort_mode == 3 ) THEN |
---|
76 | CALL MPI_ABORT( MPI_COMM_WORLD, 9999, ierr ) |
---|
77 | ENDIF |
---|
78 | ENDIF |
---|
79 | |
---|
80 | ELSE |
---|
81 | |
---|
82 | SELECT CASE ( terminate_coupled_remote ) |
---|
83 | |
---|
84 | CASE ( 0 ) |
---|
85 | IF ( myid == 0 ) THEN |
---|
86 | PRINT*, '+++ local_stop:' |
---|
87 | PRINT*, ' local model "', TRIM( coupling_mode ), '" stops now' |
---|
88 | ENDIF |
---|
89 | ! |
---|
90 | !-- Inform the remote model of the termination and its reason, provided the remote model |
---|
91 | !-- has not already been informed of another termination reason (terminate_coupled > 0) |
---|
92 | !-- 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 ), '" 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 ), '" terminated' |
---|
118 | PRINT*, ' with stop_dt = .T.' |
---|
119 | ENDIF |
---|
120 | stop_dt = .TRUE. |
---|
121 | |
---|
122 | CASE ( 3 ) |
---|
123 | IF ( myid == 0 ) THEN |
---|
124 | PRINT*, '+++ local_stop:' |
---|
125 | PRINT*, ' remote model "', TRIM( coupling_mode_remote ), '" terminated' |
---|
126 | PRINT*, ' with terminate_run = .T. (CPU-time limit)' |
---|
127 | ENDIF |
---|
128 | terminate_run = .TRUE. |
---|
129 | |
---|
130 | CASE ( 4 ) |
---|
131 | IF ( myid == 0 ) THEN |
---|
132 | PRINT*, '+++ local_stop:' |
---|
133 | PRINT*, ' remote model "', TRIM( coupling_mode_remote ), '" terminated' |
---|
134 | PRINT*, ' with terminate_run = .T. (restart)' |
---|
135 | ENDIF |
---|
136 | terminate_run = .TRUE. |
---|
137 | time_restart = time_restart + dt_restart |
---|
138 | |
---|
139 | CASE ( 5 ) |
---|
140 | IF ( myid == 0 ) THEN |
---|
141 | PRINT*, '+++ local_stop:' |
---|
142 | PRINT*, ' remote model "', TRIM( coupling_mode_remote ), '" terminated' |
---|
143 | PRINT*, ' with terminate_run = .T. (single restart)' |
---|
144 | ENDIF |
---|
145 | terminate_run = .TRUE. |
---|
146 | time_restart = 9999999.9_wp |
---|
147 | |
---|
148 | END SELECT |
---|
149 | |
---|
150 | ENDIF |
---|
151 | |
---|
152 | #else |
---|
153 | |
---|
154 | STOP 1 |
---|
155 | |
---|
156 | #endif |
---|
157 | |
---|
158 | END SUBROUTINE local_stop |
---|