! (C) Copyright 2013 ECMWF. ! ! This software is licensed under the terms of the Apache Licence Version 2.0 ! which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. ! In applying this licence, ECMWF does not waive the privileges and immunities ! granted to it by virtue of its status as an intergovernmental organisation nor ! does it submit to any jurisdiction. #include "atlas/atlas_f.h" #:include "internals/atlas_generics.fypp" #:set ranks = [1,2,3,4] module atlas_haloexchange_module use, intrinsic :: iso_c_binding, only : c_ptr, c_int, c_long, c_float, c_double use fckit_array_module, only : array_stride, array_view1d use fckit_object_module, only : fckit_object use atlas_kinds_module, only : ATLAS_KIND_IDX implicit none private :: c_ptr, c_int, c_long, c_float, c_double private :: array_stride, array_view1d private :: fckit_object public :: atlas_HaloExchange private !------------------------------------------------------------------------------ TYPE, extends(fckit_object) :: atlas_HaloExchange ! Purpose : ! ------- ! *HaloExchange* : ! Methods : ! ------- ! setup : Setup using arrays detailing proc and glb_idx, bounds and parbound ! execute : Do the halo exchange ! Author : ! ------ ! 17-Dec-2013 Willem Deconinck *ECMWF* !------------------------------------------------------------------------------ contains procedure :: setup => HaloExchange__setup @:generic_public_interface( execute, HaloExchange__execute ) procedure, public :: delete => atlas_HaloExchange__delete #if FCKIT_FINAL_NOT_INHERITING final :: atlas_HaloExchange__final_auto #endif END TYPE atlas_HaloExchange !------------------------------------------------------------------------------ interface atlas_HaloExchange module procedure atlas_HaloExchange__ctor end interface !======================================================== contains !======================================================== ! ------------------------------------------------------------------------------ ! HaloExchange routines function atlas_HaloExchange__ctor() result(halo_exchange) use atlas_haloexchange_c_binding type(atlas_HaloExchange) :: halo_exchange call halo_exchange%reset_c_ptr( atlas__HaloExchange__new() ) end function atlas_HaloExchange__ctor subroutine atlas_HaloExchange__delete(this) use atlas_haloexchange_c_binding class(atlas_HaloExchange), intent(inout) :: this if ( .not. this%is_null() ) then call atlas__HaloExchange__delete(this%CPTR_PGIBUG_A) end if call this%reset_c_ptr() end subroutine atlas_HaloExchange__delete subroutine HaloExchange__setup(this, part, remote_idx) use atlas_haloexchange_c_binding class(atlas_HaloExchange), intent(in) :: this integer(c_int), intent(in) :: part(:) integer(ATLAS_KIND_IDX), intent(in) :: remote_idx(:) call atlas__HaloExchange__setup( this%CPTR_PGIBUG_A, part, remote_idx, 1, size(part) ) end subroutine HaloExchange__setup #:for dtype,ftype,ctype in types[:4] subroutine HaloExchange__execute_${dtype}$_r1(this, field_data) use atlas_haloexchange_c_binding class(atlas_HaloExchange), intent(in) :: this ${ftype}$, intent(inout) :: field_data(:) integer :: strides(1), extents(1) strides = (/ array_stride(field_data,1) /) extents = (/ 1 /) call atlas__HaloExchange__execute_strided_${ctype}$( this%CPTR_PGIBUG_A, field_data, & & strides, extents, 1 ) end subroutine subroutine HaloExchange__execute_${dtype}$_r2(this, field_data) use atlas_haloexchange_c_binding class(atlas_HaloExchange), intent(in) :: this ${ftype}$, intent(inout) :: field_data(:,:) ${ftype}$, pointer :: view(:) integer :: strides(2), extents(2) view => array_view1d(field_data) strides = (/ array_stride(field_data,2) , array_stride(field_data,1) /) extents = (/ 1 , ubound(field_data,1) /) call atlas__HaloExchange__execute_strided_${ctype}$( this%CPTR_PGIBUG_A, view, & & strides, extents, 2 ) end subroutine subroutine HaloExchange__execute_${dtype}$_r3(this, field_data) use atlas_haloexchange_c_binding class(atlas_HaloExchange), intent(in) :: this ${ftype}$, intent(inout) :: field_data(:,:,:) ${ftype}$, pointer :: view(:) integer :: strides(3), extents(3) view => array_view1d(field_data) strides = (/ array_stride(field_data,3), array_stride(field_data,2) , array_stride(field_data,1) /) extents = (/ 1, ubound(field_data,2) , ubound(field_data,1) /) call atlas__HaloExchange__execute_strided_${ctype}$( this%CPTR_PGIBUG_A, view, & & strides, extents, 3 ) end subroutine subroutine HaloExchange__execute_${dtype}$_r4(this, field_data) use atlas_haloexchange_c_binding class(atlas_HaloExchange), intent(in) :: this ${ftype}$, intent(inout) :: field_data(:,:,:,:) ${ftype}$, pointer :: view(:) integer :: strides(4), extents(4) view => array_view1d(field_data) strides = (/ array_stride(field_data,4), array_stride(field_data,3), array_stride(field_data,2) , & array_stride(field_data,1) /) extents = (/ 1, ubound(field_data,3) , ubound(field_data,2) , ubound(field_data,1) /) call atlas__HaloExchange__execute_strided_${ctype}$( this%CPTR_PGIBUG_A, view, & & strides, extents, 4 ) end subroutine #:endfor !------------------------------------------------------------------------------- #if FCKIT_FINAL_NOT_INHERITING ATLAS_FINAL subroutine atlas_HaloExchange__final_auto(this) type(atlas_HaloExchange), intent(inout) :: this #if FCKIT_FINAL_DEBUGGING write(0,*) "atlas_HaloExchange__final_auto" #endif #if FCKIT_FINAL_NOT_PROPAGATING call this%final() #endif FCKIT_SUPPRESS_UNUSED( this ) end subroutine #endif ! ----------------------------------------------------------------------------- end module atlas_haloexchange_module