Skip to content

Commit 2969235

Browse files
committed
libnbc: fix NBC_Copy for predefined datatypes
predefined datatypes such as MPI_LONG_DOUBLE_INT are not really contiguous, so use span as returned by opal_datatype_span() instead of type extent, otherwise data might be written above allocated memory. Thanks Valentin Petrov for the report
1 parent 16fe18e commit 2969235

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

ompi/mca/coll/libnbc/nbc_internal.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,6 @@ static inline int NBC_Type_intrinsic(MPI_Datatype type) {
486486
/* let's give a try to inline functions */
487487
static inline int NBC_Copy(const void *src, int srccount, MPI_Datatype srctype, void *tgt, int tgtcount, MPI_Datatype tgttype, MPI_Comm comm) {
488488
int size, pos, res;
489-
OPAL_PTRDIFF_TYPE ext, lb;
490489
void *packbuf;
491490

492491
#if OPAL_CUDA_SUPPORT
@@ -496,13 +495,10 @@ static inline int NBC_Copy(const void *src, int srccount, MPI_Datatype srctype,
496495
#endif /* OPAL_CUDA_SUPPORT */
497496
/* if we have the same types and they are contiguous (intrinsic
498497
* types are contiguous), we can just use a single memcpy */
499-
res = ompi_datatype_get_extent(srctype, &lb, &ext);
500-
if (OMPI_SUCCESS != res) {
501-
NBC_Error ("MPI Error in MPI_Type_extent() (%i)", res);
502-
return res;
503-
}
498+
ptrdiff_t gap, span;
499+
span = opal_datatype_span(&srctype->super, srccount, &gap);
504500

505-
memcpy(tgt, src, srccount*ext);
501+
memcpy(tgt, src, span);
506502
} else {
507503
/* we have to pack and unpack */
508504
res = PMPI_Pack_size(srccount, srctype, comm, &size);

0 commit comments

Comments
 (0)