Debian Codegraph @

src/atlas_f/util/atlas_allocate_module.F90

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
11 module atlas_allocate_module
12
13 implicit none
14 private
15
16 public :: atlas_allocate_managedmem
17 public :: atlas_deallocate_managedmem
18
19
20 interface atlas_allocate_managedmem
21 module procedure atlas_allocate_managedmem_real64_r1
22 module procedure atlas_allocate_managedmem_real32_r1
23 module procedure atlas_allocate_managedmem_int32_r1
24 module procedure atlas_allocate_managedmem_int64_r1_int32
25 module procedure atlas_allocate_managedmem_int64_r1_int64
26 module procedure atlas_allocate_managedmem_real64_r2
27 module procedure atlas_allocate_managedmem_real32_r2
28 module procedure atlas_allocate_managedmem_int32_r2
29 module procedure atlas_allocate_managedmem_int64_r2_int32
30 module procedure atlas_allocate_managedmem_int64_r2_int64
31 end interface
32
33 interface atlas_deallocate_managedmem
34 module procedure atlas_deallocate_managedmem_real64_r1
35 module procedure atlas_deallocate_managedmem_real32_r1
36 module procedure atlas_deallocate_managedmem_int32_r1
37 module procedure atlas_deallocate_managedmem_int64_r1
38 module procedure atlas_deallocate_managedmem_real64_r2
39 module procedure atlas_deallocate_managedmem_real32_r2
40 module procedure atlas_deallocate_managedmem_int32_r2
41 module procedure atlas_deallocate_managedmem_int64_r2
42 end interface
43
44 !------------------------------------------------------------------------------
45 contains
46 !------------------------------------------------------------------------------
47
48 subroutine atlas_allocate_managedmem_real64_r1( A, dims )
49 use, intrinsic :: iso_c_binding
50 use atlas_allocate_c_binding
51 real(c_double), pointer :: a(:)
52 integer(c_int) :: dims(:)
53 type(c_ptr) :: value_cptr
54 integer(c_size_t) :: size
55 size = dims(1)
56 if( size > 0 ) then
57 call atlas__allocate_managedmem_double( value_cptr, size )
58 call c_f_pointer(value_cptr,a,dims)
59 endif
60 end subroutine
61
62 subroutine atlas_allocate_managedmem_real32_r1( A, dims )
63 use, intrinsic :: iso_c_binding
64 use atlas_allocate_c_binding
65 real(c_float), pointer :: a(:)
66 integer(c_int) :: dims(:)
67 type(c_ptr) :: value_cptr
68 integer(c_size_t) :: size
69 size = dims(1)
70 if( size > 0 ) then
71 call atlas__allocate_managedmem_float( value_cptr, size )
72 call c_f_pointer(value_cptr,a,dims)
73 endif
74 end subroutine
75
76 subroutine atlas_allocate_managedmem_int32_r1( A, dims )
77 use, intrinsic :: iso_c_binding
78 use atlas_allocate_c_binding
79 integer(c_int), pointer :: a(:)
80 integer(c_int) :: dims(:)
81 type(c_ptr) :: value_cptr
82 integer(c_size_t) :: size
83 size = dims(1)
84 if( size > 0 ) then
85 call atlas__allocate_managedmem_int( value_cptr, size )
86 call c_f_pointer(value_cptr,a,dims)
87 endif
88 end subroutine
89
90 subroutine atlas_allocate_managedmem_int64_r1_int32( A, dims )
91 use, intrinsic :: iso_c_binding
92 use atlas_allocate_c_binding
93 integer(c_long), pointer :: a(:)
94 integer(c_int32_t) :: dims(:)
95 type(c_ptr) :: value_cptr
96 integer(c_size_t) :: size
97 size = dims(1)
98 if( size > 0 ) then
99 call atlas__allocate_managedmem_long( value_cptr, size )
100 call c_f_pointer(value_cptr,a,dims)
101 endif
102 end subroutine
103
104 subroutine atlas_allocate_managedmem_int64_r1_int64( A, dims )
105 use, intrinsic :: iso_c_binding
106 use atlas_allocate_c_binding
107 integer(c_long), pointer :: a(:)
108 integer(c_int64_t) :: dims(:)
109 type(c_ptr) :: value_cptr
110 integer(c_size_t) :: size
111 size = dims(1)
112 if( size > 0 ) then
113 call atlas__allocate_managedmem_long( value_cptr, size )
114 call c_f_pointer(value_cptr,a,dims)
115 endif
116 end subroutine
117
118 subroutine atlas_allocate_managedmem_int32_r2( A, dims )
119 use, intrinsic :: iso_c_binding
120 use atlas_allocate_c_binding
121 integer(c_int), pointer :: a(:,:)
122 integer(c_int) :: dims(:)
123 type(c_ptr) :: value_cptr
124 integer(c_size_t) :: size
125 size = dims(1)*dims(2)
126 if( size > 0 ) then
127 call atlas__allocate_managedmem_int( value_cptr, size )
128 call c_f_pointer(value_cptr,a,dims)
129 endif
130 end subroutine
131
132 subroutine atlas_allocate_managedmem_int64_r2_int32( A, dims )
133 use, intrinsic :: iso_c_binding
134 use atlas_allocate_c_binding
135 integer(c_long), pointer :: a(:,:)
136 integer(c_int32_t) :: dims(:)
137 type(c_ptr) :: value_cptr
138 integer(c_size_t) :: size
139 size = dims(1)*dims(2)
140 if( size > 0 ) then
141 call atlas__allocate_managedmem_long( value_cptr, size )
142 call c_f_pointer(value_cptr,a,dims)
143 endif
144 end subroutine
145
146 subroutine atlas_allocate_managedmem_int64_r2_int64( A, dims )
147 use, intrinsic :: iso_c_binding
148 use atlas_allocate_c_binding
149 integer(c_long), pointer :: a(:,:)
150 integer(c_int64_t) :: dims(:)
151 type(c_ptr) :: value_cptr
152 integer(c_size_t) :: size
153 size = dims(1)*dims(2)
154 if( size > 0 ) then
155 call atlas__allocate_managedmem_long( value_cptr, size )
156 call c_f_pointer(value_cptr,a,dims)
157 endif
158 end subroutine
159
160 subroutine atlas_allocate_managedmem_real64_r2( A, dims )
161 use, intrinsic :: iso_c_binding
162 use atlas_allocate_c_binding
163 real(c_double), pointer :: a(:,:)
164 integer(c_int) :: dims(:)
165 type(c_ptr) :: value_cptr
166 integer(c_size_t) :: size
167 size = dims(1)*dims(2)
168 if( size > 0 ) then
169 call atlas__allocate_managedmem_double( value_cptr, size )
170 call c_f_pointer(value_cptr,a,dims)
171 endif
172 end subroutine
173
174 subroutine atlas_allocate_managedmem_real32_r2( A, dims )
175 use, intrinsic :: iso_c_binding
176 use atlas_allocate_c_binding
177 real(c_float), pointer :: a(:,:)
178 integer(c_int) :: dims(:)
179 type(c_ptr) :: value_cptr
180 integer(c_size_t) :: size
181 size = dims(1)*dims(2)
182 if( size > 0 ) then
183 call atlas__allocate_managedmem_float( value_cptr, size )
184 call c_f_pointer(value_cptr,a,dims)
185 endif
186 end subroutine
187
188 !------------------------------------------------------------------------------
189
190 ! These functions are private in fckit_array_module
191
192 function c_loc_int32(x)
193 use, intrinsic :: iso_c_binding
194 integer(c_int32_t), target :: x
195 type(c_ptr) :: c_loc_int32
196 c_loc_int32 = c_loc(x)
197 end function
198
199 ! =============================================================================
200
201 function c_loc_int64(x)
202 use, intrinsic :: iso_c_binding
203 integer(c_int64_t), target :: x
204 type(c_ptr) :: c_loc_int64
205 c_loc_int64 = c_loc(x)
206 end function
207
208 ! =============================================================================
209
210 function c_loc_real32(x)
211 use, intrinsic :: iso_c_binding
212 real(c_float), target :: x
213 type(c_ptr) :: c_loc_real32
214 c_loc_real32 = c_loc(x)
215 end function
216
217 ! =============================================================================
218
219 function c_loc_real64(x)
220 use, intrinsic :: iso_c_binding
221 real(c_double), target :: x
222 type(c_ptr) :: c_loc_real64
223 c_loc_real64 = c_loc(x)
224 end function
225
226 ! =============================================================================
227
228 !------------------------------------------------------------------------------
229
230 subroutine atlas_deallocate_managedmem_real64_r1( A )
231 use, intrinsic :: iso_c_binding
232 use atlas_allocate_c_binding
233 real(c_double), pointer :: a(:)
234 call atlas__deallocate_managedmem_double( c_loc_real64(A(1)), size(A,KIND=c_size_t) )
235 nullify( a )
236 end subroutine
237
238 subroutine atlas_deallocate_managedmem_real32_r1( A )
239 use, intrinsic :: iso_c_binding
240 use atlas_allocate_c_binding
241 real(c_float), pointer :: a(:)
242 call atlas__deallocate_managedmem_float( c_loc_real32(A(1)), size(A,KIND=c_size_t) )
243 nullify( a )
244 end subroutine
245
246 subroutine atlas_deallocate_managedmem_int32_r1( A )
247 use, intrinsic :: iso_c_binding
248 use atlas_allocate_c_binding
249 integer(c_int), pointer :: a(:)
250 call atlas__deallocate_managedmem_int( c_loc_int32(A(1)), size(A,KIND=c_size_t) )
251 nullify( a )
252 end subroutine
253
254 subroutine atlas_deallocate_managedmem_int64_r1( A )
255 use, intrinsic :: iso_c_binding
256 use atlas_allocate_c_binding
257 integer(c_long), pointer :: a(:)
258 call atlas__deallocate_managedmem_long( c_loc_int64(A(1)), size(A,KIND=c_size_t) )
259 nullify( a )
260 end subroutine
261
262 subroutine atlas_deallocate_managedmem_real64_r2( A )
263 use, intrinsic :: iso_c_binding
264 use atlas_allocate_c_binding
265 real(c_double), pointer :: a(:,:)
266 call atlas__deallocate_managedmem_double( c_loc_real64(A(1,1)), size(A,KIND=c_size_t) )
267 nullify( a )
268 end subroutine
269
270 subroutine atlas_deallocate_managedmem_real32_r2( A )
271 use, intrinsic :: iso_c_binding
272 use atlas_allocate_c_binding
273 real(c_float), pointer :: a(:,:)
274 call atlas__deallocate_managedmem_float( c_loc_real32(A(1,1)), size(A,KIND=c_size_t) )
275 nullify( a )
276 end subroutine
277
278 subroutine atlas_deallocate_managedmem_int32_r2( A )
279 use, intrinsic :: iso_c_binding
280 use atlas_allocate_c_binding
281 integer(c_int), pointer :: a(:,:)
282 call atlas__deallocate_managedmem_int( c_loc_int32(A(1,1)), size(A,KIND=c_size_t) )
283 nullify( a )
284 end subroutine
285
286 subroutine atlas_deallocate_managedmem_int64_r2( A )
287 use, intrinsic :: iso_c_binding
288 use atlas_allocate_c_binding
289 integer(c_long), pointer :: a(:,:)
290 call atlas__deallocate_managedmem_long( c_loc_int64(A(1,1)), size(A,KIND=c_size_t) )
291 nullify( a )
292 end subroutine
293
294 !------------------------------------------------------------------------------
295
296 end module atlas_allocate_module
297