-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from pmarguinaud/field_gang
Field gang
- Loading branch information
Showing
60 changed files
with
2,073 additions
and
547 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
#! (C) Copyright 2022- ECMWF. | ||
#! (C) Copyright 2022- Meteo-France. | ||
#! | ||
#! 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. | ||
|
||
MODULE FIELD_${RANK}$${SUFF}$_DATA_MODULE | ||
|
||
#:set fieldTypeList = fieldType.getFieldTypeList (ranks=[RANK], kinds=['JP' + str (SUFF)]) | ||
|
||
USE FIELD_CONSTANTS_MODULE | ||
${fieldType.useParkind1 ()}$ | ||
|
||
IMPLICIT NONE | ||
|
||
CONTAINS | ||
|
||
#:for ft in fieldTypeList | ||
#:set ftn = ft.name | ||
|
||
#:for d in range (0, ft.rank+1) | ||
SUBROUTINE ${ftn}$_COPY_DIM${d}$_CONTIGUOUS (HST, DEV, MAP_DEVPTR, KDIR, QUEUE) | ||
#ifdef _OPENACC | ||
USE OPENACC | ||
#endif | ||
${ft.type}$ :: HST (${ft.shape}$), DEV (${ft.shape}$) | ||
LOGICAL, INTENT (IN) :: MAP_DEVPTR | ||
INTEGER (KIND=JPIM), INTENT (IN) :: KDIR | ||
INTEGER (KIND=JPIM), OPTIONAL, INTENT (IN) :: QUEUE | ||
INTEGER (KIND=JPIM) :: ISIZE | ||
INTEGER :: ${', '.join (['J'] + list (map (lambda i: 'J' + str (i+1), range (d, ft.rank))))}$ | ||
#ifdef _OPENACC | ||
TYPE(C_DEVPTR) :: DEVPTR | ||
#endif | ||
|
||
#:for e in range (ft.rank, d, -1) | ||
${' ' * (ft.rank - e)}$DO J${e}$ = LBOUND (HST, ${e}$), UBOUND (HST, ${e}$) | ||
#:endfor | ||
#:set ar = ', '.join ([':'] * d + list (map (lambda i: 'J' + str (i+1), range (d, ft.rank)))) | ||
#:set indent = ' ' * (ft.rank - e) | ||
#ifdef _OPENACC | ||
${indent}$ IF(MAP_DEVPTR)THEN | ||
${indent}$ DEVPTR = ACC_DEVICEPTR(DEV (${ar}$)) | ||
${indent}$ ELSE | ||
#:if defined('CUDA') | ||
!$acc data deviceptr(DEVPTR, DEV) | ||
${indent}$ DEVPTR = C_DEVLOC(DEV (${ar}$)) | ||
!$acc end data | ||
#:endif | ||
${indent}$ ENDIF | ||
#endif | ||
#:if d == 0 | ||
${indent}$ ISIZE = KIND (HST) | ||
#:else | ||
${indent}$ ISIZE = KIND (HST) * SIZE (HST (${ar}$)) | ||
#:endif | ||
${indent}$ IF (KDIR == NH2D) THEN | ||
#ifdef _OPENACC | ||
${indent}$ IF(PRESENT(QUEUE))THEN | ||
${indent}$ CALL ACC_MEMCPY_TO_DEVICE_ASYNC (DEVPTR , HST (${ar}$), ISIZE, QUEUE) | ||
${indent}$ ELSE | ||
${indent}$ CALL ACC_MEMCPY_TO_DEVICE (DEVPTR , HST (${ar}$), ISIZE) | ||
${indent}$ ENDIF | ||
#else | ||
${indent}$ DEV (${ar}$) = HST (${ar}$) | ||
#endif | ||
${indent}$ ELSEIF (KDIR == ND2H) THEN | ||
#ifdef _OPENACC | ||
${indent}$ IF(PRESENT(QUEUE))THEN | ||
${indent}$ CALL ACC_MEMCPY_FROM_DEVICE_ASYNC (HST (${ar}$), DEVPTR, ISIZE, QUEUE) | ||
${indent}$ ELSE | ||
${indent}$ CALL ACC_MEMCPY_FROM_DEVICE (HST (${ar}$), DEVPTR, ISIZE) | ||
${indent}$ ENDIF | ||
#else | ||
${indent}$ HST (${ar}$) = DEV (${ar}$) | ||
#endif | ||
${indent}$ ENDIF | ||
#:for e in range (d, ft.rank) | ||
${' ' * (ft.rank - e - 1)}$ENDDO | ||
#:endfor | ||
END SUBROUTINE | ||
|
||
#:endfor | ||
|
||
#:endfor | ||
|
||
#:for ft in fieldTypeList | ||
#:set ftn = ft.name | ||
INTEGER (KIND=JPIM) FUNCTION ${ftn}$_GET_LAST_CONTIGUOUS_DIMENSION (PTR) RESULT (JDIM) | ||
${ft.type}$, POINTER :: PTR (${ft.shape}$) | ||
INTEGER*8 :: ISTRIDE (${ft.rank}$) | ||
INTEGER (KIND=JPIM) :: J, LB(${ft.rank}$) | ||
|
||
LB = LBOUND(PTR) | ||
ISTRIDE (1) = KIND (PTR) | ||
DO J = 2, ${ft.rank}$ | ||
ISTRIDE (J) = ISTRIDE (J-1) * SIZE (PTR, J-1) | ||
ENDDO | ||
|
||
JDIM = 0 | ||
#:for d in range (1, ft.rank+1) | ||
#:set ind0 = "" | ||
#:set ind1 = "" | ||
#:for i in range(1,ft.rank+1) | ||
#:set ind0 = ind0 + "LB({}), ".format(i) | ||
#:set ind1 = ind1 + "LB({}){}, ".format(i,"+1"*(i==d)) | ||
#:endfor | ||
#:set ind0 = ind0[:-2] | ||
#:set ind1 = ind1[:-2] | ||
IF (LOC (PTR (${ind1}$)) - LOC (PTR (${ind0}$)) /= ISTRIDE (${d}$)) THEN | ||
RETURN | ||
ENDIF | ||
|
||
JDIM = ${d}$ | ||
|
||
#:endfor | ||
END FUNCTION ${ftn}$_GET_LAST_CONTIGUOUS_DIMENSION | ||
#:endfor | ||
|
||
END MODULE FIELD_${RANK}$${SUFF}$_DATA_MODULE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
#! (C) Copyright 2022- ECMWF. | ||
#! (C) Copyright 2022- Meteo-France. | ||
#! | ||
#! 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. | ||
|
||
MODULE FIELD_${RANK}$${SUFF}$_FACTORY_MODULE | ||
|
||
#:set fieldTypeList = fieldType.getFieldTypeList (ranks=[RANK], kinds=['JP' + SUFF]) | ||
|
||
USE FIELD_MODULE | ||
USE FIELD_GANG_MODULE | ||
${fieldType.useParkind1 ()}$ | ||
|
||
IMPLICIT NONE | ||
|
||
PRIVATE | ||
|
||
INTERFACE FIELD_NEW | ||
#:for ft in fieldTypeList | ||
MODULE PROCEDURE ${ft.name}$_NEW_OWNER | ||
MODULE PROCEDURE ${ft.name}$_NEW_WRAPPER | ||
#:if ft.rank > 2 | ||
MODULE PROCEDURE ${ft.name}$_NEW_GANG_WRAPPER | ||
MODULE PROCEDURE ${ft.name}$_NEW_GANG_OWNER | ||
#:endif | ||
#:endfor | ||
END INTERFACE | ||
|
||
PUBLIC :: FIELD_NEW | ||
|
||
INTERFACE FIELD_DELETE | ||
#:for ft in fieldTypeList | ||
MODULE PROCEDURE ${ft.name}$_DELETE | ||
#:endfor | ||
END INTERFACE FIELD_DELETE | ||
|
||
PUBLIC :: FIELD_DELETE | ||
|
||
INTERFACE FIELD_RESIZE | ||
#:for ft in fieldTypeList | ||
MODULE PROCEDURE ${ft.name}$_RESIZE | ||
#:endfor | ||
END INTERFACE FIELD_RESIZE | ||
|
||
PUBLIC :: FIELD_RESIZE | ||
|
||
CONTAINS | ||
|
||
#:for ft in fieldTypeList | ||
SUBROUTINE ${ft.name}$_NEW_OWNER (FIELD_PTR, UBOUNDS, LBOUNDS, PERSISTENT, DELAYED, INIT_VALUE, PINNED, MAP_DEVPTR) | ||
|
||
CLASS(${ft.name}$), POINTER :: FIELD_PTR | ||
TYPE(${ft.name}$_OWNER), POINTER :: FIELD_OWNER | ||
INTEGER(KIND=JPIM), INTENT(IN) :: UBOUNDS (${ft.rank}$) | ||
INTEGER(KIND=JPIM), OPTIONAL, INTENT(IN) :: LBOUNDS (${ft.rank}$) | ||
LOGICAL, OPTIONAL, INTENT(IN) :: PERSISTENT | ||
LOGICAL, OPTIONAL, INTENT(IN) :: DELAYED | ||
${ft.type}$, OPTIONAL, INTENT(IN) :: INIT_VALUE | ||
LOGICAL, OPTIONAL, INTENT(IN) :: PINNED | ||
LOGICAL, OPTIONAL, INTENT(IN) :: MAP_DEVPTR | ||
|
||
ALLOCATE (FIELD_OWNER) | ||
|
||
CALL FIELD_OWNER%INIT (LBOUNDS=LBOUNDS, UBOUNDS=UBOUNDS, PERSISTENT=PERSISTENT, DELAYED=DELAYED, & | ||
& INIT_VALUE=INIT_VALUE, PINNED=PINNED, MAP_DEVPTR=MAP_DEVPTR) | ||
|
||
FIELD_PTR => FIELD_OWNER | ||
|
||
END SUBROUTINE | ||
|
||
SUBROUTINE ${ft.name}$_NEW_WRAPPER (FIELD_PTR, LBOUNDS, PERSISTENT, DATA, MAP_DEVPTR) | ||
|
||
CLASS(${ft.name}$), POINTER :: FIELD_PTR | ||
${ft.type}$, TARGET, INTENT (IN) :: DATA (${ft.shape}$) | ||
TYPE(${ft.name}$_WRAPPER), POINTER :: FIELD_WRAPPER | ||
INTEGER(KIND=JPIM), OPTIONAL, INTENT(IN) :: LBOUNDS (${ft.rank}$) | ||
LOGICAL, OPTIONAL, INTENT(IN) :: PERSISTENT | ||
LOGICAL, OPTIONAL, INTENT(IN) :: MAP_DEVPTR | ||
|
||
ALLOCATE (FIELD_WRAPPER) | ||
|
||
CALL FIELD_WRAPPER%INIT (DATA, LBOUNDS=LBOUNDS, PERSISTENT=PERSISTENT, MAP_DEVPTR=MAP_DEVPTR) | ||
|
||
FIELD_PTR => FIELD_WRAPPER | ||
|
||
END SUBROUTINE | ||
|
||
#:if ft.rank > 2 | ||
SUBROUTINE ${ft.name}$_NEW_GANG_WRAPPER (FIELD_PTR, CHILDREN, LBOUNDS, PERSISTENT, DATA) | ||
|
||
#:set fieldTypeList1 = fieldType.getFieldTypeList (ranks=[ft.rank-1], kinds=[ft.kind]) | ||
#:set ft1 = fieldTypeList1[0] | ||
|
||
CLASS(${ft.name}$), POINTER :: FIELD_PTR | ||
TYPE(${ft1.name}$_PTR), ALLOCATABLE :: CHILDREN (:) | ||
${ft.type}$, TARGET, INTENT (IN) :: DATA (${ft.shape}$) | ||
INTEGER(KIND=JPIM), OPTIONAL, INTENT(IN) :: LBOUNDS (${ft.rank}$) | ||
LOGICAL, OPTIONAL, INTENT(IN) :: PERSISTENT | ||
|
||
TYPE(${ft.name}$_GANG_WRAPPER), POINTER :: FIELD_GANG | ||
INTEGER (KIND=JPIM) :: JFLD | ||
|
||
ALLOCATE (FIELD_GANG) | ||
|
||
CALL FIELD_GANG%INIT (DATA, LBOUNDS=LBOUNDS, PERSISTENT=PERSISTENT) | ||
|
||
ALLOCATE (CHILDREN (SIZE (FIELD_GANG%CHILDREN))) | ||
|
||
FIELD_PTR => FIELD_GANG | ||
|
||
DO JFLD = 1, SIZE (CHILDREN) | ||
CHILDREN(JFLD)%PTR => FIELD_GANG%CHILDREN(JFLD)%PTR | ||
FIELD_GANG%CHILDREN (JFLD)%PTR%PARENT => FIELD_PTR | ||
ENDDO | ||
|
||
END SUBROUTINE | ||
|
||
SUBROUTINE ${ft.name}$_NEW_GANG_OWNER (FIELD_PTR, CHILDREN, UBOUNDS, LBOUNDS, PERSISTENT, DELAYED, INIT_VALUE) | ||
|
||
#:set fieldTypeList1 = fieldType.getFieldTypeList (ranks=[ft.rank-1], kinds=[ft.kind]) | ||
#:set ft1 = fieldTypeList1[0] | ||
|
||
CLASS(${ft.name}$), POINTER :: FIELD_PTR | ||
TYPE(${ft1.name}$_PTR), ALLOCATABLE :: CHILDREN (:) | ||
INTEGER(KIND=JPIM), INTENT(IN) :: UBOUNDS (${ft.rank}$) | ||
INTEGER(KIND=JPIM), OPTIONAL, INTENT(IN) :: LBOUNDS (${ft.rank}$) | ||
LOGICAL, OPTIONAL, INTENT(IN) :: PERSISTENT | ||
LOGICAL, OPTIONAL, INTENT(IN) :: DELAYED | ||
${ft.type}$, OPTIONAL, INTENT(IN) :: INIT_VALUE | ||
|
||
TYPE(${ft.name}$_GANG_OWNER), POINTER :: FIELD_GANG | ||
INTEGER (KIND=JPIM) :: JFLD | ||
|
||
ALLOCATE (FIELD_GANG) | ||
|
||
CALL FIELD_GANG%INIT (LBOUNDS=LBOUNDS, UBOUNDS=UBOUNDS, PERSISTENT=PERSISTENT, DELAYED=DELAYED, INIT_VALUE=INIT_VALUE) | ||
|
||
ALLOCATE (CHILDREN (SIZE (FIELD_GANG%CHILDREN))) | ||
|
||
FIELD_PTR => FIELD_GANG | ||
|
||
DO JFLD = 1, SIZE (CHILDREN) | ||
CHILDREN(JFLD)%PTR => FIELD_GANG%CHILDREN(JFLD)%PTR | ||
FIELD_GANG%CHILDREN (JFLD)%PTR%PARENT => FIELD_PTR | ||
ENDDO | ||
|
||
END SUBROUTINE | ||
|
||
#:endif | ||
|
||
SUBROUTINE ${ft.name}$_DELETE (FIELD_PTR) | ||
|
||
CLASS(${ft.name}$), POINTER :: FIELD_PTR | ||
|
||
CALL FIELD_PTR%FINAL () | ||
DEALLOCATE (FIELD_PTR) | ||
NULLIFY (FIELD_PTR) | ||
|
||
END SUBROUTINE | ||
|
||
SUBROUTINE ${ft.name}$_RESIZE (FIELD_PTR, UBOUNDS, LBOUNDS, PERSISTENT) | ||
|
||
CLASS(${ft.name}$), POINTER :: FIELD_PTR | ||
INTEGER(KIND=JPIM), INTENT(IN) :: UBOUNDS (${ft.rank}$) | ||
INTEGER(KIND=JPIM), OPTIONAL, INTENT(IN) :: LBOUNDS (${ft.rank}$) | ||
LOGICAL, OPTIONAL, INTENT(IN) :: PERSISTENT | ||
|
||
IF (.NOT. ASSOCIATED(FIELD_PTR)) THEN | ||
CALL FIELD_NEW (FIELD_PTR, UBOUNDS, LBOUNDS, PERSISTENT) | ||
ELSE | ||
CALL FIELD_PTR%RESIZE (LBOUNDS=LBOUNDS, UBOUNDS=UBOUNDS, PERSISTENT=PERSISTENT) | ||
END IF | ||
END SUBROUTINE ${ft.name}$_RESIZE | ||
|
||
#:endfor | ||
|
||
END MODULE |
Oops, something went wrong.