SURFEX v8.1
General documentation of Surfex
mpl_write_mod.F90
Go to the documentation of this file.
2 
3 !
4 ! Purpose. write to an MPIIO file
5 ! --------
6 !
7 !
8 ! Interface.
9 ! ----------
10 ! call mpl_write(...)
11 !
12 ! Explicit arguments :
13 ! --------------------
14 !
15 ! input arguments:
16 ! kfptr - handle for file
17 ! kop - requested operation
18 ! kbuf - buffer containing data to be written
19 ! klen - length of buffer in words
20 ! input/output arguements:
21 ! kreq - request handle for non-blocking operations
22 ! output arguments:
23 ! kerror - error code
24 !
25 ! Implicit arguments :
26 ! --------------------
27 !
28 ! Method.
29 ! -------
30 ! MPL supports 4 styles of MPIIO
31 !
32 ! kop = 1 - Blocking, non collective, shared file pointer
33 ! using MPI_FILE_WRITE_SHARED,
34 ! MPI_FILE_READ_SHARED
35 ! kop = 2 - Blocking, collective, ordered, shared file pointer
36 ! using MPI_FILE_WRITE_ORDERED,
37 ! MPI_FILE_READ_ORDERED
38 ! kop = 3 - Non Blocking, non collective, shared file pointer
39 ! using MPI_FILE_IWRITE_SHARED,
40 ! MPI_FILE_IREAD_SHARED
41 ! and MPI_WAIT
42 ! kop = 4 - Non Blocking, collective, ordered, shared file pointer
43 ! using MPI_FILE_WRITE_ORDERED_BEGIN/END,
44 ! MPI_FILE_READ_ORDERED_BEGIN/END
45 !
46 ! Externals.
47 ! ----------
48 !
49 ! Reference.
50 ! ----------
51 ! none yet
52 !
53 ! Author.
54 ! -------
55 ! G.Mozdzynski
56 !
57 ! Modifications.
58 ! --------------
59 ! Original : 2000-12-08 (Based on MPE_WRITE)
60 ! R. EL Khatib 24-May-2011 Change ifdef MPI2 into ifndef MPI1
61 ! -----------------------------------------------------------------
62 !
63 USE parkind1 ,ONLY : jpim ,jprb ,jprm
64 
65 USE mpl_mpif
69 
70 IMPLICIT NONE
71 
72 INTERFACE mpl_write
73 MODULE PROCEDURE mpl_write_int,mpl_write_real8
74 END INTERFACE
75 
76 PRIVATE
77 PUBLIC mpl_write
78 
79 CONTAINS
80 
81 SUBROUTINE mpl_write_int(KFPTR,KOP,KBUF,KLEN,KREQ,KERROR)
82 
83 
84 #ifdef USE_8_BYTE_WORDS
85  USE mpi4to8, ONLY : &
86  mpi_file_write_shared => mpi_file_write_shared8, &
87  mpi_file_write_ordered => mpi_file_write_ordered8, &
88  mpi_file_iwrite_shared => mpi_file_iwrite_shared8, &
89  mpi_file_write_ordered_begin => mpi_file_write_ordered_begin8, &
90  mpi_wait => mpi_wait8, &
91  mpi_file_write_ordered_end => mpi_file_write_ordered_end8
92 #endif
93 
94 INTEGER(KIND=JPIM),INTENT(IN) :: KFPTR,KOP,KLEN
95 INTEGER(KIND=JPIM),INTENT(OUT) :: KERROR
96 INTEGER(KIND=JPIM) KBUF(:)
97 INTEGER(KIND=JPIM) KREQ
98 
99 
100 INTEGER(KIND=JPIM) STATUS(mpi_status_size)
101 !
102 #ifndef MPI1
103 
104 ! -----------------------------------------------------------------
105 !
106 ! 1. Preamble
107 ! --------
108 
109 IF( mpl_rank > mpl_numio ) THEN
110  kerror = -1
111  RETURN
112 ENDIF
113 
114 IF( kop >= 1.AND.kop <= 4 ) THEN
115 
116  IF( kop /= mpl_iop ) THEN
117  kerror = -1
118  RETURN
119  ENDIF
120 
121 ENDIF
122 ! -----------------------------------------------------------------
123 !
124 ! 2. Check style and take appropriate action
125 ! ---------------------------------------
126 
127 
128 IF( kop == 1 ) THEN
129 
130 ! blocking write, non collective, shared file pointer
131 
132  CALL mpi_file_write_shared(kfptr,&
133  & kbuf,&
134  & klen,&
135  & mpi_integer,&
136  & status,&
137  & kerror)
138 
139 ELSEIF( kop == 2 ) THEN
140 
141 ! blocking write, collective, ordered with shared file pointer
142 
143  CALL mpi_file_write_ordered(kfptr,&
144  & kbuf,&
145  & klen,&
146  & mpi_integer,&
147  & status,&
148  & kerror)
149 
150 ELSEIF( kop == 3 ) THEN
151 
152 ! non blocking write, non collective, shared file pointer
153 
154  CALL mpi_file_iwrite_shared(kfptr,&
155  & kbuf,&
156  & klen,&
157  & mpi_integer,&
158  & kreq,&
159  & kerror)
160 
161 ELSEIF( kop == 4 ) THEN
162 
163 ! non blocking write, collective, ordered with shared file pointer
164 
165  CALL mpi_file_write_ordered_begin(kfptr,&
166  & kbuf,&
167  & klen,&
168  & mpi_integer,&
169  & kerror)
170 
171 ELSEIF( kop == 5 ) THEN
172 
173  CALL mpi_wait(kreq,&
174  & status,&
175  & kerror )
176 
177 ELSEIF( kop == 6 ) THEN
178 
179  CALL mpi_file_write_ordered_end(kfptr,&
180  & kbuf,&
181  & status,&
182  & kerror)
183 
184 ELSE
185 
186  kerror =-1
187  RETURN
188 
189 ENDIF
190 
191 #else
192 
193 CALL abor1('MPL_WRITE_INT not built with MPI2')
194 
195 #endif
196 !
197 ! -----------------------------------------------------------------
198 RETURN
199 END SUBROUTINE mpl_write_int
200 
201 SUBROUTINE mpl_write_real8(KFPTR,KOP,PBUF,KLEN,KREQ,KERROR)
203 
204 #ifdef USE_8_BYTE_WORDS
205  USE mpi4to8, ONLY : &
206  mpi_file_write_shared => mpi_file_write_shared8, &
207  mpi_file_write_ordered => mpi_file_write_ordered8, &
208  mpi_file_iwrite_shared => mpi_file_iwrite_shared8, &
209  mpi_file_write_ordered_begin => mpi_file_write_ordered_begin8, &
210  mpi_wait => mpi_wait8, &
211  mpi_file_write_ordered_end => mpi_file_write_ordered_end8
212 #endif
213 
214 INTEGER(KIND=JPIM),INTENT(IN) :: KFPTR,KOP,KLEN
215 INTEGER(KIND=JPIM),INTENT(OUT) :: KERROR
216 REAL(KIND=JPRM) PBUF(:)
217 INTEGER(KIND=JPIM) KREQ
218 
219 
220 INTEGER(KIND=JPIM) STATUS(mpi_status_size)
221 !
222 #ifndef MPI1
223 
224 ! -----------------------------------------------------------------
225 !
226 ! 1. Preamble
227 ! --------
228 
229 IF( mpl_rank > mpl_numio ) THEN
230  kerror = -1
231  RETURN
232 ENDIF
233 
234 IF( kop >= 1.AND.kop <= 4 ) THEN
235 
236  IF( kop /= mpl_iop ) THEN
237  kerror = -1
238  RETURN
239  ENDIF
240 
241 ENDIF
242 ! -----------------------------------------------------------------
243 !
244 ! 2. Check style and take appropriate action
245 ! ---------------------------------------
246 
247 
248 IF( kop == 1 ) THEN
249 
250 ! blocking write, non collective, shared file pointer
251 
252  CALL mpi_file_write_shared(kfptr,&
253  & pbuf,&
254  & klen,&
255  & mpi_real8,&
256  & status,&
257  & kerror)
258 
259 ELSEIF( kop == 2 ) THEN
260 
261 ! blocking write, collective, ordered with shared file pointer
262 
263  CALL mpi_file_write_ordered(kfptr,&
264  & pbuf,&
265  & klen,&
266  & mpi_real8,&
267  & status,&
268  & kerror)
269 
270 ELSEIF( kop == 3 ) THEN
271 
272 ! non blocking write, non collective, shared file pointer
273 
274  CALL mpi_file_iwrite_shared(kfptr,&
275  & pbuf,&
276  & klen,&
277  & mpi_real8,&
278  & kreq,&
279  & kerror)
280 
281 ELSEIF( kop == 4 ) THEN
282 
283 ! non blocking write, collective, ordered with shared file pointer
284 
285  CALL mpi_file_write_ordered_begin(kfptr,&
286  & pbuf,&
287  & klen,&
288  & mpi_real8,&
289  & kerror)
290 
291 ELSEIF( kop == 5 ) THEN
292 
293  CALL mpi_wait(kreq,&
294  & status,&
295  & kerror )
296 
297 ELSEIF( kop == 6 ) THEN
298 
299  CALL mpi_file_write_ordered_end(kfptr,&
300  & pbuf,&
301  & status,&
302  & kerror)
303 
304 ELSE
305 
306  kerror =-1
307  RETURN
308 
309 ENDIF
310 
311 #else
312 
313 CALL abor1('MPL_WRITE_REAL8 not built with MPI2')
314 
315 #endif
316 
317 !
318 ! -----------------------------------------------------------------
319 RETURN
320 END SUBROUTINE mpl_write_real8
321 
322 END MODULE mpl_write_mod
integer, parameter jpim
Definition: parkind1.F90:13
subroutine abor1(CDTEXT)
Definition: abor1.F90:2
integer(kind=jpim), public mpl_iop
integer(kind=jpim), public mpl_numio
subroutine mpl_write_int(KFPTR, KOP, KBUF, KLEN, KREQ, KERROR)
integer, parameter jprb
Definition: parkind1.F90:32
integer, parameter jprm
Definition: parkind1.F90:30
integer(kind=jpim) mpl_rank
subroutine mpl_write_real8(KFPTR, KOP, PBUF, KLEN, KREQ, KERROR)