Skip to content

Commit

Permalink
Merge branch 'feature/array_slicing_shared' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
theurich committed Sep 18, 2023
2 parents 880d78c + aab5278 commit b9e09a2
Show file tree
Hide file tree
Showing 14 changed files with 2,953 additions and 533 deletions.
11 changes: 6 additions & 5 deletions src/Infrastructure/Array/include/ESMCI_Array.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ namespace ESMCI {
template<typename SIT, typename DIT> class SparseMatrix;

// class definitions

//TODO: Figure out how to have code use correct SeqIndex structure automatic.
//TODO: For now just hard-code the use of one or the other via CPP definition.
#define SeqIndexTensor SeqIndex
Expand Down Expand Up @@ -173,7 +173,7 @@ namespace ESMCI {
// larrayList and larrayBaseAddrList hold the PET-local DEs in the first
// localDe many entries. Then, up to vasLocalDeCount are the DEs that
// are in the same VAS, and up to ssiLocalDeCount are the DEs that are
// in the same SSI.
// in the same SSI.
// Without VAS DE sharing, vasLocalDeCount==localDeCount.
// Without SSI DE sharing, ssiLocalDeCount==vasLocalDeCount.
LocalArray **larrayList; // [ssiLocalDeCount] localDeCount first
Expand Down Expand Up @@ -324,12 +324,12 @@ namespace ESMCI {
private:
Array(ESMC_TypeKind_Flag typekind, int rank, LocalArray **larrayList,
VM::memhandle *mh, int vasLocalDeCount, int ssiLocalDeCount,
int *localDeToDeMap, DistGrid *distgrid, bool distgridCreator,
int *localDeToDeMap, DistGrid *distgrid, bool distgridCreator,
int *exclusiveLBound, int *exclusiveUBound, int *computationalLBound,
int *computationalUBound, int *totalLBound, int *totalUBound,
int tensorCount, int tensorElementCount, int *undistLBoundArray,
int *undistUBoundArray, int *distgridToArrayMapArray,
int *arrayToDistGridMapArray, int *distgridToPackedArrayMapArray,
int *arrayToDistGridMapArray, int *distgridToPackedArrayMapArray,
ESMC_IndexFlag indexflagArg, int *rc,
VM *vm=NULL); // allow specific VM instead default
public:
Expand Down Expand Up @@ -363,7 +363,8 @@ namespace ESMCI {
InterArray<int> *undistLBoundArg, InterArray<int> *undistUBoundArg,
int *rc, VM *vm=NULL);
static Array *create(Array *array, DataCopyFlag copyflag,
DELayout *delayout=NULL, int rmLeadingTensors=0, int *rc=NULL);
DELayout *delayout=NULL, InterArray<int> *trailingTensorSlice=NULL,
int rmLeadingTensors=0, int *rc=NULL);
static Array *create(Array *array, bool rmTensorFlag, int *rc=NULL);
static int destroy(Array **array, bool noGarbage=false);
// data copy()
Expand Down
10 changes: 6 additions & 4 deletions src/Infrastructure/Array/interface/ESMCI_Array_F.C
Original file line number Diff line number Diff line change
Expand Up @@ -157,19 +157,21 @@ extern "C" {
ESMC_NOT_PRESENT_FILTER(rc))) return;
}

