1
1

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
Этот коммит содержится в:
Gilles Gouaillardet 2016-09-01 10:14:04 +09:00
родитель 16fe18eb7c
Коммит 2969235324

Просмотреть файл

@ -486,7 +486,6 @@ static inline int NBC_Type_intrinsic(MPI_Datatype type) {
/* let's give a try to inline functions */ /* let's give a try to inline functions */
static inline int NBC_Copy(const void *src, int srccount, MPI_Datatype srctype, void *tgt, int tgtcount, MPI_Datatype tgttype, MPI_Comm comm) { static inline int NBC_Copy(const void *src, int srccount, MPI_Datatype srctype, void *tgt, int tgtcount, MPI_Datatype tgttype, MPI_Comm comm) {
int size, pos, res; int size, pos, res;
OPAL_PTRDIFF_TYPE ext, lb;
void *packbuf; void *packbuf;
#if OPAL_CUDA_SUPPORT #if OPAL_CUDA_SUPPORT
@ -496,13 +495,10 @@ static inline int NBC_Copy(const void *src, int srccount, MPI_Datatype srctype,
#endif /* OPAL_CUDA_SUPPORT */ #endif /* OPAL_CUDA_SUPPORT */
/* if we have the same types and they are contiguous (intrinsic /* if we have the same types and they are contiguous (intrinsic
* types are contiguous), we can just use a single memcpy */ * types are contiguous), we can just use a single memcpy */
res = ompi_datatype_get_extent(srctype, &lb, &ext); ptrdiff_t gap, span;
if (OMPI_SUCCESS != res) { span = opal_datatype_span(&srctype->super, srccount, &gap);
NBC_Error ("MPI Error in MPI_Type_extent() (%i)", res);
return res;
}
memcpy(tgt, src, srccount*ext); memcpy(tgt, src, span);
} else { } else {
/* we have to pack and unpack */ /* we have to pack and unpack */
res = PMPI_Pack_size(srccount, srctype, comm, &size); res = PMPI_Pack_size(srccount, srctype, comm, &size);