diff --git a/src/Infrastructure/Array/examples/ESMF_ArrayEx.F90 b/src/Infrastructure/Array/examples/ESMF_ArrayEx.F90 index d32b6e67ac..e848ece4b7 100644 --- a/src/Infrastructure/Array/examples/ESMF_ArrayEx.F90 +++ b/src/Infrastructure/Array/examples/ESMF_ArrayEx.F90 @@ -1308,6 +1308,7 @@ program ESMF_ArrayEx !BOE ! \subsubsection{Arrays with replicated dimensions} +! \label{sec:array:usage:replicated_dims} ! ! Thus far most examples demonstrated cases where the DistGrid {\tt dimCount} ! was equal to the Array {\tt rank}. The previous section introduced the diff --git a/src/Infrastructure/Array/include/ESMCI_Array.h b/src/Infrastructure/Array/include/ESMCI_Array.h index 0c9b1b0a1c..1a131adfb1 100644 --- a/src/Infrastructure/Array/include/ESMCI_Array.h +++ b/src/Infrastructure/Array/include/ESMCI_Array.h @@ -191,6 +191,8 @@ namespace ESMCI { int *totalUBound; // [redDimCount*ssiLocalDeCount] int tensorCount; // number of tensor dimensions int tensorElementCount; // number of tensor elements per element + int replicatedDimCount; // number of replicated dimensions + // (i.e., dimensions where distgridToArrayMap[i] == 0) int *undistLBound; // [tensorCount] int *undistUBound; // [tensorCount] int *distgridToArrayMap; // [dimCount] - entries are basis 1 @@ -262,6 +264,7 @@ namespace ESMCI { totalLBound = NULL; totalUBound = NULL; tensorCount = 0; + replicatedDimCount = 0; undistLBound = NULL; undistUBound = NULL; distgridToArrayMap = NULL; @@ -300,6 +303,7 @@ namespace ESMCI { totalLBound = NULL; totalUBound = NULL; tensorCount = 0; + replicatedDimCount = 0; undistLBound = NULL; undistUBound = NULL; distgridToArrayMap = NULL; @@ -327,8 +331,8 @@ namespace ESMCI { 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 tensorCount, int tensorElementCount, int replicatedDimCount, + int *undistLBoundArray, int *undistUBoundArray, int *distgridToArrayMapArray, int *arrayToDistGridMapArray, int *distgridToPackedArrayMapArray, ESMC_IndexFlag indexflagArg, int *rc, VM *vm=NULL); // allow specific VM instead default @@ -385,6 +389,7 @@ namespace ESMCI { const int *getTotalLBound() const {return totalLBound;} const int *getTotalUBound() const {return totalUBound;} int getTensorCount() const {return tensorCount;} + int getReplicatedDimCount() const {return replicatedDimCount;} const int *getUndistLBound() const {return undistLBound;} const int *getUndistUBound() const {return undistUBound;} const int *getExclusiveElementCountPDe()const diff --git a/src/Infrastructure/Array/interface/ESMCI_Array_F.C b/src/Infrastructure/Array/interface/ESMCI_Array_F.C index c249ec0411..c35cb34cc8 100644 --- a/src/Infrastructure/Array/interface/ESMCI_Array_F.C +++ b/src/Infrastructure/Array/interface/ESMCI_Array_F.C @@ -193,7 +193,8 @@ extern "C" { } void FTN_X(c_esmc_arrayget)(ESMCI::Array **ptr, ESMC_TypeKind_Flag *typekind, - int *rank, int *ssiLocalDeCount, ESMCI::LocalArray **opt_localArrayList, + int *rank, int *replicatedDimCount, + int *ssiLocalDeCount, ESMCI::LocalArray **opt_localArrayList, int *len_localArrayList, ESMCI::InterArray *localDeToDeMap, ESMCI::DistGrid **distgrid, ESMCI::DELayout **delayout, ESMC_IndexFlag *indexflag, @@ -227,6 +228,8 @@ extern "C" { *typekind = (*ptr)->getTypekind(); if (ESMC_NOT_PRESENT_FILTER(rank) != ESMC_NULL_POINTER) *rank = (*ptr)->getRank(); + if (ESMC_NOT_PRESENT_FILTER(replicatedDimCount) != ESMC_NULL_POINTER) + *replicatedDimCount = (*ptr)->getReplicatedDimCount(); if (ESMC_NOT_PRESENT_FILTER(ssiLocalDeCount) != ESMC_NULL_POINTER) *ssiLocalDeCount = (*ptr)->getSsiLocalDeCount(); if (ESMC_NOT_PRESENT_FILTER(indexflag) != ESMC_NULL_POINTER) diff --git a/src/Infrastructure/Array/interface/ESMF_ArrayGet.cppF90 b/src/Infrastructure/Array/interface/ESMF_ArrayGet.cppF90 index 3cb91bee07..10495990cc 100644 --- a/src/Infrastructure/Array/interface/ESMF_ArrayGet.cppF90 +++ b/src/Infrastructure/Array/interface/ESMF_ArrayGet.cppF90 @@ -128,12 +128,13 @@ contains ! !INTERFACE: ! Private name; call using ESMF_ArrayGet() - subroutine ESMF_ArrayGetDefault(array, keywordEnforcer, arrayspec, typekind, & +subroutine ESMF_ArrayGetDefault(array, keywordEnforcer, arrayspec, typekind, & rank, localarrayList, indexflag, distgridToArrayMap, & distgridToPackedArrayMap, arrayToDistGridMap, undistLBound, & undistUBound, exclusiveLBound, exclusiveUBound, computationalLBound, & computationalUBound, totalLBound, totalUBound, computationalLWidth, & - computationalUWidth, totalLWidth, totalUWidth, distgrid, dimCount, & + computationalUWidth, totalLWidth, totalUWidth, distgrid, & + dimCount, replicatedDimCount, & tileCount, minIndexPTile, maxIndexPTile, deToTileMap, indexCountPDe, & delayout, deCount, localDeCount, ssiLocalDeCount, localDeToDeMap, & localDeList, & ! DEPRECATED ARGUMENT @@ -164,6 +165,7 @@ type(ESMF_KeywordEnforcer), optional:: keywordEnforcer ! must use keywords below integer, target, intent(out), optional :: totalUWidth(:,:) type(ESMF_DistGrid), intent(out), optional :: distgrid integer, intent(out), optional :: dimCount + integer, intent(out), optional :: replicatedDimCount integer, intent(out), optional :: tileCount integer, intent(out), optional :: minIndexPTile(:,:) integer, intent(out), optional :: maxIndexPTile(:,:) @@ -314,6 +316,10 @@ type(ESMF_KeywordEnforcer), optional:: keywordEnforcer ! must use keywords below ! Upon return this holds the associated {\tt ESMF\_DistGrid} object. ! \item[{[dimCount]}] ! Number of dimensions (rank) of {\tt distgrid}. +! \item[{[replicatedDimCount]}] +! Number of replicated dimensions in the Array. (See +! Section~\ref{sec:array:usage:replicated_dims} for an explanation of replicated +! dimensions.) ! \item[{[tileCount]}] ! Number of tiles in {\tt distgrid}. ! \item[{[minIndexPTile]}] @@ -462,7 +468,8 @@ type(ESMF_KeywordEnforcer), optional:: keywordEnforcer ! must use keywords below ESMF_CONTEXT, rcToReturn=rc)) return ! Call into the C++ interface, which will sort out optional arguments - call c_ESMC_ArrayGet(array, opt_typekind, opt_rank, opt_ssiLocalDeCount, & + call c_ESMC_ArrayGet(array, opt_typekind, opt_rank, & + replicatedDimCount, opt_ssiLocalDeCount, & opt_localarrayPtrList, len_localarrayPtrList, localDeToDeMapArg, & opt_distgrid, opt_delayout, indexflag, & distgridToArrayMapArg, distgridToPackedArrayMapArg, & diff --git a/src/Infrastructure/Array/src/ESMCI_Array.C b/src/Infrastructure/Array/src/ESMCI_Array.C index 25e5bd141a..af6a7910b0 100644 --- a/src/Infrastructure/Array/src/ESMCI_Array.C +++ b/src/Infrastructure/Array/src/ESMCI_Array.C @@ -160,6 +160,7 @@ Array::Array( int *totalUBoundArg, // (in) int tensorCountArg, // (in) int tensorElementCountArg, // (in) + int replicatedDimCountArg, // (in) int *undistLBoundArray, // (in) int *undistUBoundArray, // (in) int *distgridToArrayMapArray, // (in) @@ -259,6 +260,8 @@ Array::Array( memcpy(undistLBound, undistLBoundArray, tensorCountArg * sizeof(int)); memcpy(undistUBound, undistUBoundArray, tensorCountArg * sizeof(int)); } + // replicated dimension count + replicatedDimCount = replicatedDimCountArg; // distgridToArrayMap, arrayToDistGridMap and distgridToPackedArrayMap int dimCount = distgrid->getDimCount(); distgridToArrayMap = new int[dimCount]; @@ -511,6 +514,19 @@ int Array::constructContiguousFlag(int redDimCount){ } //----------------------------------------------------------------------------- +// Helper for create +//----------------------------------------------------------------------------- +#undef ESMC_METHOD +#define ESMC_METHOD "ESMCI::calcReplicatedDimCount()" + int calcReplicatedDimCount(int dimCount, int *distgridToArrayMap) { + int replicatorCount = 0; + for (int i=0; i redDimCount int redDimCount = dimCount - replicatorCount; // determine tensorCount @@ -1240,7 +1254,7 @@ Array *Array::create( ssiLocalDeCountArg, NULL, distgrid, false, exclusiveLBound, exclusiveUBound, computationalLBound, computationalUBound, totalLBound, totalUBound, tensorCount, - tensorElementCount, undistLBoundArray, undistUBoundArray, + tensorElementCount, replicatorCount, undistLBoundArray, undistUBoundArray, distgridToArrayMapArray, arrayToDistGridMapArray, distgridToPackedArrayMap, indexflag, &localrc); if (ESMC_LogDefault.MsgFoundError(localrc, ESMCI_ERR_PASSTHRU, ESMC_CONTEXT, @@ -1400,9 +1414,7 @@ Array *Array::create( } } // determine replicatorCount - int replicatorCount = 0; // initialize - for (int i=0; i redDimCount int redDimCount = dimCount - replicatorCount; // determine tensorCount @@ -2050,7 +2062,7 @@ Array *Array::create( ssiLocalDeCountArg, localDeToDeMapArg, distgrid, false, exclusiveLBound, exclusiveUBound, computationalLBound, computationalUBound, totalLBound, totalUBound, tensorCount, - tensorElementCount, undistLBoundArray, undistUBoundArray, + tensorElementCount, replicatorCount, undistLBoundArray, undistUBoundArray, distgridToArrayMapArray, arrayToDistGridMapArray, distgridToPackedArrayMap, indexflag, &localrc, vm); if (ESMC_LogDefault.MsgFoundError(localrc, ESMCI_ERR_PASSTHRU, @@ -2155,6 +2167,7 @@ Array *Array::create( int tensorCount = arrayOut->tensorCount = arrayIn->tensorCount - rmLeadingTensors - rmTrailingTensors; + arrayOut->replicatedDimCount = arrayIn->replicatedDimCount; arrayOut->vasLocalDeCount = arrayIn->vasLocalDeCount; if (copyflag == DATACOPY_REFERENCE){ // sharing reference means also sharing memhandle @@ -2470,6 +2483,7 @@ Array *Array::create( arrayOut->tensorElementCount = 1; else arrayOut->tensorElementCount = arrayIn->tensorElementCount; + arrayOut->replicatedDimCount = arrayIn->replicatedDimCount; arrayOut->distgrid = arrayIn->distgrid; // copy reference arrayOut->distgridCreator = false; // not a locally created object arrayOut->delayout = arrayIn->delayout; // copy reference @@ -4447,10 +4461,11 @@ int Array::serialize( for (int i=0; igetDimCount(); i++) *ip++ = distgridToPackedArrayMap[i]; *ip++ = tensorElementCount; + *ip++ = replicatedDimCount; for (int i=0; igetDeCount(); i++) *ip++ = exclusiveElementCountPDe[i]; } else - ip += 2 + 2*tensorCount + 2*distgrid->getDimCount () + + ip += 3 + 2*tensorCount + 2*distgrid->getDimCount () + rank + delayout->getDeCount (); // fix offset @@ -4542,6 +4557,7 @@ int Array::deserialize( for (int i=0; igetDimCount(); i++) distgridToPackedArrayMap[i] = *ip++; tensorElementCount = *ip++; + replicatedDimCount = *ip++; exclusiveElementCountPDe = new int[delayout->getDeCount()]; for (int i=0; igetDeCount(); i++) exclusiveElementCountPDe[i] = *ip++; diff --git a/src/Infrastructure/Array/tests/ESMF_ArrayCreateGetUTest.F90 b/src/Infrastructure/Array/tests/ESMF_ArrayCreateGetUTest.F90 index a882461219..78fec45329 100644 --- a/src/Infrastructure/Array/tests/ESMF_ArrayCreateGetUTest.F90 +++ b/src/Infrastructure/Array/tests/ESMF_ArrayCreateGetUTest.F90 @@ -54,6 +54,7 @@ program ESMF_ArrayCreateGetUTest !LOCAL VARIABLES: type(ESMF_VM):: vm integer:: i,j,k,l, next, rank + integer:: replicatedDimCount integer:: petCount, localPet, deCount, de, localDeCount, lde, ssiLocalDeCount integer, allocatable :: regDecomp(:) type(ESMF_ArraySpec) :: arrayspec, arrayspec2 @@ -316,6 +317,19 @@ program ESMF_ArrayCreateGetUTest write(failMsg, *) "Incorrect name" call ESMF_Test((trim(arrayName)=="MyArray with ArraySpec"), name, failMsg, result, ESMF_SRCLINE) + !------------------------------------------------------------------------ + !NEX_UTest_Multi_Proc_Only + write(name, *) "ArrayGet replicatedDimCount Test" + write(failMsg, *) "Did not return ESMF_SUCCESS" + call ESMF_ArrayGet(array, replicatedDimCount=replicatedDimCount, rc=rc) + call ESMF_Test((rc.eq.ESMF_SUCCESS), name, failMsg, result, ESMF_SRCLINE) + + !------------------------------------------------------------------------ + !NEX_UTest_Multi_Proc_Only + write(name, *) "Verify replicatedDimCount returned from Array with 0 replicated dims" + write(failMsg, *) "Incorrect replicatedDimCount" + call ESMF_Test(replicatedDimCount==0, name, failMsg, result, ESMF_SRCLINE) + !------------------------------------------------------------------------ !NEX_UTest_Multi_Proc_Only write(name, *) "ArrayGet Fortran array pointer, 2D ESMF_TYPEKIND_R8 Test" @@ -2541,6 +2555,43 @@ program ESMF_ArrayCreateGetUTest call ESMF_ArrayDestroy(array, rc=rc) call ESMF_Test((rc.eq.ESMF_SUCCESS), name, failMsg, result, ESMF_SRCLINE) + !------------------------------------------------------------------------ + !NEX_UTest_Multi_Proc_Only + write(name, *) "ArrayCreate Allocate 2D with 4D DistGrid Test" + write(failMsg, *) "Did not return ESMF_SUCCESS" + array = ESMF_ArrayCreate(arrayspec=arrayspec, distgrid=distgrid, & + ! Dimensions 1 and 3 are replicated dimensions + distgridToArrayMap = [0,1,0,2], & + indexflag=ESMF_INDEX_GLOBAL, name="2D Array with 4D DistGrid", rc=rc) + call ESMF_Test((rc.eq.ESMF_SUCCESS), name, failMsg, result, ESMF_SRCLINE) + + !------------------------------------------------------------------------ + !NEX_UTest_Multi_Proc_Only + write(name, *) "ArrayGet replicatedDimCount Test" + write(failMsg, *) "Did not return ESMF_SUCCESS" + call ESMF_ArrayGet(array, replicatedDimCount=replicatedDimCount, rc=rc) + call ESMF_Test((rc.eq.ESMF_SUCCESS), name, failMsg, result, ESMF_SRCLINE) + + !------------------------------------------------------------------------ + !NEX_UTest_Multi_Proc_Only + write(name, *) "Verify replicatedDimCount returned from Array with 2 replicated dims" + write(failMsg, *) "Incorrect replicatedDimCount" + call ESMF_Test(replicatedDimCount==2, name, failMsg, result, ESMF_SRCLINE) + + !------------------------------------------------------------------------ + !NEX_UTest_Multi_Proc_Only + write(name, *) "ArrayGet Fortran array pointer from Array with 2 replicated dims Test" + write(failMsg, *) "Did not return ESMF_SUCCESS" + call ESMF_ArrayGet(array, farrayPtr=farrayPtr2D, rc=rc) + call ESMF_Test((rc.eq.ESMF_SUCCESS), name, failMsg, result, ESMF_SRCLINE) + + !------------------------------------------------------------------------ + !NEX_UTest_Multi_Proc_Only + write(name, *) "ArrayDestroy Test" + write(failMsg, *) "Did not return ESMF_SUCCESS" + call ESMF_ArrayDestroy(array, rc=rc) + call ESMF_Test((rc.eq.ESMF_SUCCESS), name, failMsg, result, ESMF_SRCLINE) + !------------------------------------------------------------------------ ! cleanup call ESMF_DistGridDestroy(distgrid, rc=rc) diff --git a/src/Infrastructure/Array/tests/ESMF_ArrayIOUTest.F90 b/src/Infrastructure/Array/tests/ESMF_ArrayIOUTest.F90 index 5427cf7edc..85cf9a7bc1 100644 --- a/src/Infrastructure/Array/tests/ESMF_ArrayIOUTest.F90 +++ b/src/Infrastructure/Array/tests/ESMF_ArrayIOUTest.F90 @@ -1309,7 +1309,7 @@ program ESMF_ArrayIOUTest call ESMF_Test((rc == ESMF_SUCCESS), name, failMsg, result, ESMF_SRCLINE) !------------------------------------------------------------------------ -! Array with repliocated dimension(s) decomp along dim 1 +! Array with replicated dimension(s) decomp along dim 1 !------------------------------------------------------------------------ !------------------------------------------------------------------------ @@ -1332,14 +1332,10 @@ program ESMF_ArrayIOUTest !------------------------------------------------------------------------ !NEX_UTest_Multi_Proc_Only write(name, *) "Array with replicated dimension 1 get and fill Test" - write(failMsg, *) "Did not return ESMF_SUCCESS" - ! access the pointer to the allocated memory on each DE - call ESMF_ArrayGet(array_repli1, farrayPtr=arrayPtrR8D1, rc=rc) + write(failMsg, *) "Did not return ESMF_SUCCESS" + call fillArray1d(array_repli1, arrayPtrR8D1, rc) call ESMF_Test((rc == ESMF_SUCCESS), name, failMsg, result, ESMF_SRCLINE) - ! initialize data - arrayPtrR8D1 = 12345._ESMF_KIND_R8*localPet - !------------------------------------------------------------------------ !NEX_UTest_Multi_Proc_Only ! ! Given an ESMF array, write the netCDF file. @@ -1392,7 +1388,7 @@ program ESMF_ArrayIOUTest write(name, *) "Array with replicated dimension 1 comparison Test" write(failMsg, *) "Did not return ESMF_SUCCESS" #if (defined ESMF_PIO && (defined ESMF_NETCDF || defined ESMF_PNETCDF)) - passfail = all (arrayPtrR8D1_r == 12345.0_ESMF_KIND_R8*localPet) + passfail = all (arrayPtrR8D1_r == arrayPtrR8D1) #else passfail = .true. #endif @@ -1424,13 +1420,9 @@ program ESMF_ArrayIOUTest !------------------------------------------------------------------------ !NEX_UTest_Multi_Proc_Only write(name, *) "Array with replicated dimension 2 get and fill Test" - write(failMsg, *) "Did not return ESMF_SUCCESS" - ! access the pointer to the allocated memory on each DE - call ESMF_ArrayGet(array_repli2, farrayPtr=arrayPtrR8D1, rc=rc) + write(failMsg, *) "Did not return ESMF_SUCCESS" + call fillArray1d(array_repli2, arrayPtrR8D1, rc) call ESMF_Test((rc == ESMF_SUCCESS), name, failMsg, result, ESMF_SRCLINE) - - ! initialize data - arrayPtrR8D1 = 12345._ESMF_KIND_R8*localPet !------------------------------------------------------------------------ !NEX_UTest_Multi_Proc_Only @@ -1484,7 +1476,7 @@ program ESMF_ArrayIOUTest write(name, *) "Array with replicated dimension 2 comparison Test" write(failMsg, *) "Did not return ESMF_SUCCESS" #if (defined ESMF_PIO && (defined ESMF_NETCDF || defined ESMF_PNETCDF)) - passfail = all (arrayPtrR8D1_r == 12345.0_ESMF_KIND_R8*localPet) + passfail = all (arrayPtrR8D1_r == arrayPtrR8D1) #else passfail = .true. #endif @@ -1512,7 +1504,7 @@ program ESMF_ArrayIOUTest call ESMF_Test((rc == ESMF_SUCCESS), name, failMsg, result, ESMF_SRCLINE) !------------------------------------------------------------------------ -! Array with repliocated dimension(s) decomp along dim 2 +! Array with replicated dimension(s) decomp along dim 2 !------------------------------------------------------------------------ !------------------------------------------------------------------------ @@ -1535,20 +1527,16 @@ program ESMF_ArrayIOUTest !------------------------------------------------------------------------ !NEX_UTest_Multi_Proc_Only write(name, *) "Array with replicated dimension 1 get and fill Test" - write(failMsg, *) "Did not return ESMF_SUCCESS" - ! access the pointer to the allocated memory on each DE - call ESMF_ArrayGet(array_repli1, farrayPtr=arrayPtrR8D1, rc=rc) + write(failMsg, *) "Did not return ESMF_SUCCESS" + call fillArray1d(array_repli1, arrayPtrR8D1, rc) call ESMF_Test((rc == ESMF_SUCCESS), name, failMsg, result, ESMF_SRCLINE) - ! initialize data - arrayPtrR8D1 = 12345._ESMF_KIND_R8*localPet - !------------------------------------------------------------------------ !NEX_UTest_Multi_Proc_Only ! ! Given an ESMF array, write the netCDF file. write(name, *) "Array with replicated dimension 1 (first) write to NetCDF Test" write(failMsg, *) "Did not return ESMF_SUCCESS" - call ESMF_ArrayWrite(array_repli1, fileName="Array_repli1_first.nc", & + call ESMF_ArrayWrite(array_repli1, fileName="Array_repli1_second.nc", & status=ESMF_FILESTATUS_REPLACE, iofmt=ESMF_IOFMT_NETCDF, rc=rc) #if (defined ESMF_PIO && (defined ESMF_NETCDF || defined ESMF_PNETCDF)) call ESMF_Test((rc==ESMF_SUCCESS), name, failMsg, result, ESMF_SRCLINE) @@ -1580,7 +1568,7 @@ program ESMF_ArrayIOUTest ! ! Given an ESMF array, read the netCDF file. write(name, *) "Array with replicated dimension 1 (first) read from NetCDF Test" write(failMsg, *) "Did not return ESMF_SUCCESS" - call ESMF_ArrayRead(array_repli1_r, fileName="Array_repli1_first.nc", & + call ESMF_ArrayRead(array_repli1_r, fileName="Array_repli1_second.nc", & iofmt=ESMF_IOFMT_NETCDF, rc=rc) #if (defined ESMF_PIO && (defined ESMF_NETCDF || defined ESMF_PNETCDF)) call ESMF_Test((rc == ESMF_SUCCESS), name, failMsg, result, ESMF_SRCLINE) @@ -1595,7 +1583,7 @@ program ESMF_ArrayIOUTest write(name, *) "Array with replicated dimension 1 comparison Test" write(failMsg, *) "Did not return ESMF_SUCCESS" #if (defined ESMF_PIO && (defined ESMF_NETCDF || defined ESMF_PNETCDF)) - passfail = all (arrayPtrR8D1_r == 12345.0_ESMF_KIND_R8*localPet) + passfail = all (arrayPtrR8D1_r == arrayPtrR8D1) #else passfail = .true. #endif @@ -1627,20 +1615,16 @@ program ESMF_ArrayIOUTest !------------------------------------------------------------------------ !NEX_UTest_Multi_Proc_Only write(name, *) "Array with replicated dimension 2 get and fill Test" - write(failMsg, *) "Did not return ESMF_SUCCESS" - ! access the pointer to the allocated memory on each DE - call ESMF_ArrayGet(array_repli2, farrayPtr=arrayPtrR8D1, rc=rc) + write(failMsg, *) "Did not return ESMF_SUCCESS" + call fillArray1d(array_repli2, arrayPtrR8D1, rc) call ESMF_Test((rc == ESMF_SUCCESS), name, failMsg, result, ESMF_SRCLINE) - ! initialize data - arrayPtrR8D1 = 12345._ESMF_KIND_R8*localPet - !------------------------------------------------------------------------ !NEX_UTest_Multi_Proc_Only ! ! Given an ESMF array, write the netCDF file. write(name, *) "Array with replicated dimension 2 (first) write to NetCDF Test" write(failMsg, *) "Did not return ESMF_SUCCESS" - call ESMF_ArrayWrite(array_repli2, fileName="Array_repli2_first.nc", & + call ESMF_ArrayWrite(array_repli2, fileName="Array_repli2_second.nc", & status=ESMF_FILESTATUS_REPLACE, iofmt=ESMF_IOFMT_NETCDF, rc=rc) #if (defined ESMF_PIO && (defined ESMF_NETCDF || defined ESMF_PNETCDF)) call ESMF_Test((rc==ESMF_SUCCESS), name, failMsg, result, ESMF_SRCLINE) @@ -1672,7 +1656,7 @@ program ESMF_ArrayIOUTest ! ! Given an ESMF array, read the netCDF file. write(name, *) "Array with replicated dimension 2 (first) read from NetCDF Test" write(failMsg, *) "Did not return ESMF_SUCCESS" - call ESMF_ArrayRead(array_repli2_r, fileName="Array_repli2_first.nc", & + call ESMF_ArrayRead(array_repli2_r, fileName="Array_repli2_second.nc", & iofmt=ESMF_IOFMT_NETCDF, rc=rc) #if (defined ESMF_PIO && (defined ESMF_NETCDF || defined ESMF_PNETCDF)) call ESMF_Test((rc == ESMF_SUCCESS), name, failMsg, result, ESMF_SRCLINE) @@ -1684,14 +1668,14 @@ program ESMF_ArrayIOUTest #if 0 ! This test is disabled because currently there is no support of scattering ! data during read into DEs along replicated dims that hold data outside -! the exclusive regrion of the index space of the DistGrid. +! the exclusive region of the index space of the DistGrid. !------------------------------------------------------------------------ !NEX_disabled_UTest_Multi_Proc_Only ! ! Compare read-in Array to expected write(name, *) "Array with replicated dimension 2 comparison Test" write(failMsg, *) "Did not return ESMF_SUCCESS" #if (defined ESMF_PIO && (defined ESMF_NETCDF || defined ESMF_PNETCDF)) - passfail = all (arrayPtrR8D1_r == 12345.0_ESMF_KIND_R8*localPet) + passfail = all (arrayPtrR8D1_r == arrayPtrR8D1) #else passfail = .true. #endif @@ -1872,4 +1856,27 @@ program ESMF_ArrayIOUTest call ESMF_TestEnd(ESMF_SRCLINE) ! calls ESMF_Finalize() internally !----------------------------------------------------------------------------- +contains + + subroutine fillArray1d(arrayToFill, arrayToFillPtr, rc) + ! Fills a 1-d ESMF_Array with data (localPet times index), and returns a pointer to + ! the Array's data + ! + ! Assumes 1 DE per PET; works best if arrayToFill is created with ESMF_INDEX_GLOBAL + + type(ESMF_Array), intent(in) :: arrayToFill + real(ESMF_KIND_R8), pointer, intent(out) :: arrayToFillPtr(:) + integer, intent(out) :: rc + + integer :: i + + call ESMF_ArrayGet(arrayToFill, farrayPtr=arrayToFillPtr, rc=rc) + if (rc /= ESMF_SUCCESS) return + + do i = lbound(arrayToFillPtr, 1), ubound(arrayToFillPtr, 1) + arrayToFillPtr(i) = localPet*100._ESMF_KIND_R8 + i + end do + + end subroutine fillArray1d + end program ESMF_ArrayIOUTest diff --git a/src/Infrastructure/IO/src/ESMCI_IO.C b/src/Infrastructure/IO/src/ESMCI_IO.C index 62325c29b2..c653580ffe 100644 --- a/src/Infrastructure/IO/src/ESMCI_IO.C +++ b/src/Infrastructure/IO/src/ESMCI_IO.C @@ -1257,9 +1257,7 @@ void IO::redist_arraycreate1de(Array *src_array_p, Array **dest_array_p, int pet int ndims = dg_orig->getDimCount(); int rank = src_array_p->getRank(); - int replicatedDims=0; - for (int i=0; igetReplicatedDimCount(); std::vector minIndexTileVec; std::vector maxIndexTileVec;