Skip to content

Commit

Permalink
Use HAVE_MPI_LARGE_COUNT to check availability of large-count MPI APIs
Browse files Browse the repository at this point in the history
This should avoid issue of using large-count APIs to create MPI
datatypes which is later used in non-large-count APIs.
  • Loading branch information
wkliao committed Nov 11, 2024
1 parent 0e4cc93 commit 1d9186c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
28 changes: 14 additions & 14 deletions src/drivers/common/dtype_decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ dtype_filter(MPI_Datatype type)
static MPI_Offset
darray_get_totalblks(int rank,
int ndims,
#ifdef HAVE_MPI_TYPE_GET_CONTENTS_C
#ifdef HAVE_MPI_LARGE_COUNT
MPI_Count array_of_gsizes[],
#else
int array_of_gsizes[],
Expand Down Expand Up @@ -324,7 +324,7 @@ int ncmpii_dtype_decode(MPI_Datatype dtype,
}

is_large_type = 0;
#ifdef HAVE_MPI_TYPE_GET_ENVELOPE_C
#ifdef HAVE_MPI_LARGE_COUNT
/* MPI_Type_get_envelope_c is introduced in MPI 4.0 */
mpireturn = MPI_Type_get_envelope_c(dtype, &num_ints, &num_adds, &num_larges, &num_dtypes, &combiner);
if (mpireturn != MPI_SUCCESS)
Expand Down Expand Up @@ -366,7 +366,7 @@ int ncmpii_dtype_decode(MPI_Datatype dtype,
array_of_dtypes = (MPI_Datatype *) NCI_Malloc((size_t)num_dtypes * sizeof(MPI_Datatype));

if (is_large_type) {
#ifdef HAVE_MPI_TYPE_GET_CONTENTS_C
#ifdef HAVE_MPI_LARGE_COUNT
array_of_larges = (MPI_Count *) NCI_Malloc(sizeof(MPI_Count) * num_larges);
mpireturn = MPI_Type_get_contents_c(dtype, num_ints, num_adds, num_larges, num_dtypes,
array_of_ints, array_of_adds, array_of_larges, array_of_dtypes);
Expand Down Expand Up @@ -414,7 +414,7 @@ int ncmpii_dtype_decode(MPI_Datatype dtype,
case MPI_COMBINER_STRUCT_INTEGER:
#endif
if (is_large_type)
#ifdef HAVE_MPI_TYPE_GET_CONTENTS_C
#ifdef HAVE_MPI_LARGE_COUNT
count = array_of_larges[0];
#else
return ncmpii_error_mpi2nc(MPI_ERR_IO, "MPI_COMBINER_STRUCT");
Expand All @@ -431,7 +431,7 @@ int ncmpii_dtype_decode(MPI_Datatype dtype,
if (status != NC_NOERR) return status;
if (isderived) MPI_Type_free(array_of_dtypes+i);
if (is_large_type) {
#ifdef HAVE_MPI_TYPE_GET_CONTENTS_C
#ifdef HAVE_MPI_LARGE_COUNT
/* product of array_of_blocklengths[] */
if (el_size > 0) nelems *= array_of_larges[1+i];
#else
Expand All @@ -457,13 +457,13 @@ int ncmpii_dtype_decode(MPI_Datatype dtype,
NCI_Free(array_of_ints);
NCI_Free(array_of_adds);
NCI_Free(array_of_dtypes);
#ifdef HAVE_MPI_TYPE_GET_CONTENTS_C
#ifdef HAVE_MPI_LARGE_COUNT
if (is_large_type) NCI_Free(array_of_larges);
#endif
DEBUG_RETURN_ERROR(NC_EMULTITYPES)
}
if (is_large_type)
#ifdef HAVE_MPI_TYPE_GET_CONTENTS_C
#ifdef HAVE_MPI_LARGE_COUNT
/* product of array_of_blocklengths[] */
nelems += tmpnelems * array_of_larges[1+i];
#else
Expand All @@ -484,7 +484,7 @@ int ncmpii_dtype_decode(MPI_Datatype dtype,
/* single etype */
case MPI_COMBINER_CONTIGUOUS:
if (is_large_type)
#ifdef HAVE_MPI_TYPE_GET_CONTENTS_C
#ifdef HAVE_MPI_LARGE_COUNT
total_blocks = array_of_larges[0];
#else
return ncmpii_error_mpi2nc(MPI_ERR_IO, "MPI_COMBINER_CONTIGUOUS");
Expand All @@ -500,7 +500,7 @@ int ncmpii_dtype_decode(MPI_Datatype dtype,
case MPI_COMBINER_INDEXED_BLOCK:
if (iscontig_of_ptypes) *iscontig_of_ptypes = 0;
if (is_large_type)
#ifdef HAVE_MPI_TYPE_GET_CONTENTS_C
#ifdef HAVE_MPI_LARGE_COUNT
/* count x blocklength */
total_blocks = array_of_larges[0]*array_of_larges[1];
#else
Expand All @@ -517,7 +517,7 @@ int ncmpii_dtype_decode(MPI_Datatype dtype,
#endif
if (iscontig_of_ptypes) *iscontig_of_ptypes = 0;
if (is_large_type) {
#ifdef HAVE_MPI_TYPE_GET_CONTENTS_C
#ifdef HAVE_MPI_LARGE_COUNT
/* sum of array_of_blocklengths[] */
for (i=0, total_blocks=0; i<array_of_larges[0]; i++)
total_blocks += array_of_larges[1+i];
Expand All @@ -535,7 +535,7 @@ int ncmpii_dtype_decode(MPI_Datatype dtype,
if (iscontig_of_ptypes) *iscontig_of_ptypes = 0;
ndims = array_of_ints[0];
if (is_large_type) {
#ifdef HAVE_MPI_TYPE_GET_CONTENTS_C
#ifdef HAVE_MPI_LARGE_COUNT
/* calculate product of array_of_subsizes[] */
for (i=0, total_blocks=1; i<ndims; i++)
total_blocks *= array_of_larges[ndims+i];
Expand All @@ -552,7 +552,7 @@ int ncmpii_dtype_decode(MPI_Datatype dtype,
case MPI_COMBINER_DARRAY:
if (iscontig_of_ptypes) *iscontig_of_ptypes = 0;
ndims = array_of_ints[2];
#ifdef HAVE_MPI_TYPE_GET_CONTENTS_C
#ifdef HAVE_MPI_LARGE_COUNT
int *distribs, *dargs, *psizes;
MPI_Count *gzises;
if (is_large_type) {
Expand All @@ -577,7 +577,7 @@ int ncmpii_dtype_decode(MPI_Datatype dtype,
/* seldom reached, so put it in a separate function */
total_blocks = darray_get_totalblks(array_of_ints[1], /* rank */
ndims, gzises, distribs, dargs, psizes);
#ifdef HAVE_MPI_TYPE_GET_CONTENTS_C
#ifdef HAVE_MPI_LARGE_COUNT
if (!is_large_type) NCI_Free(gzises);
#endif
break;
Expand All @@ -599,7 +599,7 @@ int ncmpii_dtype_decode(MPI_Datatype dtype,
NCI_Free(array_of_ints);
NCI_Free(array_of_adds);
NCI_Free(array_of_dtypes);
#ifdef HAVE_MPI_TYPE_GET_CONTENTS_C
#ifdef HAVE_MPI_LARGE_COUNT
if (is_large_type) NCI_Free(array_of_larges);
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/drivers/ncmpio/ncmpio_filetype.c
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ ncmpio_filetype_create_vars(const NC *ncp,
}

if (isLargeReq) {
#ifdef HAVE_MPI_TYPE_CREATE_HINDEXED_C
#ifdef HAVE_MPI_LARGE_COUNT
MPI_Count *blocklens_c, *disps_c;
blocklens_c = (MPI_Count*) NCI_Malloc(sizeof(MPI_Count) * nblocks);
disps_c = (MPI_Count*) NCI_Malloc(sizeof(MPI_Count) * nblocks);
Expand Down

0 comments on commit 1d9186c

Please sign in to comment.