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

Last change on this file since 3540 was 3312, checked in by knoop, 6 years ago

Added proper exit code to PALM and fixed exit code handling by palmbuild and palmrun

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