Debian Codegraph @

src/atlas_f/parallel/atlas_HaloExchange_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,4]
13
14 module atlas_haloexchange_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_HaloExchange
28
29 private
30
31 !------------------------------------------------------------------------------
32 TYPE, extends(fckit_object) :: atlas_HaloExchange
33
34 ! Purpose :
35 ! -------
36 ! *HaloExchange* :
37
38 ! Methods :
39 ! -------
40 ! setup : Setup using arrays detailing proc and glb_idx, bounds and parbound
41 ! execute : Do the halo exchange
42
43 ! Author :
44 ! ------
45 ! 17-Dec-2013 Willem Deconinck *ECMWF*
46
47 !------------------------------------------------------------------------------
48 contains
49 procedure :: setup => HaloExchange__setup
50 @:generic_public_interface( execute, HaloExchange__execute )
51
52 procedure, public :: delete => atlas_HaloExchange__delete
53
54 #if FCKIT_FINAL_NOT_INHERITING
55 final :: atlas_HaloExchange__final_auto
56 #endif
57
58 END TYPE atlas_HaloExchange
59 !------------------------------------------------------------------------------
60
61 interface atlas_HaloExchange
62 module procedure atlas_HaloExchange__ctor
63 end interface
64
65 !========================================================
66 contains
67 !========================================================
68
69
70 ! ------------------------------------------------------------------------------
71 ! HaloExchange routines
72
73 function atlas_HaloExchange__ctor() result(halo_exchange)
74 use atlas_haloexchange_c_binding
75 type(atlas_HaloExchange) :: halo_exchange
76 call halo_exchange%reset_c_ptr( atlas__HaloExchange__new() )
77 end function atlas_HaloExchange__ctor
78
79 subroutine atlas_HaloExchange__delete(this)
80 use atlas_haloexchange_c_binding
81 class(atlas_HaloExchange), intent(inout) :: this
82 if ( .not. this%is_null() ) then
83 call atlas__HaloExchange__delete(this%CPTR_PGIBUG_A)
84 end if
85 call this%reset_c_ptr()
86 end subroutine atlas_HaloExchange__delete
87
88 subroutine HaloExchange__setup(this, part, remote_idx)
89 use atlas_haloexchange_c_binding
90 class(atlas_HaloExchange), intent(in) :: this
91 integer(c_int), intent(in) :: part(:)
92 integer(ATLAS_KIND_IDX), intent(in) :: remote_idx(:)
93 call atlas__HaloExchange__setup( this%CPTR_PGIBUG_A, part, remote_idx, 1, size(part) )
94 end subroutine HaloExchange__setup
95
96 #:for dtype,ftype,ctype in types[:4]
97
98 subroutine HaloExchange__execute_${dtype}$_r1(this, field_data)
99 use atlas_haloexchange_c_binding
100 class(atlas_HaloExchange), intent(in) :: this
101 ${ftype}$, intent(inout) :: field_data(:)
102 integer :: strides(1), extents(1)
103 strides = (/ array_stride(field_data,1) /)
104 extents = (/ 1 /)
105 call atlas__HaloExchange__execute_strided_${ctype}$( this%CPTR_PGIBUG_A, field_data, &
106 & strides, extents, 1 )
107 end subroutine
108
109 subroutine HaloExchange__execute_${dtype}$_r2(this, field_data)
110 use atlas_haloexchange_c_binding
111 class(atlas_HaloExchange), intent(in) :: this
112 ${ftype}$, intent(inout) :: field_data(:,:)
113 ${ftype}$, pointer :: view(:)
114 integer :: strides(2), extents(2)
115 view => array_view1d(field_data)
116 strides = (/ array_stride(field_data,2) , array_stride(field_data,1) /)
117 extents = (/ 1 , ubound(field_data,1) /)
118 call atlas__HaloExchange__execute_strided_${ctype}$( this%CPTR_PGIBUG_A, view, &
119 & strides, extents, 2 )
120 end subroutine
121
122 subroutine HaloExchange__execute_${dtype}$_r3(this, field_data)
123 use atlas_haloexchange_c_binding
124 class(atlas_HaloExchange), intent(in) :: this
125 ${ftype}$, intent(inout) :: field_data(:,:,:)
126 ${ftype}$, pointer :: view(:)
127 integer :: strides(3), extents(3)
128 view => array_view1d(field_data)
129 strides = (/ array_stride(field_data,3), array_stride(field_data,2) , array_stride(field_data,1) /)
130 extents = (/ 1, ubound(field_data,2) , ubound(field_data,1) /)
131 call atlas__HaloExchange__execute_strided_${ctype}$( this%CPTR_PGIBUG_A, view, &
132 & strides, extents, 3 )
133 end subroutine
134
135 subroutine HaloExchange__execute_${dtype}$_r4(this, field_data)
136 use atlas_haloexchange_c_binding
137 class(atlas_HaloExchange), intent(in) :: this
138 ${ftype}$, intent(inout) :: field_data(:,:,:,:)
139 ${ftype}$, pointer :: view(:)
140 integer :: strides(4), extents(4)
141 view => array_view1d(field_data)
142 strides = (/ array_stride(field_data,4), array_stride(field_data,3), array_stride(field_data,2) , &
143 array_stride(field_data,1) /)
144 extents = (/ 1, ubound(field_data,3) , ubound(field_data,2) , ubound(field_data,1) /)
145 call atlas__HaloExchange__execute_strided_${ctype}$( this%CPTR_PGIBUG_A, view, &
146 & strides, extents, 4 )
147 end subroutine
148
149 #:endfor
150
151 !-------------------------------------------------------------------------------
152
153 #if FCKIT_FINAL_NOT_INHERITING
154 ATLAS_FINAL subroutine atlas_HaloExchange__final_auto(this)
155 type(atlas_HaloExchange), intent(inout) :: this
156 #if FCKIT_FINAL_DEBUGGING
157 write(0,*) "atlas_HaloExchange__final_auto"
158 #endif
159 #if FCKIT_FINAL_NOT_PROPAGATING
160 call this%final()
161 #endif
162 FCKIT_SUPPRESS_UNUSED( this )
163 end subroutine
164 #endif
165
166 ! -----------------------------------------------------------------------------
167
168 end module atlas_haloexchange_module
169