Debian Codegraph @

src/atlas_f/parallel/atlas_Checksum_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_checksum_module
15
16 use, intrinsic :: iso_c_binding, only : c_ptr, c_int, c_long, c_float, c_double, c_char
17 use fckit_array_module, only : array_stride, array_view1d
18 use fckit_c_interop_module, only : c_str_to_string
19 use fckit_object_module, only : fckit_object
20 use atlas_kinds_module, only : ATLAS_KIND_IDX
21
22 implicit none
23
24 private :: c_ptr, c_int, c_long, c_float, c_double, c_char
25 private :: array_stride, array_view1d, c_str_to_string
26 private :: fckit_object
27
28 public :: atlas_Checksum
29
30 private
31
32 !------------------------------------------------------------------------------
33 TYPE, extends(fckit_object) :: atlas_Checksum
34
35 ! Purpose :
36 ! -------
37 ! *Checksum* :
38
39 ! Methods :
40 ! -------
41 ! setup : Setup using arrays detailing proc, glb_idx, remote_idx, max_glb_idx
42 ! execute : Do the Checksum
43
44 ! Author :
45 ! ------
46 ! 27-Jun-2014 Willem Deconinck *ECMWF*
47
48 !------------------------------------------------------------------------------
49 contains
50 procedure, private :: Checksum__setup32
51 procedure, private :: Checksum__setup64
52
53 generic :: setup => &
54 & Checksum__setup32, &
55 & Checksum__setup64
56
57 @:generic_public_interface( execute )
58
59 procedure, public :: delete => atlas_Checksum__delete
60
61 #if FCKIT_FINAL_NOT_INHERITING
62 final :: atlas_Checksum__final_auto
63 #endif
64
65 END TYPE atlas_Checksum
66
67 !------------------------------------------------------------------------------
68
69 interface atlas_Checksum
70 module procedure atlas_Checksum__ctor
71 end interface
72
73 !------------------------------------------------------------------------------
74 !========================================================
75 contains
76 !========================================================
77
78 ! ------------------------------------------------------------------------------
79 ! Checksum routines
80
81 function atlas_Checksum__ctor() result(Checksum)
82 use atlas_checksum_c_binding
83 type(atlas_Checksum) :: Checksum
84 call Checksum%reset_c_ptr( atlas__Checksum__new() )
85 end function atlas_checksum__ctor
86
87 subroutine atlas_Checksum__delete(this)
88 use atlas_checksum_c_binding
89 class(atlas_Checksum), intent(inout) :: this
90 if ( .not. this%is_null() ) then
91 call atlas__Checksum__delete(this%CPTR_PGIBUG_A)
92 end if
93 call this%reset_c_ptr()
94 end subroutine atlas_Checksum__delete
95
96 subroutine Checksum__setup32(this, part, remote_idx, glb_idx )
97 use atlas_checksum_c_binding
98 class(atlas_Checksum), intent(in) :: this
99 integer(c_int), intent(in) :: part(:)
100 integer(ATLAS_KIND_IDX), intent(in) :: remote_idx(:)
101 integer(c_int), intent(in) :: glb_idx(:)
102 call atlas__Checksum__setup32( this%CPTR_PGIBUG_A, part, remote_idx, 1, &
103 & glb_idx, size(part) )
104 end subroutine Checksum__setup32
105
106 subroutine Checksum__setup64(this, part, remote_idx, glb_idx)
107 use atlas_checksum_c_binding
108 class(atlas_Checksum), intent(in) :: this
109 integer(c_int), intent(in) :: part(:)
110 integer(ATLAS_KIND_IDX), intent(in) :: remote_idx(:)
111 integer(c_long), intent(in) :: glb_idx(:)
112 call atlas__Checksum__setup64( this%CPTR_PGIBUG_A, part, remote_idx, 1, &
113 & glb_idx, size(part) )
114 end subroutine Checksum__setup64
115
116 #:for dtype,ftype,ctype in types[:4]
117
118 function execute_${dtype}$_r1(this, loc_field_data) result(checksum)
119 use atlas_checksum_c_binding
120 class(atlas_Checksum), intent(in) :: this
121 ${ftype}$, intent(in) :: loc_field_data(:)
122 character(len=:), allocatable :: checksum
123 character(kind=c_char) :: checksum_c_str(132)
124 integer :: lstrides(1), lextents(1), lrank=1
125 ${ftype}$, pointer :: lview(:)
126 lstrides = (/ array_stride(loc_field_data,1) /)
127 lextents = (/ 1 /)
128 lview => array_view1d(loc_field_data)
129 call atlas__Checksum__execute_strided_${ctype}$( this%CPTR_PGIBUG_A, &
130 & lview, lstrides, lextents, lrank, checksum_c_str )
131 checksum = c_str_to_string(checksum_c_str)
132 end function
133
134 function execute_${dtype}$_r2(this, loc_field_data) result(checksum)
135 use atlas_checksum_c_binding
136 class(atlas_Checksum), intent(in) :: this
137 ${ftype}$, intent(in) :: loc_field_data(:,:)
138 character(len=:), allocatable :: checksum
139 character(kind=c_char) :: checksum_c_str(132)
140 ${ftype}$, pointer :: lview(:)
141 integer :: lstrides(2), lextents(2), lrank=2
142 lstrides = (/ array_stride(loc_field_data,2), array_stride(loc_field_data,1) /)
143 lextents = (/ 1, size (loc_field_data,1) /)
144 lview => array_view1d(loc_field_data)
145 call atlas__Checksum__execute_strided_${ctype}$( this%CPTR_PGIBUG_A, &
146 & lview, lstrides, lextents, lrank, checksum_c_str )
147 checksum = c_str_to_string(checksum_c_str)
148 end function
149
150 function execute_${dtype}$_r3(this, loc_field_data) result(checksum)
151 use atlas_checksum_c_binding
152 class(atlas_Checksum), intent(in) :: this
153 ${ftype}$, intent(in) :: loc_field_data(:,:,:)
154 character(len=:), allocatable :: checksum
155 character(kind=c_char) :: checksum_c_str(132)
156 ${ftype}$, pointer :: lview(:)
157 integer :: lstrides(3), lextents(3), lrank=3
158 lstrides = (/ array_stride(loc_field_data,3), array_stride(loc_field_data,2) , array_stride(loc_field_data,1) /)
159 lextents = (/ 1, size (loc_field_data,2) , size (loc_field_data,1) /)
160 lview => array_view1d(loc_field_data)
161 call atlas__Checksum__execute_strided_${ctype}$( this%CPTR_PGIBUG_A, &
162 & lview, lstrides, lextents, lrank, checksum_c_str )
163 checksum = c_str_to_string(checksum_c_str)
164 end function
165
166 #:endfor
167
168 !-------------------------------------------------------------------------------
169
170 #if FCKIT_FINAL_NOT_INHERITING
171 ATLAS_FINAL subroutine atlas_Checksum__final_auto(this)
172 type(atlas_Checksum), intent(inout) :: this
173 #if FCKIT_FINAL_DEBUGGING
174 write(0,*) "atlas_Checksum__final_auto"
175 #endif
176 #if FCKIT_FINAL_NOT_PROPAGATING
177 call this%final()
178 #endif
179 FCKIT_SUPPRESS_UNUSED( this )
180 end subroutine
181 #endif
182
183 ! -----------------------------------------------------------------------------
184
185 end module atlas_checksum_module
186