void FTN_X(c_esmc_arraycreatecopy)(ESMCI::Array **ptr,
void FTN_X(c_esmc_arraycreatefromarray)(ESMCI::Array **ptr,
ESMCI::Array **arrayOut, ESMCI::DataCopyFlag *copyflag,
ESMCI::DELayout **delayout, int *rc){
ESMCI::DELayout **delayout, ESMCI::InterArray<int> *trailingUndistSlice,
int *rc){
#undef ESMC_METHOD
#define ESMC_METHOD "c_esmc_arraycreatecopy()"
#define ESMC_METHOD "c_esmc_arraycreatefromarray()"
// Initialize return code; assume routine not implemented
if (rc!=NULL) *rc = ESMC_RC_NOT_IMPL;
int localrc = ESMC_RC_NOT_IMPL;
ESMCI::DELayout *delayout_opt = NULL;
if (ESMC_NOT_PRESENT_FILTER(delayout) != ESMC_NULL_POINTER)
delayout_opt = *delayout;
// call into C++
*arrayOut = ESMCI::Array::create(*ptr, *copyflag, delayout_opt, 0, &localrc);
*arrayOut = ESMCI::Array::create(*ptr, *copyflag, delayout_opt,
trailingUndistSlice, 0, &localrc);
if (ESMC_LogDefault.MsgFoundError(localrc, ESMCI_ERR_PASSTHRU, ESMC_CONTEXT,
ESMC_NOT_PRESENT_FILTER(rc))) return;
}
Expand Down
50 changes: 35 additions & 15 deletions src/Infrastructure/Array/interface/ESMF_ArrayCreate.cppF90
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ module ESMF_ArrayCreateMod
module procedure ESMF_ArrayCreateAllocateAS
module procedure ESMF_ArrayCreateAllocateASArb
module procedure ESMF_ArrayCreateAllocateASArbI8
module procedure ESMF_ArrayCreateCopy
module procedure ESMF_ArrayCreateFromArray

! !DESCRIPTION:
! This interface provides a single entry point for the various
Expand Down Expand Up @@ -3862,22 +3862,24 @@ TypeKindRankDeclarationMacro(ArrayCreateAsmdSpArbI8)

! -------------------------- ESMF-public method -------------------------------
^undef ESMF_METHOD
^define ESMF_METHOD "ESMF_ArrayCreateCopy()"
^define ESMF_METHOD "ESMF_ArrayCreateFromArray()"
!BOP
! !IROUTINE: ESMF_ArrayCreate - Create Array object as copy of existing Array object
! !IROUTINE: ESMF_ArrayCreate - Create Array object from an existing Array object

! !INTERFACE:
! Private name; call using ESMF_ArrayCreate()
function ESMF_ArrayCreateCopy(array, keywordEnforcer, datacopyflag, delayout, rc)
function ESMF_ArrayCreateFromArray(array, keywordEnforcer, datacopyflag, delayout, &
trailingUndistSlice, rc)
!
! !RETURN VALUE:
type(ESMF_Array) :: ESMF_ArrayCreateCopy
type(ESMF_Array) :: ESMF_ArrayCreateFromArray
!
! !ARGUMENTS:
type(ESMF_Array), intent(in) :: array
type(ESMF_KeywordEnforcer), optional:: keywordEnforcer ! must use keywords below
type(ESMF_DataCopy_Flag), intent(in), optional :: datacopyflag
type(ESMF_DELayout), intent(in), optional :: delayout
integer, intent(in), optional :: trailingUndistSlice(:)
integer, intent(out), optional :: rc
!
! !STATUS:
Expand All @@ -3886,14 +3888,16 @@ TypeKindRankDeclarationMacro(ArrayCreateAsmdSpArbI8)
! \item\apiStatusModifiedSinceVersion{5.2.0r}
! \begin{description}
! \item[8.1.0] Added argument {\tt datacopyflag} to select between different
! copy options.\newline
! data copy options.\newline
! Added argument {\tt delayout} to create Array with different localDe -> DE
! mapping. This is identical to a change in DE -> PET mapping.
! \item[8.6.0] Added argument {\tt trailingUndistSlice} to allow slicing of
! arrays created by reference.
! \end{description}
! \end{itemize}
!
! !DESCRIPTION:
! Create an {\tt ESMF\_Array} object as the copy of an existing Array.
! Create an {\tt ESMF\_Array} object from an existing Array.
!
! The return value is the newly created {\tt ESMF\_Array} object.
!
Expand All @@ -3909,6 +3913,10 @@ TypeKindRankDeclarationMacro(ArrayCreateAsmdSpArbI8)
! \item[{[delayout]}]
! If present, override the DELayout of the incoming {\tt distgrid}.
! By default use the DELayout defined in {\tt distgrid}.
! \item[{[trailingUndistSlice]}]
! If present, the returned Array references the data of the array slice
! as defined by the specified tuple, applied to the right most
! trailing undistributed dimensions.
! \item[{[rc]}]
! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
! \end{description}
Expand All @@ -3917,38 +3925,50 @@ TypeKindRankDeclarationMacro(ArrayCreateAsmdSpArbI8)
!------------------------------------------------------------------------------
integer :: localrc ! local return code
type(ESMF_Array) :: arrayOut ! opaque pointer to new C++ Array
type(ESMF_DataCopy_Flag):: datacopyflag_opt ! helper variable
type(ESMF_DataCopy_Flag):: datacopyflag_opt ! helper variable
type(ESMF_InterArray) :: trailingUndistSliceArg ! helper variable

! Initialize return code; assume failure until success is certain
localrc = ESMF_RC_NOT_IMPL
if (present(rc)) rc = ESMF_RC_NOT_IMPL

! Mark this Array object as invalid
arrayOut%this = ESMF_NULL_POINTER
ESMF_ArrayCreateCopy = arrayOut
ESMF_ArrayCreateFromArray = arrayOut

ESMF_INIT_CHECK_DEEP_SHORT(ESMF_ArrayGetInit, array, rc)

! Set copy/ref behavior
! Set data copy/ref behavior
datacopyflag_opt = ESMF_DATACOPY_VALUE ! default
if (present(datacopyflag)) datacopyflag_opt = datacopyflag

! Deal with (optional) array arguments
trailingUndistSliceArg = ESMF_InterArrayCreate( &
farray1D=trailingUndistSlice, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return

! Call into the C++ interface
call c_ESMC_ArrayCreateCopy(array, arrayOut, datacopyflag_opt, delayout, &
localrc)
call c_ESMC_ArrayCreateFromArray(array, arrayOut, datacopyflag_opt, &
delayout, trailingUndistSliceArg, localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return

! Garbage collection
call ESMF_InterArrayDestroy(trailingUndistSliceArg, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return

! Set return value
ESMF_ArrayCreateCopy = arrayOut
ESMF_ArrayCreateFromArray = arrayOut

! Set init code
ESMF_INIT_SET_CREATED(ESMF_ArrayCreateCopy)
ESMF_INIT_SET_CREATED(ESMF_ArrayCreateFromArray)

! Return successfully
if (present(rc)) rc = ESMF_SUCCESS

end function ESMF_ArrayCreateCopy
end function ESMF_ArrayCreateFromArray
!------------------------------------------------------------------------------


Expand Down
Loading

0 comments on commit b9e09a2

Please sign in to comment.