source: palm/trunk/SOURCE/local_stop.f90 @ 2365

Last change on this file since 2365 was 2365, checked in by kanani, 4 years ago

Vertical nesting implemented (SadiqHuq?)

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