Debian Codegraph @

src/atlas_f/parallel/atlas_GatherScatter_module.fypp

raw
1 ! (C) Copyright 2013 ECMWF.
2 !
3 ! This software is licensed under the terms of the Apache Licence Version 2.0
4 ! which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
5 ! In applying this licence, ECMWF does not waive the privileges and immunities
6 ! granted to it by virtue of its status as an intergovernmental organisation nor
7 ! does it submit to any jurisdiction.
8
9 #include "atlas/atlas_f.h"
10 #:include "internals/atlas_generics.fypp"
11
12 #:set ranks = [1,2,3]
13
14 module atlas_gatherscatter_module
15
16 use, intrinsic :: iso_c_binding, only : c_ptr, c_int, c_long, c_float, c_double
17 use fckit_array_module, only : array_stride, array_view1d
18 use fckit_object_module, only : fckit_object
19 use atlas_kinds_module, only : ATLAS_KIND_IDX
20
21 implicit none
22
23 private :: c_ptr, c_int, c_long, c_float, c_double
24 private :: array_stride, array_view1d
25 private :: fckit_object
26
27 public :: atlas_GatherScatter
28
29 private
30
31 !------------------------------------------------------------------------------
32 TYPE, extends(fckit_object) :: atlas_GatherScatter
33
34 ! Purpose :
35 ! -------
36 ! *Gather* :
37
38 ! Methods :
39 ! -------
40 ! setup : Setup using arrays detailing proc, glb_idx, remote_idx, max_glb_idx
41 ! execute : Do the gather
42
43 ! Author :
44 ! ------
45 ! 17-Dec-2013 Willem Deconinck *ECMWF*
46
47 !------------------------------------------------------------------------------
48 contains
49 procedure :: glb_dof => GatherScatter__glb_dof
50 procedure, private :: GatherScatter__setup32
51 procedure, private :: GatherScatter__setup64
52
53 generic :: setup => &
54 & GatherScatter__setup32, &
55 & GatherScatter__setup64
56
57 @:generic_public_interface( gather )
58 @:generic_public_interface( scatter )
59
60
61 procedure, public :: delete => atlas_GatherScatter__delete
62
63 #if FCKIT_FINAL_NOT_INHERITING
64 final :: atlas_GatherScatter__final_auto
65 #endif
66
67 END TYPE atlas_GatherScatter
68 !------------------------------------------------------------------------------
69
70 interface atlas_GatherScatter
71 module procedure atlas_GatherScatter__ctor
72 end interface
73
74 !------------------------------------------------------------------------------
75
76
77 !========================================================
78 contains
79 !========================================================
80
81 ! ------------------------------------------------------------------------------
82 ! Gather routines
83
84 function atlas_GatherScatter__ctor() result(gather)
85 use atlas_gatherscatter_c_binding
86 type(atlas_GatherScatter) :: gather
87 call gather%reset_c_ptr( atlas__GatherScatter__new() )
88 end function atlas_GatherScatter__ctor
89
90 subroutine atlas_GatherScatter__delete(this)
91 use atlas_gatherscatter_c_binding
92 class(atlas_GatherScatter), intent(inout) :: this
93 if ( .not. this%is_null() ) then
94 call atlas__GatherScatter__delete(this%CPTR_PGIBUG_A)
95 end if
96 call this%reset_c_ptr()
97 end subroutine atlas_GatherScatter__delete
98
99
100 subroutine GatherScatter__setup32(this, part, remote_idx, glb_idx)
101 use atlas_gatherscatter_c_binding
102 class(atlas_GatherScatter), intent(in) :: this
103 integer(c_int), intent(in) :: part(:)
104 integer(ATLAS_KIND_IDX), intent(in) :: remote_idx(:)
105 integer(c_int), intent(in) :: glb_idx(:)
106 call atlas__GatherScatter__setup32( this%CPTR_PGIBUG_A, part, remote_idx, 1, &
107 & glb_idx, size(part) )
108 end subroutine GatherScatter__setup32
109
110 subroutine GatherScatter__setup64(this, part, remote_idx, glb_idx )
111 use atlas_gatherscatter_c_binding
112 class(atlas_GatherScatter), intent(in) :: this
113 integer(c_int), intent(in) :: part(:)
114 integer(ATLAS_KIND_IDX), intent(in) :: remote_idx(:)
115 integer(c_long), intent(in) :: glb_idx(:)
116 call atlas__GatherScatter__setup64( this%CPTR_PGIBUG_A, part, remote_idx, 1, &
117 & glb_idx, size(part) )
118 end subroutine GatherScatter__setup64
119
120 function GatherScatter__glb_dof(this) result(glb_dof)
121 use atlas_gatherscatter_c_binding
122 class(atlas_GatherScatter), intent(in) :: this
123 integer :: glb_dof
124 glb_dof = atlas__GatherScatter__glb_dof(this%CPTR_PGIBUG_A)
125 end function GatherScatter__glb_dof
126
127 ! -----------------------------------------------------------------------------
128
129 #:for dtype,ftype,ctype in types[:4]
130
131 subroutine gather_${dtype}$_r1(this, loc_field_data, glb_field_data)
132 use atlas_gatherscatter_c_binding
133 class(atlas_GatherScatter), intent(in) :: this
134 ${ftype}$, intent(in) :: loc_field_data(:)
135 ${ftype}$, intent(out) :: glb_field_data(:)
136 integer :: lstrides(1), lextents(1), lrank=1
137 integer :: gstrides(1), gextents(1), grank=1
138 ${ftype}$, pointer :: lview(:), gview(:)
139 lstrides = (/ array_stride(loc_field_data,2) /)
140 lextents = (/ 1 /)
141 lview => array_view1d(loc_field_data)
142 gstrides = (/ array_stride(glb_field_data,2) /)
143 gextents = (/ 1 /)
144 gview => array_view1d(glb_field_data)
145 if( size(gview) == 0 ) then
146 allocate(gview(0))
147 endif
148 call atlas__GatherScatter__gather_${ctype}$( this%CPTR_PGIBUG_A, &
149 & lview, lstrides, lextents, lrank, &
150 & gview, gstrides, gextents, grank )
151 end subroutine
152
153 subroutine gather_${dtype}$_r2(this, loc_field_data, glb_field_data)
154 use atlas_gatherscatter_c_binding
155 class(atlas_GatherScatter), intent(in) :: this
156 ${ftype}$, intent(in) :: loc_field_data(:,:)
157 ${ftype}$, intent(out) :: glb_field_data(:,:)
158 ${ftype}$, pointer :: lview(:), gview(:)
159 integer :: lstrides(2), lextents(2), lrank=2
160 integer :: gstrides(2), gextents(2), grank=2
161 lstrides = (/ array_stride(loc_field_data,2), array_stride(loc_field_data,1) /)
162 lextents = (/ 1, size (loc_field_data,1) /)
163 lview => array_view1d(loc_field_data)
164 gstrides = (/ array_stride(glb_field_data,2), array_stride(glb_field_data,1) /)
165 gextents = (/ 1, size (glb_field_data,1) /)
166 gview => array_view1d(glb_field_data)
167 if( size(gview) == 0 ) then
168 allocate(gview(0))
169 endif
170 call atlas__GatherScatter__gather_${ctype}$( this%CPTR_PGIBUG_A, &
171 & lview, lstrides, lextents, lrank, &
172 & gview, gstrides, gextents, grank )
173 end subroutine
174
175 subroutine gather_${dtype}$_r3(this, loc_field_data, glb_field_data)
176 use atlas_gatherscatter_c_binding
177 class(atlas_GatherScatter), intent(in) :: this
178 ${ftype}$, intent(in) :: loc_field_data(:,:,:)
179 ${ftype}$, intent(out) :: glb_field_data(:,:,:)
180 ${ftype}$, pointer :: lview(:), gview(:)
181 integer :: lstrides(3), lextents(3), lrank=3
182 integer :: gstrides(3), gextents(3), grank=3
183 lstrides = (/ array_stride(loc_field_data,3), array_stride(loc_field_data,2) , array_stride(loc_field_data,1) /)
184 lextents = (/ 1, size (loc_field_data,2) , size (loc_field_data,1) /)
185 lview => array_view1d(loc_field_data)
186 gstrides = (/ array_stride(glb_field_data,3), array_stride(glb_field_data,2) , array_stride(glb_field_data,1) /)
187 gextents = (/ 1, size (glb_field_data,2) , size (glb_field_data,1) /)
188 gview => array_view1d(glb_field_data)
189 if( size(gview) == 0 ) then
190 allocate(gview(0))
191 endif
192 call atlas__GatherScatter__gather_${ctype}$( this%CPTR_PGIBUG_A, &
193 & lview, lstrides, lextents, lrank, &
194 & gview, gstrides, gextents, grank )
195 end subroutine
196
197 ! -----------------------------------------------------------------------------
198
199 subroutine scatter_${dtype}$_r1(this, glb_field_data, loc_field_data)
200 use atlas_gatherscatter_c_binding
201 class(atlas_GatherScatter), intent(in) :: this
202 ${ftype}$, intent(in) :: glb_field_data(:)
203 ${ftype}$, intent(out) :: loc_field_data(:)
204 ${ftype}$, pointer :: lview(:), gview(:)
205 integer :: lstrides(1), lextents(1), lrank=1
206 integer :: gstrides(1), gextents(1), grank=1
207 lstrides = (/ array_stride(loc_field_data,1) /)
208 lextents = (/ 1 /)
209 lview => array_view1d(loc_field_data)
210 gstrides = (/ array_stride(glb_field_data,1) /)
211 gextents = (/ 1 /)
212 gview => array_view1d(glb_field_data)
213 call atlas__GatherScatter__scatter_${ctype}$( this%CPTR_PGIBUG_A, &
214 & gview, gstrides, gextents, grank, &
215 & lview, lstrides, lextents, lrank )
216 end subroutine
217
218 subroutine scatter_${dtype}$_r2(this, glb_field_data, loc_field_data)
219 use atlas_gatherscatter_c_binding
220 class(atlas_GatherScatter), intent(in) :: this
221 ${ftype}$, intent(in) :: glb_field_data(:,:)
222 ${ftype}$, intent(out) :: loc_field_data(:,:)
223 ${ftype}$, pointer :: lview(:), gview(:)
224 integer :: lstrides(2), lextents(2), lrank=2
225 integer :: gstrides(2), gextents(2), grank=2
226 lstrides = (/ array_stride(loc_field_data,2), array_stride(loc_field_data,1) /)
227 lextents = (/ 1, size (loc_field_data,1) /)
228 lview => array_view1d(loc_field_data)
229 gstrides = (/ array_stride(glb_field_data,2), array_stride(glb_field_data,1) /)
230 gextents = (/ 1, size (glb_field_data,1) /)
231 gview => array_view1d(glb_field_data)
232 if( size(gview) == 0 ) then
233 allocate(gview(0))
234 endif
235 call atlas__GatherScatter__scatter_${ctype}$( this%CPTR_PGIBUG_A, &
236 & gview, gstrides, gextents, grank, &
237 & lview, lstrides, lextents, lrank )
238 end subroutine
239
240 subroutine scatter_${dtype}$_r3(this, glb_field_data, loc_field_data)
241 use atlas_gatherscatter_c_binding
242 class(atlas_GatherScatter), intent(in) :: this
243 ${ftype}$, intent(in) :: glb_field_data(:,:,:)
244 ${ftype}$, intent(out) :: loc_field_data(:,:,:)
245 ${ftype}$, pointer :: lview(:), gview(:)
246 integer :: lstrides(3), lextents(3), lrank=3
247 integer :: gstrides(3), gextents(3), grank=3
248 lstrides = (/ array_stride(loc_field_data,3), array_stride(loc_field_data,2), array_stride(loc_field_data,1) /)
249 lextents = (/ 1, size (loc_field_data,2) , size (loc_field_data,1) /)
250 lview => array_view1d(loc_field_data)
251 gstrides = (/ array_stride(glb_field_data,3), array_stride(glb_field_data,2), array_stride(glb_field_data,1) /)
252 gextents = (/ 1, size (glb_field_data,2) , size (glb_field_data,1) /)
253 gview => array_view1d(glb_field_data)
254 if( size(gview) == 0 ) then
255 allocate(gview(0))
256 endif
257 call atlas__GatherScatter__scatter_${ctype}$( this%CPTR_PGIBUG_A, &
258 & gview, gstrides, gextents, grank, &
259 & lview, lstrides, lextents, lrank )
260 end subroutine
261
262 #:endfor
263
264 !-------------------------------------------------------------------------------
265
266 #if FCKIT_FINAL_NOT_INHERITING
267 ATLAS_FINAL subroutine atlas_GatherScatter__final_auto(this)
268 type(atlas_GatherScatter), intent(inout) :: this
269 #if FCKIT_FINAL_DEBUGGING
270 write(0,*) "atlas_GatherScatter__final_auto"
271 #endif
272 #if FCKIT_FINAL_NOT_PROPAGATING
273 call this%final()
274 #endif
275 FCKIT_SUPPRESS_UNUSED( this )
276 end subroutine
277 #endif
278
279 ! -----------------------------------------------------------------------------
280
281 end module atlas_gatherscatter_module