SURFEX v8.1
General documentation of Surfex
mpl_probe_mod.F90
Go to the documentation of this file.
2 
3 !**** MPL_PROBE - Check for incoming message
4 
5 ! Purpose.
6 ! --------
7 ! Look for existence of an incoming message.
8 
9 !** Interface.
10 ! ----------
11 ! CALL MPL_PROBE
12 
13 ! Input required arguments :
14 ! -------------------------
15 ! none
16 
17 ! Input optional arguments :
18 ! -------------------------
19 ! KSOURCE - rank of process sending the message
20 ! default is MPI_ANY_SOURCE
21 ! KTAG - tag of incoming message
22 ! default is MPI_ANY_TAG
23 ! KCOMM - Communicator number if different from MPI_COMM_WORLD
24 ! LDWAIT - = TRUE : waits for a message to be available
25 ! = FALSE: return immediately and set
26 ! LDFLAG to indicate if a message exists
27 ! CDSTRING - Character string for ABORT messages
28 ! used when KERROR is not provided
29 
30 ! Output required arguments :
31 ! -------------------------
32 ! none
33 
34 ! Output optional arguments :
35 ! -------------------------
36 ! KERROR - return error code. If not supplied,
37 ! MPL_PROBE aborts when an error is detected.
38 ! LDFLAG - must be supplied if LDWAIT=false
39 ! = TRUE if a message exists
40 ! Author.
41 ! -------
42 ! D.Dent, M.Hamrud ECMWF
43 
44 ! Modifications.
45 ! --------------
46 ! Original: 2000-09-01
47 ! P. Marguinaud : 01-Jan-2011 : Extends original interface with
48 ! KCOUNT,KRECVTAG,KFROM (same meaning as
49 ! in all MPL_* routines)
50 
51 ! ------------------------------------------------------------------
52 
53 USE parkind1 ,ONLY : jpim ,jprb
54 
55 USE mpl_mpif
58 
59 IMPLICIT NONE
60 
61 PUBLIC mpl_probe
62 
63 PRIVATE
64 
65 !--- Moved into subroutine to make thrreadsafe----
66 ! INTEGER(KIND=JPIM) :: IRECV_STATUS(MPI_STATUS_SIZE)
67 ! INTEGER(KIND=JPIM) :: ICOMM,ITAG,ISOURCE,IERROR
68 ! LOGICAL :: LLWAIT,LLABORT=.TRUE.
69 
70 CONTAINS
71 
72 SUBROUTINE mpl_probe(KSOURCE,KTAG,KCOMM,LDWAIT,LDFLAG,CDSTRING,KERROR,KCOUNT,KRECVTAG,KFROM)
73 
74 
75 #ifdef USE_8_BYTE_WORDS
76  USE mpi4to8, ONLY : &
77  mpi_probe => mpi_probe8, mpi_iprobe => mpi_iprobe8
78 #endif
79 
80 
81 INTEGER(KIND=JPIM),INTENT(IN), OPTIONAL :: KSOURCE,KTAG,KCOMM
82 INTEGER(KIND=JPIM),INTENT(OUT),OPTIONAL :: KERROR
83 LOGICAL,INTENT(IN), OPTIONAL :: LDWAIT
84 LOGICAL,INTENT(OUT),OPTIONAL :: LDFLAG
85 CHARACTER*(*),INTENT(IN),OPTIONAL :: CDSTRING
86 INTEGER(KIND=JPIM),INTENT(OUT),OPTIONAL :: KCOUNT, KRECVTAG, KFROM
87 
88 INTEGER(KIND=JPIM) :: IRECV_STATUS(mpi_status_size)
89 INTEGER(KIND=JPIM) :: ICOMM,ITAG,ISOURCE,IERROR
90 LOGICAL :: LLWAIT,LLABORT=.true.
91 INTEGER(KIND=JPIM) :: ITID
92 itid = oml_my_thread()
93 IF(mpl_numproc < 1) CALL mpl_message( &
94  & cdmessage='MPL_PROBE: MPL NOT INITIALISED ',ldabort=llabort)
95 
96 IF(PRESENT(kcomm)) THEN
97  icomm=kcomm
98 ELSE
99  icomm=mpl_comm_oml(itid)
100 ENDIF
101 IF(PRESENT(ksource)) THEN
102  isource=ksource-1
103 ELSE
104  isource=mpi_any_source
105 ENDIF
106 IF(PRESENT(ktag)) THEN
107  itag=ktag
108 ELSE
109  itag=mpi_any_tag
110 ENDIF
111 
112 IF(PRESENT(ldwait)) THEN
113  llwait=ldwait
114 ELSE
115  llwait=.true.
116 ENDIF
117 
118 IF(llwait) THEN
119  CALL mpi_probe(isource,itag,icomm,irecv_status,ierror)
120  IF (ierror == 0) THEN
121  IF (PRESENT (kcount)) CALL mpi_get_count (irecv_status, mpi_character, kcount, ierror)
122  IF (PRESENT (krecvtag)) krecvtag = irecv_status(mpi_tag)
123  IF (PRESENT (kfrom)) kfrom = irecv_status(mpi_source)+1
124  ENDIF
125 ELSE
126  IF(PRESENT(ldflag)) THEN
127  CALL mpi_iprobe(isource,itag,icomm,ldflag,irecv_status,ierror)
128  IF (ierror == 0 .AND. ldflag) THEN
129  IF (PRESENT (kcount)) CALL mpi_get_count (irecv_status, mpi_character, kcount, ierror)
130  IF (PRESENT (krecvtag)) krecvtag = irecv_status(mpi_tag)
131  IF (PRESENT (kfrom)) kfrom = irecv_status(mpi_source)+1
132  ENDIF
133  ELSE
134  CALL mpl_message(ierror,'MPL_PROBE: MUST PROVIDE LDFLAG ',cdstring, &
135  & ldabort=llabort)
136  ENDIF
137 ENDIF
138 IF(PRESENT(kerror)) THEN
139  kerror=ierror
140 ELSE
141  IF(ierror /= 0 ) CALL mpl_message(ierror,'MPL_PROBE',cdstring,ldabort=llabort)
142 ENDIF
143 
144 RETURN
145 END SUBROUTINE mpl_probe
146 
147 END MODULE mpl_probe_mod
subroutine, public mpl_message(KERROR, CDMESSAGE, CDSTRING, LDABORT)
integer, parameter jpim
Definition: parkind1.F90:13
integer(kind=jpim) mpl_numproc
subroutine, public mpl_probe(KSOURCE, KTAG, KCOMM, LDWAIT, LDFLAG, CDSTRING, KERROR, KCOUNT, KRECVTAG, KFROM)
integer(kind=jpim), dimension(:), allocatable mpl_comm_oml
integer, parameter jprb
Definition: parkind1.F90:32