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

Last change on this file since 1802 was 1765, checked in by raasch, 9 years ago

last commit documented

  • Property svn:keywords set to Id
File size: 5.7 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 terms
6! of the GNU General Public License as published by the Free Software Foundation,
7! either version 3 of the License, or (at your option) any later version.
8!
9! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
10! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
12!
13! You should have received a copy of the GNU General Public License along with
14! PALM. If not, see <http://www.gnu.org/licenses/>.
15!
16! Copyright 1997-2014 Leibniz Universitaet Hannover
17!--------------------------------------------------------------------------------!
18!
19! Current revisions:
20! -----------------
21!
22!
23! Former revisions:
24! -----------------
25! $Id: local_stop.f90 1765 2016-02-28 13:30:40Z raasch $
26!
27! 1764 2016-02-28 12:45:19Z raasch
28! abort with MPI_COMM_WORLD added, nested runs always abort with MPI_ABORT
29!
30! 1682 2015-10-07 23:56:08Z knoop
31! Code annotations made doxygen readable
32!
33! 1353 2014-04-08 15:21:23Z heinze
34! REAL constants provided with KIND-attribute
35!
36! 1320 2014-03-20 08:40:49Z raasch
37! ONLY-attribute added to USE-statements,
38! revision history before 2012 removed
39!
40! 1036 2012-10-22 13:43:42Z raasch
41! code put under GPL (PALM 3.9)
42!
43! 809 2012-01-30 13:32:58Z maronga
44! Bugfix: replaced .AND. and .NOT. with && and ! in the preprocessor directives
45!
46! 807 2012-01-25 11:53:51Z maronga
47! New cpp directive "__check" implemented which is used by check_namelist_files
48!
49! Revision 1.1  2002/12/19 15:46:23  raasch
50! Initial revision
51!
52!
53! Description:
54! ------------
55!> Stop program execution
56!------------------------------------------------------------------------------!
57 SUBROUTINE local_stop
58 
59
60    USE control_parameters,                                                    &
61        ONLY:  abort_mode, coupling_mode, coupling_mode_remote, dt_restart,    &
62               stop_dt, terminate_coupled, terminate_coupled_remote,           &
63               terminate_run, time_restart
64
65    USE pegrid
66
67    USE pmc_interface,                                                         &
68        ONLY:  nested_run
69
70#if defined( __parallel ) && ! defined ( __check )
71    IF ( coupling_mode == 'uncoupled' )  THEN
72       IF ( nested_run )  THEN
73!
74!--       Workaround: If any of the nested model crashes, it aborts the whole
75!--       run with MPI_ABORT, regardless of the reason given by abort_mode
76          CALL MPI_ABORT( MPI_COMM_WORLD, 9999, ierr )
77       ELSE
78          IF ( abort_mode == 1 )  THEN
79             CALL MPI_FINALIZE( ierr )
80             STOP
81          ELSEIF ( abort_mode == 2 )  THEN
82             CALL MPI_ABORT( comm2d, 9999, ierr )
83          ELSEIF ( abort_mode == 3 )  THEN
84             CALL MPI_ABORT( MPI_COMM_WORLD, 9999, ierr )
85          ENDIF
86       ENDIF
87    ELSE
88
89       SELECT CASE ( terminate_coupled_remote )
90
91          CASE ( 0 )
92             IF ( myid == 0 )  THEN
93                PRINT*, '+++ local_stop:'
94                PRINT*, '    local model "', TRIM( coupling_mode ), &
95                     '" stops now'
96             ENDIF
97!
98!--          Inform the remote model of the termination and its reason, provided
99!--          the remote model has not already been informed of another
100!--          termination reason (terminate_coupled > 0) before.
101             IF ( terminate_coupled == 0 )  THEN
102                terminate_coupled = 1
103                IF ( myid == 0 ) THEN
104                   CALL MPI_SENDRECV( &
105                        terminate_coupled,        1, MPI_INTEGER, target_id,  0, &
106                        terminate_coupled_remote, 1, MPI_INTEGER, target_id,  0, &
107                        comm_inter, status, ierr )
108                ENDIF
109                CALL MPI_BCAST( terminate_coupled_remote, 1, MPI_REAL, 0, comm2d, ierr)
110             ENDIF
111             CALL MPI_FINALIZE( ierr )
112             STOP
113
114          CASE ( 1 )
115             IF ( myid == 0 )  THEN
116                PRINT*, '+++ local_stop:'
117                PRINT*, '    remote model "', TRIM( coupling_mode_remote ), &
118                     '" stopped'
119             ENDIF
120             CALL MPI_FINALIZE( ierr )
121             STOP
122
123          CASE ( 2 )
124             IF ( myid == 0 )  THEN
125                PRINT*, '+++ local_stop:'
126                PRINT*, '    remote model "', TRIM( coupling_mode_remote ), &
127                     '" terminated'
128                PRINT*, '    with stop_dt = .T.'
129             ENDIF
130             stop_dt = .TRUE.
131
132          CASE ( 3 )
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. (CPU-time limit)'
138             ENDIF
139             terminate_run = .TRUE.
140
141          CASE ( 4 )
142             IF ( myid == 0 )  THEN
143                PRINT*, '+++ local_stop:'
144                PRINT*, '    remote model "', TRIM( coupling_mode_remote ), &
145                     '" terminated'
146                PRINT*, '    with terminate_run = .T. (restart)'
147             ENDIF
148             terminate_run = .TRUE.
149             time_restart = time_restart + dt_restart
150
151          CASE ( 5 )
152             IF ( myid == 0 )  THEN
153                PRINT*, '+++ local_stop:'
154                PRINT*, '    remote model "', TRIM( coupling_mode_remote ), &
155                     '" terminated'
156                PRINT*, '    with terminate_run = .T. (single restart)'
157             ENDIF
158             terminate_run = .TRUE.
159             time_restart = 9999999.9_wp
160
161       END SELECT
162
163    ENDIF
164
165#else
166
167    STOP
168
169#endif
170
171 END SUBROUTINE local_stop   
Note: See TracBrowser for help on using the repository browser.