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

Last change on this file since 1764 was 1764, checked in by raasch, 5 years ago

update of the nested domain system + some bugfixes

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