FMS  2024.03
Flexible Modeling System
mpp_transmit.inc
1 ! -*-f90-*-
2 
3 !***********************************************************************
4 !* GNU Lesser General Public License
5 !*
6 !* This file is part of the GFDL Flexible Modeling System (FMS).
7 !*
8 !* FMS is free software: you can redistribute it and/or modify it under
9 !* the terms of the GNU Lesser General Public License as published by
10 !* the Free Software Foundation, either version 3 of the License, or (at
11 !* your option) any later version.
12 !*
13 !* FMS is distributed in the hope that it will be useful, but WITHOUT
14 !* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 !* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 !* for more details.
17 !*
18 !* You should have received a copy of the GNU Lesser General Public
19 !* License along with FMS. If not, see <http://www.gnu.org/licenses/>.
20 !***********************************************************************
21 !> @file
22 !> @brief Routines for data transmission between PE's
23 
24 !> @addtogroup mpp_mod
25 !> @{
26 
27 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
28 ! !
29 ! MPP_TRANSMIT !
30 ! !
31 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
32 
33  subroutine mpp_transmit_scalar_( put_data, to_pe, get_data, from_pe, plen, glen, block, tag, &
34  recv_request, send_request)
35  integer, intent(in) :: to_pe, from_pe
36  mpp_type_, intent(in) :: put_data
37  mpp_type_, intent(out) :: get_data
38  integer, optional, intent(in) :: plen, glen
39  logical, intent(in), optional :: block
40  integer, intent(in), optional :: tag
41  integer, intent(out), optional :: recv_request, send_request
42  integer :: put_len, get_len
43  mpp_type_ :: put_data1d(1), get_data1d(1)
44  pointer( ptrp, put_data1d )
45  pointer( ptrg, get_data1d )
46 
47  get_data = mpp_type_init_value
48 
49  ptrp = loc(put_data)
50  ptrg = loc(get_data)
51  put_len=1; if(PRESENT(plen))put_len=plen
52  get_len=1; if(PRESENT(glen))get_len=glen
53  call mpp_transmit_ ( put_data1d, put_len, to_pe, get_data1d, get_len, from_pe, block, tag, &
54  recv_request=recv_request, send_request=send_request )
55 
56  return
57  end subroutine mpp_transmit_scalar_
58 
59  subroutine mpp_transmit_2d_( put_data, put_len, to_pe, get_data, get_len, from_pe, block, tag, &
60  recv_request, send_request )
61  integer, intent(in) :: put_len, to_pe, get_len, from_pe
62  mpp_type_, intent(in) :: put_data(:,:)
63  mpp_type_, intent(out) :: get_data(:,:)
64  logical, intent(in), optional :: block
65  integer, intent(in), optional :: tag
66  integer, intent(out), optional :: recv_request, send_request
67  mpp_type_ :: put_data1d(put_len), get_data1d(get_len)
68 
69  pointer( ptrp, put_data1d )
70  pointer( ptrg, get_data1d )
71  get_data = mpp_type_init_value
72 
73  ptrp = loc(put_data)
74  ptrg = loc(get_data)
75  call mpp_transmit( put_data1d, put_len, to_pe, get_data1d, get_len, from_pe, block, tag, &
76  recv_request=recv_request, send_request=send_request )
77 
78  return
79  end subroutine mpp_transmit_2d_
80 
81  subroutine mpp_transmit_3d_( put_data, put_len, to_pe, get_data, get_len, from_pe, block, tag, &
82  recv_request, send_request )
83  integer, intent(in) :: put_len, to_pe, get_len, from_pe
84  mpp_type_, intent(in) :: put_data(:,:,:)
85  mpp_type_, intent(out) :: get_data(:,:,:)
86  logical, intent(in), optional :: block
87  integer, intent(in), optional :: tag
88  integer, intent(out), optional :: recv_request, send_request
89  mpp_type_ :: put_data1d(put_len), get_data1d(get_len)
90 
91  pointer( ptrp, put_data1d )
92  pointer( ptrg, get_data1d )
93  get_data = mpp_type_init_value
94 
95  ptrp = loc(put_data)
96  ptrg = loc(get_data)
97  call mpp_transmit( put_data1d, put_len, to_pe, get_data1d, get_len, from_pe, block, tag, &
98  recv_request=recv_request, send_request=send_request )
99 
100  return
101  end subroutine mpp_transmit_3d_
102 
103  subroutine mpp_transmit_4d_( put_data, put_len, to_pe, get_data, get_len, from_pe, block, tag, &
104  recv_request, send_request )
105  integer, intent(in) :: put_len, to_pe, get_len, from_pe
106  mpp_type_, intent(in) :: put_data(:,:,:,:)
107  mpp_type_, intent(out) :: get_data(:,:,:,:)
108  logical, intent(in), optional :: block
109  integer, intent(in), optional :: tag
110  integer, intent(out), optional :: recv_request, send_request
111  mpp_type_ :: put_data1d(put_len), get_data1d(get_len)
112 
113  pointer( ptrp, put_data1d )
114  pointer( ptrg, get_data1d )
115  get_data = mpp_type_init_value
116 
117  ptrp = loc(put_data)
118  ptrg = loc(get_data)
119  call mpp_transmit( put_data1d, put_len, to_pe, get_data1d, get_len, from_pe, block, tag, &
120  recv_request=recv_request, send_request=send_request )
121 
122  return
123  end subroutine mpp_transmit_4d_
124 
125  subroutine mpp_transmit_5d_( put_data, put_len, to_pe, get_data, get_len, from_pe, block, tag, &
126  recv_request, send_request )
127  integer, intent(in) :: put_len, to_pe, get_len, from_pe
128  mpp_type_, intent(in) :: put_data(:,:,:,:,:)
129  mpp_type_, intent(out) :: get_data(:,:,:,:,:)
130  logical, intent(in), optional :: block
131  integer, intent(in), optional :: tag
132  integer, intent(out), optional :: recv_request, send_request
133  mpp_type_ :: put_data1d(put_len), get_data1d(get_len)
134 
135  pointer( ptrp, put_data1d )
136  pointer( ptrg, get_data1d )
137  get_data = mpp_type_init_value
138 
139  ptrp = loc(put_data)
140  ptrg = loc(get_data)
141  call mpp_transmit( put_data1d, put_len, to_pe, get_data1d, get_len, from_pe, block, tag, &
142  recv_request=recv_request, send_request=send_request )
143 
144  return
145  end subroutine mpp_transmit_5d_
146 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
147 ! !
148 ! MPP_SEND and RECV !
149 ! !
150 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
151 
152  subroutine mpp_recv_( get_data, get_len, from_pe, block, tag, request )
153 !a mpp_transmit with null arguments on the put side
154  integer, intent(in) :: get_len, from_pe
155  mpp_type_, intent(out) :: get_data(*)
156  logical, intent(in), optional :: block
157  integer, intent(in), optional :: tag
158  integer, intent(out), optional :: request
159 
160  mpp_type_ :: dummy(1)
161  call mpp_transmit( dummy, 1, null_pe, get_data, get_len, from_pe, block, tag, recv_request=request )
162  end subroutine mpp_recv_
163 
164  subroutine mpp_send_( put_data, put_len, to_pe, tag, request )
165 !a mpp_transmit with null arguments on the get side
166  integer, intent(in) :: put_len, to_pe
167  mpp_type_, intent(in) :: put_data(*)
168  integer, intent(in), optional :: tag
169  integer, intent(out), optional :: request
170  mpp_type_ :: dummy(1)
171  call mpp_transmit( put_data, put_len, to_pe, dummy, 1, null_pe, tag=tag, send_request=request )
172  end subroutine mpp_send_
173 
174  subroutine mpp_recv_scalar_( get_data, from_pe, glen, block, tag, request )
175 !a mpp_transmit with null arguments on the put side
176  integer, intent(in) :: from_pe
177  mpp_type_, intent(out) :: get_data
178  logical, intent(in), optional :: block
179  integer, intent(in), optional :: tag
180  integer, intent(out), optional :: request
181 
182  integer, optional, intent(in) :: glen
183  integer :: get_len
184  mpp_type_ :: get_data1d(1)
185  mpp_type_ :: dummy(1)
186 
187  pointer( ptr, get_data1d )
188  get_data = mpp_type_init_value
189 
190  ptr = loc(get_data)
191  get_len=1; if(PRESENT(glen))get_len=glen
192  call mpp_transmit( dummy, 1, null_pe, get_data1d, get_len, from_pe, block, tag, recv_request=request )
193 
194  end subroutine mpp_recv_scalar_
195 
196  subroutine mpp_send_scalar_( put_data, to_pe, plen, tag, request)
197 !a mpp_transmit with null arguments on the get side
198  integer, intent(in) :: to_pe
199  mpp_type_, intent(in) :: put_data
200  integer, optional, intent(in) :: plen
201  integer, intent(in), optional :: tag
202  integer, intent(out), optional :: request
203  integer :: put_len
204  mpp_type_ :: put_data1d(1)
205  mpp_type_ :: dummy(1)
206 
207  pointer( ptr, put_data1d )
208  ptr = loc(put_data)
209  put_len=1; if(PRESENT(plen))put_len=plen
210  call mpp_transmit( put_data1d, put_len, to_pe, dummy, 1, null_pe, tag = tag, send_request=request )
211 
212  end subroutine mpp_send_scalar_
213 
214  subroutine mpp_recv_2d_( get_data, get_len, from_pe, block, tag, request )
215 !a mpp_transmit with null arguments on the put side
216  integer, intent(in) :: get_len, from_pe
217  mpp_type_, intent(out) :: get_data(:,:)
218  logical, intent(in), optional :: block
219  integer, intent(in), optional :: tag
220  integer, intent(out), optional :: request
221 
222  mpp_type_ :: dummy(1,1)
223  call mpp_transmit( dummy, 1, null_pe, get_data, get_len, from_pe, block, tag, recv_request=request )
224  end subroutine mpp_recv_2d_
225 
226  subroutine mpp_send_2d_( put_data, put_len, to_pe, tag, request )
227 !a mpp_transmit with null arguments on the get side
228  integer, intent(in) :: put_len, to_pe
229  mpp_type_, intent(in) :: put_data(:,:)
230  integer, intent(in), optional :: tag
231  integer, intent(out), optional :: request
232  mpp_type_ :: dummy(1,1)
233  call mpp_transmit( put_data, put_len, to_pe, dummy, 1, null_pe, tag = tag, send_request=request )
234  end subroutine mpp_send_2d_
235 
236  subroutine mpp_recv_3d_( get_data, get_len, from_pe, block, tag, request )
237 !a mpp_transmit with null arguments on the put side
238  integer, intent(in) :: get_len, from_pe
239  mpp_type_, intent(out) :: get_data(:,:,:)
240  logical, intent(in), optional :: block
241  integer, intent(in), optional :: tag
242  integer, intent(out), optional :: request
243 
244  mpp_type_ :: dummy(1,1,1)
245  call mpp_transmit( dummy, 1, null_pe, get_data, get_len, from_pe, block, tag, recv_request=request )
246  end subroutine mpp_recv_3d_
247 
248  subroutine mpp_send_3d_( put_data, put_len, to_pe, tag, request )
249 !a mpp_transmit with null arguments on the get side
250  integer, intent(in) :: put_len, to_pe
251  mpp_type_, intent(in) :: put_data(:,:,:)
252  integer, intent(in), optional :: tag
253  integer, intent(out), optional :: request
254  mpp_type_ :: dummy(1,1,1)
255  call mpp_transmit( put_data, put_len, to_pe, dummy, 1, null_pe, tag = tag, send_request=request )
256  end subroutine mpp_send_3d_
257 
258  subroutine mpp_recv_4d_( get_data, get_len, from_pe, block, tag, request )
259 !a mpp_transmit with null arguments on the put side
260  integer, intent(in) :: get_len, from_pe
261  mpp_type_, intent(out) :: get_data(:,:,:,:)
262  logical, intent(in), optional :: block
263  integer, intent(in), optional :: tag
264  integer, intent(out), optional :: request
265 
266  mpp_type_ :: dummy(1,1,1,1)
267  call mpp_transmit( dummy, 1, null_pe, get_data, get_len, from_pe, block, tag, recv_request=request )
268  end subroutine mpp_recv_4d_
269 
270  subroutine mpp_send_4d_( put_data, put_len, to_pe, tag, request )
271 !a mpp_transmit with null arguments on the get side
272  integer, intent(in) :: put_len, to_pe
273  mpp_type_, intent(in) :: put_data(:,:,:,:)
274  integer, intent(in), optional :: tag
275  integer, intent(out), optional :: request
276  mpp_type_ :: dummy(1,1,1,1)
277  call mpp_transmit( put_data, put_len, to_pe, dummy, 1, null_pe, tag = tag, send_request=request )
278  end subroutine mpp_send_4d_
279 
280  subroutine mpp_recv_5d_( get_data, get_len, from_pe, block, tag, request)
281 !a mpp_transmit with null arguments on the put side
282  integer, intent(in) :: get_len, from_pe
283  mpp_type_, intent(out) :: get_data(:,:,:,:,:)
284  logical, intent(in), optional :: block
285  integer, intent(in), optional :: tag
286  integer, intent(out), optional :: request
287 
288  mpp_type_ :: dummy(1,1,1,1,1)
289  call mpp_transmit( dummy, 1, null_pe, get_data, get_len, from_pe, block, tag, recv_request=request )
290  end subroutine mpp_recv_5d_
291 
292  subroutine mpp_send_5d_( put_data, put_len, to_pe, tag, request )
293 !a mpp_transmit with null arguments on the get side
294  integer, intent(in) :: put_len, to_pe
295  mpp_type_, intent(in) :: put_data(:,:,:,:,:)
296  integer, intent(in), optional :: tag
297  integer, intent(out), optional :: request
298  mpp_type_ :: dummy(1,1,1,1,1)
299  call mpp_transmit( put_data, put_len, to_pe, dummy, 1, null_pe, tag = tag, send_request=request )
300  end subroutine mpp_send_5d_
301 
302 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
303 ! !
304 ! MPP_BROADCAST !
305 ! !
306 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
307 
308  subroutine mpp_broadcast_scalar_( broadcast_data, from_pe, pelist )
309  mpp_type_, intent(inout) :: broadcast_data
310  integer, intent(in) :: from_pe
311  integer, intent(in), optional :: pelist(:)
312  mpp_type_ :: data1d(1)
313 
314  pointer( ptr, data1d )
315 
316  ptr = loc(broadcast_data)
317  call mpp_broadcast_( data1d, 1, from_pe, pelist )
318 
319  return
320  end subroutine mpp_broadcast_scalar_
321 
322  subroutine mpp_broadcast_2d_( broadcast_data, length, from_pe, pelist )
323 !this call was originally bundled in with mpp_transmit, but that doesn't allow
324 !broadcast to a subset of PEs. This version will, and mpp_transmit will remain
325 !backward compatible.
326  mpp_type_, intent(inout) :: broadcast_data(:,:)
327  integer, intent(in) :: length, from_pe
328  integer, intent(in), optional :: pelist(:)
329  mpp_type_ :: data1d(length)
330 
331  pointer( ptr, data1d )
332  ptr = loc(broadcast_data)
333  call mpp_broadcast( data1d, length, from_pe, pelist )
334 
335  return
336  end subroutine mpp_broadcast_2d_
337 
338  subroutine mpp_broadcast_3d_( broadcast_data, length, from_pe, pelist )
339 !this call was originally bundled in with mpp_transmit, but that doesn't allow
340 !broadcast to a subset of PEs. This version will, and mpp_transmit will remain
341 !backward compatible.
342  mpp_type_, intent(inout) :: broadcast_data(:,:,:)
343  integer, intent(in) :: length, from_pe
344  integer, intent(in), optional :: pelist(:)
345  mpp_type_ :: data1d(length)
346 
347  pointer( ptr, data1d )
348  ptr = loc(broadcast_data)
349  call mpp_broadcast( data1d, length, from_pe, pelist )
350 
351  return
352  end subroutine mpp_broadcast_3d_
353 
354  subroutine mpp_broadcast_4d_( broadcast_data, length, from_pe, pelist )
355 !this call was originally bundled in with mpp_transmit, but that doesn't allow
356 !broadcast to a subset of PEs. This version will, and mpp_transmit will remain
357 !backward compatible.
358  mpp_type_, intent(inout) :: broadcast_data(:,:,:,:)
359  integer, intent(in) :: length, from_pe
360  integer, intent(in), optional :: pelist(:)
361  mpp_type_ :: data1d(length)
362 
363  pointer( ptr, data1d )
364  ptr = loc(broadcast_data)
365  call mpp_broadcast( data1d, length, from_pe, pelist )
366 
367  return
368  end subroutine mpp_broadcast_4d_
369 
370  subroutine mpp_broadcast_5d_( broadcast_data, length, from_pe, pelist )
371 !this call was originally bundled in with mpp_transmit, but that doesn't allow
372 !broadcast to a subset of PEs. This version will, and mpp_transmit will remain
373 !backward compatible.
374  mpp_type_, intent(inout) :: broadcast_data(:,:,:,:,:)
375  integer, intent(in) :: length, from_pe
376  integer, intent(in), optional :: pelist(:)
377  mpp_type_ :: data1d(length)
378 
379  pointer( ptr, data1d )
380  ptr = loc(broadcast_data)
381  call mpp_broadcast( data1d, length, from_pe, pelist )
382 
383  return
384  end subroutine mpp_broadcast_5d_
385 !> @}