SURFEX v8.1
General documentation of Surfex
mpl_buffer_method_mod.F90
Go to the documentation of this file.
2 
3 !**** MPL_BUFFER_METHOD Establish message passing default method
4 
5 ! Purpose.
6 ! --------
7 ! Setup the message passing buffering
8 ! by allocating an attached buffer if required.
9 
10 !** Interface.
11 ! ----------
12 ! CALL MPL_BUFFER_METHOD
13 
14 ! Input required arguments :
15 ! -------------------------
16 ! KMP_TYPE - buffering type
17 ! possible values are :
18 ! JP_BLOCKING_STANDARD, JP_BLOCKING_BUFFERED
19 ! defined as parameters in MPL_DATA_MODULE
20 
21 ! Input optional arguments :
22 ! -------------------------
23 ! KMBX_SIZE - Size (in bytes) of attached buffer
24 ! if KMP_TYPE=JP_BLOCKING_BUFFERED
25 ! KPROCIDS - array of processor ids
26 ! LDINFO - = .TRUE. : Print informative msgs from MPL_INIT (default)
27 ! = .FALSE. : Do not print
28 
29 ! Output required arguments :
30 ! -------------------------
31 ! none
32 
33 ! Output optional arguments :
34 ! -------------------------
35 ! KERROR - return error code. If not supplied,
36 ! MPL_BUFFER_METHOD aborts when an error is detected.
37 ! Author.
38 ! -------
39 ! D.Dent, M.Hamrud ECMWF
40 
41 ! Modifications.
42 ! --------------
43 ! Original: 2000-09-01
44 
45 ! ------------------------------------------------------------------
46 
49 
50 IMPLICIT NONE
51 
52 PRIVATE
53 PUBLIC mpl_buffer_method
54 
55 CONTAINS
56 
57 SUBROUTINE mpl_buffer_method(KMP_TYPE,KMBX_SIZE,KERROR,KPROCIDS,LDINFO)
58 
59 
60 #ifdef USE_8_BYTE_WORDS
61  USE mpi4to8, ONLY : &
62  mpi_buffer_detach => mpi_buffer_detach8, mpi_buffer_attach => mpi_buffer_attach8
63 #endif
64 
65 
66 USE parkind1 ,ONLY : jpim ,jprb
67 
68 INTEGER(KIND=JPIM),INTENT(IN) :: KMP_TYPE
69 INTEGER(KIND=JPIM),OPTIONAL,INTENT(IN) :: KMBX_SIZE
70 INTEGER(KIND=JPIM),OPTIONAL,INTENT(IN) :: KPROCIDS(:)
71 INTEGER(KIND=JPIM),OPTIONAL,INTENT(OUT) :: KERROR
72 LOGICAL,INTENT(IN),OPTIONAL :: LDINFO
73 INTEGER(KIND=JPIM) :: IMBX_DEFAULT_SIZE = 1000000
74 INTEGER(KIND=JPIM) :: IBUFFMPI,IERROR,ILEN
75 LOGICAL :: LLABORT=.true., llinfo
76 
77 IF(mpl_numproc < 1) CALL mpl_message( &
78  & cdmessage='MPL_BUFFER_METHOD: MPL NOT INITIALISED ',ldabort=llabort)
79 
80 IF (ALLOCATED(mpl_attached_buffer)) THEN
81  CALL mpi_buffer_detach(mpl_attached_buffer,mpl_mbx_size,ierror)
82  DEALLOCATE(mpl_attached_buffer)
83 ENDIF
84 
85 IF(PRESENT(ldinfo)) THEN
86  llinfo = ldinfo
87 ELSE
88  llinfo = .true.
89 ENDIF
90 
91 IF(kmp_type == jp_blocking_standard) THEN
92  ibuffmpi=mpl_mbx_size
93 ELSE IF(kmp_type == jp_blocking_buffered) THEN
94  ibuffmpi=kmbx_size
95  IF(ibuffmpi == 0) ibuffmpi=imbx_default_size
96 ! convert to bytes
97  ilen = (ibuffmpi-1)/jp_attached_buffer_bytes+1
98  ALLOCATE(mpl_attached_buffer(ilen))
99 #ifdef OPS_COMPILE
100  ierror = 0
101 #else
102  CALL mpi_buffer_attach(mpl_attached_buffer,ibuffmpi,ierror)
103 #endif
104  IF(PRESENT(kerror)) THEN
105  kerror=ierror
106  ELSE
107  IF( ierror /= 0 )THEN
108  CALL mpl_message(ierror,'MPL_BUFFER_METHOD ','MPI_BUFFER_ATTACH ERROR',ldabort=llabort)
109  ENDIF
110  ENDIF
111 ELSE
112 ! invalid type
113  IF(PRESENT(kerror)) THEN
114  kerror=1
115  ELSE
116  CALL mpl_message(kmp_type,'MPL_BUFFER_METHOD','INVALID KMP_TYPE=',ldabort=llabort)
117  ENDIF
118 ENDIF
119 
120 mpl_mbx_size=ibuffmpi
121 mpl_method=kmp_type
122 
123 IF (mpl_rank == 1) THEN
124  IF (llinfo) WRITE(mpl_unit,'(A,I2,I12)') 'MPL_BUFFER_METHOD: ',mpl_method,mpl_mbx_size
125 ENDIF
126 
127 IF(PRESENT(kprocids)) THEN
128  IF(SIZE(kprocids) < mpl_numproc) THEN
129  CALL mpl_message(cdmessage='MPL_BUFFER_METHOD: KPROCIDS NOT CORRECT',ldabort=llabort)
130  ELSE
131  mpl_ids=kprocids
132  ENDIF
133 ENDIF
134 
135 RETURN
136 END SUBROUTINE mpl_buffer_method
137 
138 END MODULE mpl_buffer_method_mod
subroutine, public mpl_message(KERROR, CDMESSAGE, CDSTRING, LDABORT)
integer(kind=jpim), parameter jp_blocking_buffered
integer, parameter jpim
Definition: parkind1.F90:13
integer(kind=jpim) mpl_numproc
subroutine, public mpl_buffer_method(KMP_TYPE, KMBX_SIZE, KERROR, KPROCIDS, LDINFO)
integer(kind=jpim), parameter jp_blocking_standard
integer(kind=jpim), parameter jp_attached_buffer_bytes
integer, parameter jprb
Definition: parkind1.F90:32
integer(kind=jpim) mpl_rank
integer(kind=jpim) mpl_mbx_size
integer(kind=jpim) mpl_method
integer(kind=jpim), dimension(:), allocatable, target mpl_attached_buffer
integer(kind=jpim), dimension(:), allocatable mpl_ids
integer(kind=jpim) mpl_unit