SURFEX v8.1
General documentation of Surfex
mpl_end_mod.F90
Go to the documentation of this file.
1 MODULE mpl_end_mod
2 
3 !**** MPL_END - Terminates the message passing environment
4 
5 ! Purpose.
6 ! --------
7 ! Cleans up all of the MPI state.
8 ! Subsequently, no MPI routine can be called
9 
10 !** Interface.
11 ! ----------
12 ! CALL MPL_END
13 
14 ! Input required arguments :
15 ! -------------------------
16 ! none
17 
18 ! Input optional arguments :
19 ! -------------------------
20 ! none
21 
22 ! Output required arguments :
23 ! -------------------------
24 ! none
25 
26 ! Output optional arguments :
27 ! -------------------------
28 ! KERROR - return error code. If not supplied,
29 ! MPL_END aborts when an error is detected.
30 ! Author.
31 ! -------
32 ! D.Dent, M.Hamrud ECMWF
33 
34 ! Modifications.
35 ! --------------
36 ! Original: 2000-09-01
37 ! P. Towers 3-Jul-2014 Add call to ec_cray_meminfo
38 
39 ! ------------------------------------------------------------------
40 
41 USE parkind1 ,ONLY : jpim ,jprb
42 
45 
46 IMPLICIT NONE
47 
48 PUBLIC mpl_end
49 PRIVATE
50 
51 INTEGER :: ierror
52 
53 CONTAINS
54 
55 SUBROUTINE mpl_end(KERROR)
56 
57 
58 #ifdef USE_8_BYTE_WORDS
59  USE mpi4to8, ONLY : &
60  mpi_buffer_detach => mpi_buffer_detach8, mpi_finalize => mpi_finalize8
61 #endif
62 
63 
64 INTEGER(KIND=JPIM),INTENT(OUT),OPTIONAL :: KERROR
65 INTEGER(KIND=JPIM) :: IERROR
66 LOGICAL :: LLABORT=.true.
67 
68 IF(mpl_numproc < 1) THEN
69  IF(mpl_numproc == -1) THEN
70  IF (.NOT.linitmpi_via_mpl) THEN
71  ! Neither MPL_INIT_MOD nor MPL_ARG_MOD -modules were called before this
72  CALL mpl_message(cdmessage=' MPL_END CALLED BEFORE MPL_INIT ')
73  ENDIF
74 !!-- we do not want the following message to appear, since its non-fatal
75 !! ELSEIF(MPL_NUMPROC == -2) THEN
76 !! CALL MPL_MESSAGE(CDMESSAGE=' MPL_END CALLED MULTIPLE TIMES ')
77  ENDIF
78  IF(PRESENT(kerror)) THEN
79  ierror=0
80  kerror=ierror
81  ENDIF
82  RETURN
83 ENDIF
84 
85 #ifdef _CRAYFTN
86  CALL ec_cray_meminfo(-1,"mpl_end",mpl_comm)
87 #endif
88 
89 IF (ALLOCATED(mpl_attached_buffer)) THEN
90  CALL mpi_buffer_detach(mpl_attached_buffer,mpl_mbx_size,ierror)
91  IF(PRESENT(kerror)) THEN
92  kerror=ierror
93  ELSE
94  IF( ierror /= 0 )THEN
95  CALL mpl_message(ierror,'MPL_END ',ldabort=llabort)
96  ENDIF
97  ENDIF
98  DEALLOCATE(mpl_attached_buffer)
99 ENDIF
100 
101 IF (linitmpi_via_mpl) THEN
102  CALL mpi_finalize(ierror)
103 ELSE
104  ierror = 0
105 ENDIF
106 
107 mpl_numproc = -2
108 linitmpi_via_mpl = .false.
109 
110 IF(PRESENT(kerror)) THEN
111  kerror=ierror
112 ENDIF
113 
114 RETURN
115 END SUBROUTINE mpl_end
116 
117 END MODULE mpl_end_mod
subroutine, public mpl_message(KERROR, CDMESSAGE, CDSTRING, LDABORT)
integer, parameter jpim
Definition: parkind1.F90:13
integer(kind=jpim) mpl_numproc
subroutine ec_cray_meminfo(IU, IDSTRING, KCOMM)
subroutine, public mpl_end(KERROR)
Definition: mpl_end_mod.F90:56
integer, parameter jprb
Definition: parkind1.F90:32
integer(kind=jpim) mpl_comm
integer(kind=jpim) mpl_mbx_size
integer(kind=jpim), dimension(:), allocatable, target mpl_attached_buffer
integer ierror
Definition: mpl_end_mod.F90:51