Debian Codegraph @

src/atlas_f/field/atlas_FieldSet_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
11 #:include "atlas/atlas_f.fypp"
12 #:include "internals/atlas_generics.fypp"
13
14 module atlas_FieldSet_module
15
16 use fckit_owned_object_module, only: fckit_owned_object
17 use atlas_field_module, only: atlas_field, array_c_to_f
18 use atlas_kinds_module, only : ATLAS_KIND_IDX
19
20 implicit none
21
22 private :: fckit_owned_object
23
24 public :: atlas_FieldSet
25
26 private
27
28 !------------------------------------------------------------------------------
29 TYPE, extends(fckit_owned_object) :: atlas_FieldSet
30
31 ! Purpose :
32 ! -------
33 ! *FieldSet* : Object that groups Fields that go together
34 ! Fields can belong to several fieldsets simultaneously.
35 ! The actual ownership of the field lies in a FunctionSpace
36
37 ! Methods :
38 ! -------
39 ! add_field : The name or tag this field was created with
40 ! field : Return the field as a fortran array of specified shape
41
42 ! Author :
43 ! ------
44 ! 20-Nov-2013 Willem Deconinck *ECMWF*
45
46 !------------------------------------------------------------------------------
47 contains
48 procedure, public :: name => FieldSet__name
49 procedure, public :: size => FieldSet__size
50 procedure, public :: has
51 procedure, private :: field_by_name
52 procedure, private :: field_by_idx_int
53 procedure, private :: field_by_idx_long
54 procedure, public :: add_field
55 procedure, public :: add_fieldset
56 generic :: add => add_field, add_fieldset
57 generic :: field => field_by_name, field_by_idx_int, field_by_idx_long
58
59 procedure, public :: set_dirty
60 procedure, public :: halo_exchange
61
62 #:for rank in ranks
63 #:for dtype in dtypes
64 procedure, private :: access_data_${dtype}$_r${rank}$_by_name
65 procedure, private :: access_data_${dtype}$_r${rank}$_by_idx
66 procedure, private :: access_data_${dtype}$_r${rank}$_slice_by_name
67 procedure, private :: access_data_${dtype}$_r${rank}$_slice_by_idx
68 procedure, private :: access_device_data_${dtype}$_r${rank}$_by_name
69 procedure, private :: access_device_data_${dtype}$_r${rank}$_by_idx
70 #:endfor
71 #:endfor
72
73 generic, public :: data => &
74 #:for rank in ranks
75 #:for dtype in dtypes
76 & access_data_${dtype}$_r${rank}$_by_name, &
77 & access_data_${dtype}$_r${rank}$_by_idx, &
78 & access_data_${dtype}$_r${rank}$_slice_by_name, &
79 & access_data_${dtype}$_r${rank}$_slice_by_idx, &
80 #:endfor
81 #:endfor
82 & dummy
83
84 generic, public :: device_data => &
85 #:for rank in ranks
86 #:for dtype in dtypes
87 & access_device_data_${dtype}$_r${rank}$_by_name, &
88 & access_device_data_${dtype}$_r${rank}$_by_idx, &
89 #:endfor
90 #:endfor
91 & dummy
92
93 procedure, private :: dummy
94
95 procedure, public :: set_host_needs_update_idx
96 procedure, public :: set_host_needs_update_value
97 procedure, public :: set_host_needs_update_name
98 generic :: set_host_needs_update => set_host_needs_update_idx, set_host_needs_update_value, &
99 set_host_needs_update_name
100 procedure, public :: set_device_needs_update_idx
101 procedure, public :: set_device_needs_update_value
102 procedure, public :: set_device_needs_update_name
103 generic :: set_device_needs_update => set_device_needs_update_idx, set_device_needs_update_value, &
104 set_device_needs_update_name
105 procedure, public :: sync_host_device_idx
106 procedure, public :: sync_host_device_name
107 generic :: sync_host_device => sync_host_device_idx, sync_host_device_name
108 procedure, public :: sync_host_idx
109 procedure, public :: sync_host_name
110 generic :: sync_host => sync_host_idx, sync_host_name
111 procedure, public :: sync_device_idx
112 procedure, public :: sync_device_name
113 generic :: sync_device => sync_device_idx, sync_device_name
114 procedure, public :: allocate_device_idx
115 procedure, public :: allocate_device_name
116 generic :: allocate_device => allocate_device_idx, allocate_device_name
117 procedure, public :: update_device_idx
118 procedure, public :: update_device_name
119 generic :: update_device => update_device_idx, update_device_name
120 procedure, public :: update_host_idx
121 procedure, public :: update_host_name
122 generic :: update_host => update_host_idx, update_host_name
123 procedure, public :: deallocate_device_idx
124 procedure, public :: deallocate_device_name
125 generic :: deallocate_device => deallocate_device_idx, deallocate_device_name
126
127 #if FCKIT_FINAL_NOT_INHERITING
128 final :: atlas_FieldSet__final_auto
129 #endif
130 procedure, public :: has_field => has ! deprecated !
131
132 END TYPE atlas_FieldSet
133 !------------------------------------------------------------------------------
134
135 interface atlas_FieldSet
136 module procedure atlas_FieldSet__cptr
137 module procedure atlas_FieldSet__ctor
138 end interface
139
140 !------------------------------------------------------------------------------
141
142
143 !========================================================
144 contains
145 !========================================================
146 ! -----------------------------------------------------------------------------
147 ! FieldSet routines
148
149 #:for rank in ranks
150 #:for dtype,ftype,ctype in types
151 subroutine access_data_${dtype}$_r${rank}$_by_name(this, name, field)
152 use fckit_c_interop_module, only: c_str
153 use atlas_fieldset_c_binding
154 use, intrinsic :: iso_c_binding, only : c_ptr, c_int, c_long, c_float, c_double
155 class(atlas_FieldSet), intent(in) :: this
156 character(len=*), intent(in) :: name
157 ${ftype}$, pointer, intent(inout) :: field(${dim[rank]}$)
158 type(c_ptr) :: field_cptr
159 type(c_ptr) :: shape_cptr
160 type(c_ptr) :: strides_cptr
161 integer(c_int) :: rank
162 call atlas__FieldSet__data_${ctype}$_specf(this%CPTR_PGIBUG_A, c_str(name), field_cptr, rank, shape_cptr, strides_cptr)
163 call array_c_to_f(field_cptr, rank, shape_cptr, strides_cptr, field)
164 end subroutine
165 subroutine access_data_${dtype}$_r${rank}$_by_idx(this, idx, field)
166 use fckit_c_interop_module, only: c_str
167 use atlas_fieldset_c_binding
168 use, intrinsic :: iso_c_binding, only : c_ptr, c_int, c_long, c_float, c_double
169 class(atlas_FieldSet), intent(in) :: this
170 integer, intent(in) :: idx
171 ${ftype}$, pointer, intent(inout) :: field(${dim[rank]}$)
172 type(c_ptr) :: field_cptr
173 type(c_ptr) :: shape_cptr
174 type(c_ptr) :: strides_cptr
175 integer(c_int) :: rank
176 call atlas__FieldSet__data_${ctype}$_specf_by_idx(this%CPTR_PGIBUG_A, idx-1, field_cptr, rank, shape_cptr, strides_cptr)
177 call array_c_to_f(field_cptr, rank, shape_cptr, strides_cptr, field)
178 end subroutine
179 subroutine access_data_${dtype}$_r${rank}$_slice_by_name(this, name, slice, iblk)
180 use fckit_c_interop_module, only: c_str
181 use atlas_fieldset_c_binding
182 use, intrinsic :: iso_c_binding, only : c_ptr, c_int, c_long, c_float, c_double
183 class(atlas_FieldSet), intent(in) :: this
184 character(len=*), intent(in) :: name
185 #:if rank > 1
186 ${ftype}$, pointer, intent(inout) :: slice(${dimr[rank]}$)
187 #:else
188 ${ftype}$, pointer, intent(inout) :: slice
189 #:endif
190 integer, intent(in) :: iblk
191 ${ftype}$, pointer :: field(${dim[rank]}$)
192 call access_data_${dtype}$_r${rank}$_by_name(this, c_str(name), field)
193 #:if rank > 1
194 slice => field(${dimr[rank]}$, iblk)
195 #:else
196 slice => field(iblk)
197 #:endif
198 end subroutine
199 subroutine access_data_${dtype}$_r${rank}$_slice_by_idx(this, idx, slice, iblk)
200 use fckit_c_interop_module, only: c_str
201 use atlas_fieldset_c_binding
202 use, intrinsic :: iso_c_binding, only : c_ptr, c_int, c_long, c_float, c_double
203 class(atlas_FieldSet), intent(in) :: this
204 integer, intent(in) :: idx
205 #:if rank > 1
206 ${ftype}$, pointer, intent(inout) :: slice(${dimr[rank]}$)
207 #:else
208 ${ftype}$, pointer, intent(inout) :: slice
209 #:endif
210 integer, intent(in) :: iblk
211 ${ftype}$, pointer :: field(${dim[rank]}$)
212 call access_data_${dtype}$_r${rank}$_by_idx(this, idx, field)
213 #:if rank > 1
214 slice => field(${dimr[rank]}$, iblk)
215 #:else
216 slice => field(iblk)
217 #:endif
218 end subroutine
219
220 !-------------------------------------------------------------------------------
221
222 subroutine access_device_data_${dtype}$_r${rank}$_by_name(this, name, field)
223 use fckit_c_interop_module, only: c_str
224 use atlas_field_c_binding
225 use atlas_Field_module, only: atlas_Field
226 use, intrinsic :: iso_c_binding, only : c_ptr, c_int, c_long, c_float, c_double
227 class(atlas_FieldSet), intent(in) :: this
228 character(len=*), intent(in) :: name
229 ${ftype}$, pointer, intent(inout) :: field(${dim[rank]}$)
230 type(c_ptr) :: field_cptr
231 type(c_ptr) :: shape_cptr
232 type(c_ptr) :: strides_cptr
233 integer(c_int) :: rank
234 type(atlas_Field) :: field_sel
235 field_sel = this%field(name)
236 call atlas__Field__device_data_${ctype}$_specf(field_sel%CPTR_PGIBUG_A, field_cptr, rank, shape_cptr, strides_cptr)
237 call array_c_to_f(field_cptr, rank, shape_cptr, strides_cptr, field)
238 end subroutine
239
240 !-------------------------------------------------------------------------------
241
242 subroutine access_device_data_${dtype}$_r${rank}$_by_idx(this, idx, field)
243 use fckit_c_interop_module, only: c_str
244 use atlas_field_c_binding
245 use atlas_Field_module, only: atlas_Field
246 use, intrinsic :: iso_c_binding, only : c_ptr, c_int, c_long, c_float, c_double
247 class(atlas_FieldSet), intent(in) :: this
248 integer, intent(in) :: idx
249 ${ftype}$, pointer, intent(inout) :: field(${dim[rank]}$)
250 type(c_ptr) :: field_cptr
251 type(c_ptr) :: shape_cptr
252 type(c_ptr) :: strides_cptr
253 integer(c_int) :: rank
254 type(atlas_Field) :: field_loc
255 field_loc = this%field(idx)
256 call atlas__Field__device_data_${ctype}$_specf(field_loc%CPTR_PGIBUG_A, field_cptr, rank, shape_cptr, strides_cptr)
257 call array_c_to_f(field_cptr, rank, shape_cptr, strides_cptr, field)
258 end subroutine
259
260 !-------------------------------------------------------------------------------
261
262 #:endfor
263 #:endfor
264
265 subroutine dummy(this)
266 use atlas_fieldset_c_binding
267 class(atlas_FieldSet), intent(in) :: this
268 FCKIT_SUPPRESS_UNUSED(this)
269 end subroutine
270
271 function atlas_FieldSet__cptr(cptr) result(fieldset)
272 use, intrinsic :: iso_c_binding, only: c_ptr
273 type(atlas_FieldSet) :: fieldset
274 type(c_ptr), intent(in) :: cptr
275 call fieldset%reset_c_ptr( cptr )
276 call fieldset%return()
277 end function
278
279 function atlas_FieldSet__ctor(name) result(fieldset)
280 use fckit_c_interop_module, only: c_str
281 use atlas_fieldset_c_binding
282 character(len=*), intent(in), optional :: name
283 type(atlas_FieldSet) :: fieldset
284 if( present(name) ) then
285 fieldset = atlas_FieldSet__cptr( atlas__FieldSet__new( c_str(name) ) )
286 else
287 fieldset = atlas_FieldSet__cptr( atlas__FieldSet__new( c_str("") ) )
288 endif
289 call fieldset%return()
290 end function
291
292 function FieldSet__name(this) result(fieldset_name)
293 use, intrinsic :: iso_c_binding, only : c_ptr
294 use fckit_c_interop_module, only : c_ptr_to_string, c_str
295 use atlas_fieldset_c_binding
296 class(atlas_FieldSet), intent(in) :: this
297 character(len=:), allocatable :: fieldset_name
298 type(c_ptr) :: fieldset_name_c_str
299 fieldset_name_c_str = atlas__FieldSet__name(this%CPTR_PGIBUG_A)
300 fieldset_name = c_ptr_to_string(fieldset_name_c_str)
301 end function FieldSet__name
302
303 subroutine add_field(this,field)
304 use atlas_fieldset_c_binding
305 use atlas_Field_module, only: atlas_Field
306 class(atlas_FieldSet), intent(in) :: this
307 type(atlas_Field), intent(in) :: field
308 call atlas__FieldSet__add_field(this%CPTR_PGIBUG_A, field%CPTR_PGIBUG_A)
309 end subroutine
310
311 subroutine add_fieldset(this,fset)
312 use atlas_fieldset_c_binding
313 class(atlas_FieldSet), intent(inout) :: this
314 class(atlas_FieldSet), intent(in) :: fset
315 call atlas__FieldSet__add_fieldset(this%CPTR_PGIBUG_A, fset%CPTR_PGIBUG_A)
316 end subroutine
317
318 function has(this,name) result(flag)
319 use, intrinsic :: iso_c_binding, only: c_int
320 use fckit_c_interop_module, only: c_str
321 use atlas_fieldset_c_binding
322 class(atlas_FieldSet), intent(in) :: this
323 character(len=*), intent(in) :: name
324 logical :: flag
325 integer(c_int) :: rc
326 rc = atlas__FieldSet__has_field(this%CPTR_PGIBUG_A, c_str(name))
327 if( rc == 0 ) then
328 flag = .False.
329 else
330 flag = .True.
331 end if
332 end function
333
334
335 function FieldSet__size(this) result(nb_fields)
336 use atlas_fieldset_c_binding
337 class(atlas_FieldSet), intent(in) :: this
338 integer(ATLAS_KIND_IDX) :: nb_fields
339 nb_fields = atlas__FieldSet__size(this%CPTR_PGIBUG_A)
340 end function
341
342 function field_by_name(this,name) result(field)
343 use fckit_c_interop_module, only: c_str
344 use atlas_fieldset_c_binding
345 use atlas_Field_module, only: atlas_Field
346 class(atlas_FieldSet), intent(in) :: this
347 character(len=*), intent(in) :: name
348 type(atlas_Field) :: field
349 field = atlas_Field( atlas__FieldSet__field_by_name(this%CPTR_PGIBUG_A, c_str(name) ) )
350 call field%return()
351 end function
352
353 function field_by_idx_long(this,idx) result(field)
354 use, intrinsic :: iso_c_binding, only: c_long
355 use atlas_fieldset_c_binding
356 use atlas_Field_module, only: atlas_Field
357 class(atlas_FieldSet), intent(in) :: this
358 integer(c_long), intent(in) :: idx
359 type(atlas_Field) :: field
360 field = atlas_Field( atlas__FieldSet__field_by_idx(this%CPTR_PGIBUG_A, int(idx-1_c_long,ATLAS_KIND_IDX) ) ) ! C index
361 call field%return()
362 end function
363
364 function field_by_idx_int(this,idx) result(field)
365 use, intrinsic :: iso_c_binding, only: c_int
366 use atlas_fieldset_c_binding
367 use atlas_Field_module, only: atlas_Field
368 class(atlas_FieldSet), intent(in) :: this
369 integer(c_int), intent(in) :: idx
370 type(atlas_Field) :: field
371 field = atlas_Field( atlas__FieldSet__field_by_idx(this%CPTR_PGIBUG_A, int(idx-1_c_int,ATLAS_KIND_IDX) ) ) ! C index
372 call field%return()
373 end function
374
375 !-------------------------------------------------------------------------------
376
377 subroutine halo_exchange(this,on_device)
378 use, intrinsic :: iso_c_binding, only : c_int
379 use atlas_fieldset_c_binding
380 class(atlas_FieldSet), intent(inout) :: this
381 logical, optional :: on_device
382 integer(c_int) :: on_device_int
383 on_device_int = 0
384 if( present(on_device) ) then
385 if( on_device ) on_device_int = 1
386 endif
387 call atlas__FieldSet__halo_exchange(this%CPTR_PGIBUG_A, on_device_int)
388 end subroutine
389
390 !-------------------------------------------------------------------------------
391
392 subroutine set_host_needs_update_value(this, value)
393 use, intrinsic :: iso_c_binding, only : c_int
394 use atlas_field_c_binding
395 use atlas_Field_module, only: atlas_Field
396 class(atlas_FieldSet), intent(inout) :: this
397 logical, intent(in), optional :: value
398 type(atlas_Field) :: field
399 integer(c_int) :: i, value_int
400 value_int = 1
401 if (present(value)) then
402 if (.not. value) then
403 value_int = 0
404 end if
405 end if
406 do i = 1, this%size()
407 field = this%field(i)
408 call atlas__Field__set_host_needs_update(field%CPTR_PGIBUG_A, value_int)
409 end do
410 end subroutine
411
412 !-------------------------------------------------------------------------------
413
414 subroutine set_host_needs_update_idx(this, field_indices, value)
415 use, intrinsic :: iso_c_binding, only : c_int
416 use atlas_field_c_binding
417 use atlas_Field_module, only: atlas_Field
418 class(atlas_FieldSet), intent(inout) :: this
419 integer, intent(in) :: field_indices(:)
420 logical, intent(in), optional :: value
421 type(atlas_Field) :: field
422 integer(c_int) :: i, value_int
423 value_int = 1
424 if (present(value)) then
425 if (.not. value) then
426 value_int = 0
427 end if
428 end if
429 do i = 1, size(field_indices)
430 field = this%field(field_indices(i))
431 call atlas__Field__set_host_needs_update(field%CPTR_PGIBUG_A, value_int)
432 end do
433 end subroutine
434
435 !-------------------------------------------------------------------------------
436
437 subroutine set_host_needs_update_name(this, field_names, value)
438 use, intrinsic :: iso_c_binding, only : c_int
439 use atlas_field_c_binding
440 use atlas_Field_module, only: atlas_Field
441 class(atlas_FieldSet), intent(inout) :: this
442 character(*), intent(in) :: field_names(:)
443 logical, intent(in), optional :: value
444 type(atlas_Field) :: field
445 integer(c_int) :: i, value_int
446 value_int = 1
447 if (present(value)) then
448 if (.not. value) then
449 value_int = 0
450 end if
451 end if
452 do i = 1, size(field_names)
453 field = this%field(field_names(i))
454 call atlas__Field__set_host_needs_update(field%CPTR_PGIBUG_A, value_int)
455 end do
456 end subroutine
457
458 !-------------------------------------------------------------------------------
459
460 subroutine set_device_needs_update_value(this, value)
461 use, intrinsic :: iso_c_binding, only : c_int
462 use atlas_field_c_binding
463 use atlas_Field_module, only: atlas_Field
464 class(atlas_FieldSet), intent(inout) :: this
465 logical, intent(in), optional :: value
466 type(atlas_Field) :: field
467 integer(c_int) :: i, value_int
468 value_int = 1
469 if (present(value)) then
470 if (.not. value) then
471 value_int = 0
472 end if
473 end if
474 do i = 1, this%size()
475 field = this%field(i)
476 call atlas__Field__set_device_needs_update(field%CPTR_PGIBUG_A, value_int)
477 end do
478 end subroutine
479
480 !-------------------------------------------------------------------------------
481
482 subroutine set_device_needs_update_idx(this, field_indices, value)
483 use, intrinsic :: iso_c_binding, only : c_int
484 use atlas_field_c_binding
485 use atlas_Field_module, only: atlas_Field
486 class(atlas_FieldSet), intent(inout) :: this
487 integer, intent(in) :: field_indices(:)
488 logical, intent(in), optional :: value
489 type(atlas_Field) :: field
490 integer(c_int) :: i, value_int
491 value_int = 1
492 if (present(value)) then
493 if (.not. value) then
494 value_int = 0
495 end if
496 end if
497 do i = 1, size(field_indices)
498 field = this%field(field_indices(i))
499 call atlas__Field__set_device_needs_update(field%CPTR_PGIBUG_A, value_int)
500 end do
501 end subroutine
502
503 !-------------------------------------------------------------------------------
504
505 subroutine set_device_needs_update_name(this, field_names, value)
506 use, intrinsic :: iso_c_binding, only : c_int
507 use atlas_field_c_binding
508 use atlas_Field_module, only: atlas_Field
509 class(atlas_FieldSet), intent(inout) :: this
510 character(*), intent(in) :: field_names(:)
511 logical, intent(in), optional :: value
512 type(atlas_Field) :: field
513 integer(c_int) :: i, value_int
514 value_int = 1
515 if (present(value)) then
516 if (.not. value) then
517 value_int = 0
518 end if
519 end if
520 do i = 1, size(field_names)
521 field = this%field(field_names(i))
522 call atlas__Field__set_device_needs_update(field%CPTR_PGIBUG_A, value_int)
523 end do
524 end subroutine
525
526 !-------------------------------------------------------------------------------
527
528 subroutine sync_host_device_idx(this, field_indices)
529 use, intrinsic :: iso_c_binding, only : c_int
530 use atlas_field_c_binding
531 use atlas_Field_module, only: atlas_Field
532 class(atlas_FieldSet), intent(inout) :: this
533 integer, intent(in), optional :: field_indices(:)
534 type(atlas_Field) :: field
535 integer(c_int) :: i
536 if (present(field_indices)) then
537 do i = 1, size(field_indices)
538 field = this%field(field_indices(i))
539 call atlas__Field__sync_host_device(field%CPTR_PGIBUG_A)
540 end do
541 else
542 do i = 1, this%size()
543 field = this%field(i)
544 call atlas__Field__sync_host_device(field%CPTR_PGIBUG_A)
545 end do
546 end if
547 end subroutine
548
549 !-------------------------------------------------------------------------------
550
551 subroutine sync_host_device_name(this, field_names)
552 use, intrinsic :: iso_c_binding, only : c_int
553 use atlas_field_c_binding
554 use atlas_Field_module, only: atlas_Field
555 class(atlas_FieldSet), intent(inout) :: this
556 character(*), intent(in) :: field_names(:)
557 type(atlas_Field) :: field
558 integer(c_int) :: i
559 do i = 1, size(field_names)
560 field = this%field(field_names(i))
561 call atlas__Field__sync_host_device(field%CPTR_PGIBUG_A)
562 end do
563 end subroutine
564
565 !-------------------------------------------------------------------------------
566
567 subroutine sync_host_idx(this, field_indices)
568 use, intrinsic :: iso_c_binding, only : c_int
569 use atlas_field_c_binding
570 use atlas_Field_module, only: atlas_Field
571 class(atlas_FieldSet), intent(inout) :: this
572 integer, intent(in), optional :: field_indices(:)
573 type(atlas_Field) :: field
574 integer(c_int) :: i
575 if (present(field_indices)) then
576 do i = 1, size(field_indices)
577 field = this%field(field_indices(i))
578 call atlas__Field__sync_host(field%CPTR_PGIBUG_A)
579 end do
580 else
581 do i = 1, this%size()
582 field = this%field(i)
583 call atlas__Field__sync_host(field%CPTR_PGIBUG_A)
584 end do
585 end if
586 end subroutine
587
588 !-------------------------------------------------------------------------------
589
590 subroutine sync_host_name(this, field_names)
591 use, intrinsic :: iso_c_binding, only : c_int
592 use atlas_field_c_binding
593 use atlas_Field_module, only: atlas_Field
594 class(atlas_FieldSet), intent(inout) :: this
595 character(*), intent(in) :: field_names(:)
596 type(atlas_Field) :: field
597 integer(c_int) :: i
598 do i = 1, size(field_names)
599 field = this%field(field_names(i))
600 call atlas__Field__sync_host(field%CPTR_PGIBUG_A)
601 end do
602 end subroutine
603
604 !-------------------------------------------------------------------------------
605
606 subroutine sync_device_idx(this, field_indices)
607 use, intrinsic :: iso_c_binding, only : c_int
608 use atlas_field_c_binding
609 use atlas_Field_module, only: atlas_Field
610 class(atlas_FieldSet), intent(inout) :: this
611 integer, intent(in), optional :: field_indices(:)
612 type(atlas_Field) :: field
613 integer(c_int) :: i
614 if (present(field_indices)) then
615 do i = 1, size(field_indices)
616 field = this%field(field_indices(i))
617 call atlas__Field__sync_device(field%CPTR_PGIBUG_A)
618 end do
619 else
620 do i = 1, this%size()
621 field = this%field(i)
622 call atlas__Field__sync_device(field%CPTR_PGIBUG_A)
623 end do
624 end if
625 end subroutine
626
627 !-------------------------------------------------------------------------------
628
629 subroutine sync_device_name(this, field_names)
630 use, intrinsic :: iso_c_binding, only : c_int
631 use atlas_field_c_binding
632 use atlas_Field_module, only: atlas_Field
633 class(atlas_FieldSet), intent(inout) :: this
634 character(*), intent(in) :: field_names(:)
635 type(atlas_Field) :: field
636 integer(c_int) :: i
637 do i = 1, size(field_names)
638 field = this%field(field_names(i))
639 call atlas__Field__sync_device(field%CPTR_PGIBUG_A)
640 end do
641 end subroutine
642
643 !-------------------------------------------------------------------------------
644
645 subroutine allocate_device_idx(this, field_indices)
646 use, intrinsic :: iso_c_binding, only : c_int
647 use atlas_field_c_binding
648 use atlas_Field_module, only: atlas_Field
649 class(atlas_FieldSet), intent(inout) :: this
650 integer, intent(in), optional :: field_indices(:)
651 type(atlas_Field) :: field
652 integer(c_int) :: i
653 if (present(field_indices)) then
654 do i = 1, size(field_indices)
655 field = this%field(field_indices(i))
656 call atlas__Field__allocate_device(field%CPTR_PGIBUG_A)
657 end do
658 else
659 do i = 1, this%size()
660 field = this%field(i)
661 call atlas__Field__allocate_device(field%CPTR_PGIBUG_A)
662 end do
663 end if
664 end subroutine
665
666 !-------------------------------------------------------------------------------
667
668 subroutine allocate_device_name(this, field_names)
669 use, intrinsic :: iso_c_binding, only : c_int
670 use atlas_field_c_binding
671 use atlas_Field_module, only: atlas_Field
672 class(atlas_FieldSet), intent(inout) :: this
673 character(*), intent(in) :: field_names(:)
674 type(atlas_Field) :: field
675 integer(c_int) :: i
676 do i = 1, size(field_names)
677 field = this%field(field_names(i))
678 call atlas__Field__allocate_device(field%CPTR_PGIBUG_A)
679 end do
680 end subroutine
681
682 !-------------------------------------------------------------------------------
683
684 subroutine update_device_idx(this, field_indices)
685 use, intrinsic :: iso_c_binding, only : c_int
686 use atlas_field_c_binding
687 use atlas_Field_module, only: atlas_Field
688 class(atlas_FieldSet), intent(inout) :: this
689 integer, intent(in), optional :: field_indices(:)
690 type(atlas_Field) :: field
691 integer(c_int) :: i
692 if (present(field_indices)) then
693 do i = 1, size(field_indices)
694 field = this%field(field_indices(i))
695 call atlas__Field__update_device(field%CPTR_PGIBUG_A)
696 end do
697 else
698 do i = 1, this%size()
699 field = this%field(i)
700 call atlas__Field__update_device(field%CPTR_PGIBUG_A)
701 end do
702 end if
703 end subroutine
704
705 !-------------------------------------------------------------------------------
706
707 subroutine update_device_name(this, field_names)
708 use, intrinsic :: iso_c_binding, only : c_int
709 use atlas_field_c_binding
710 use atlas_Field_module, only: atlas_Field
711 class(atlas_FieldSet), intent(inout) :: this
712 character(*), intent(in) :: field_names(:)
713 type(atlas_Field) :: field
714 integer(c_int) :: i
715 do i = 1, size(field_names)
716 field = this%field(field_names(i))
717 call atlas__Field__update_device(field%CPTR_PGIBUG_A)
718 end do
719 end subroutine
720
721 !-------------------------------------------------------------------------------
722
723 subroutine update_host_idx(this, field_indices)
724 use, intrinsic :: iso_c_binding, only : c_int
725 use atlas_field_c_binding
726 use atlas_Field_module, only: atlas_Field
727 class(atlas_FieldSet), intent(inout) :: this
728 integer, intent(in), optional :: field_indices(:)
729 type(atlas_Field) :: field
730 integer(c_int) :: i
731 if (present(field_indices)) then
732 do i = 1, size(field_indices)
733 field = this%field(field_indices(i))
734 call atlas__Field__update_host(field%CPTR_PGIBUG_A)
735 end do
736 else
737 do i = 1, this%size()
738 field = this%field(i)
739 call atlas__Field__update_host(field%CPTR_PGIBUG_A)
740 end do
741 end if
742 end subroutine
743
744 !-------------------------------------------------------------------------------
745
746 subroutine update_host_name(this, field_names)
747 use, intrinsic :: iso_c_binding, only : c_int
748 use atlas_field_c_binding
749 use atlas_Field_module, only: atlas_Field
750 class(atlas_FieldSet), intent(inout) :: this
751 character(*), intent(in) :: field_names(:)
752 type(atlas_Field) :: field
753 integer(c_int) :: i
754 do i = 1, size(field_names)
755 field = this%field(field_names(i))
756 call atlas__Field__update_host(field%CPTR_PGIBUG_A)
757 end do
758 end subroutine
759
760 !-------------------------------------------------------------------------------
761
762 subroutine deallocate_device_idx(this, field_indices)
763 use, intrinsic :: iso_c_binding, only : c_int
764 use atlas_field_c_binding
765 use atlas_Field_module, only: atlas_Field
766 class(atlas_FieldSet), intent(inout) :: this
767 integer, optional :: field_indices(:)
768 type(atlas_Field) :: field
769 integer(c_int) :: i
770 if (present(field_indices)) then
771 do i = 1, size(field_indices)
772 field = this%field(field_indices(i))
773 call atlas__Field__deallocate_device(field%CPTR_PGIBUG_A)
774 end do
775 else
776 do i = 1, this%size()
777 field = this%field(i)
778 call atlas__Field__deallocate_device(field%CPTR_PGIBUG_A)
779 end do
780 end if
781 end subroutine
782
783 !-------------------------------------------------------------------------------
784
785 subroutine deallocate_device_name(this, field_names)
786 use, intrinsic :: iso_c_binding, only : c_int
787 use atlas_field_c_binding
788 use atlas_Field_module, only: atlas_Field
789 class(atlas_FieldSet), intent(inout) :: this
790 character(*), intent(in) :: field_names(:)
791 type(atlas_Field) :: field
792 integer(c_int) :: i
793 do i = 1, size(field_names)
794 field = this%field(field_names(i))
795 call atlas__Field__deallocate_device(field%CPTR_PGIBUG_A)
796 end do
797 end subroutine
798
799 !-------------------------------------------------------------------------------
800
801 subroutine set_dirty(this,value)
802 use, intrinsic :: iso_c_binding, only : c_int
803 use atlas_fieldset_c_binding
804 class(atlas_FieldSet), intent(inout) :: this
805 logical, optional, intent(in) :: value
806 integer(c_int) :: value_int
807 if( present(value) ) then
808 if( value ) then
809 value_int = 1
810 else
811 value_int = 0
812 endif
813 else
814 value_int = 1
815 endif
816 call atlas__FieldSet__set_dirty(this%CPTR_PGIBUG_A, value_int)
817 end subroutine
818
819 !-------------------------------------------------------------------------------
820
821 #if FCKIT_FINAL_NOT_INHERITING
822 ATLAS_FINAL subroutine atlas_FieldSet__final_auto(this)
823 type(atlas_FieldSet), intent(inout) :: this
824 #if FCKIT_FINAL_DEBUGGING
825 write(0,*) "atlas_FieldSet__final_auto"
826 #endif
827 #if FCKIT_FINAL_NOT_PROPAGATING
828 call this%final()
829 #endif
830 FCKIT_SUPPRESS_UNUSED( this )
831 end subroutine
832 #endif
833
834 ! ----------------------------------------------------------------------------------------
835
836 end module atlas_FieldSet_module