1
1

Fix incorrect behavior with length == 0

Fixes #6575.

Signed-off-by: George Bosilca <bosilca@icl.utk.edu>
Этот коммит содержится в:
George Bosilca 2019-05-09 16:27:49 -04:00
родитель e547a2b94d
Коммит f68b06e9ee
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 09C926752C9F09B1
5 изменённых файлов: 68 добавлений и 87 удалений

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

@ -3,7 +3,7 @@
* Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana * Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana
* University Research and Technology * University Research and Technology
* Corporation. All rights reserved. * Corporation. All rights reserved.
* Copyright (c) 2004-2013 The University of Tennessee and The University * Copyright (c) 2004-2019 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights * of Tennessee Research Foundation. All rights
* reserved. * reserved.
* Copyright (c) 2004-2006 High Performance Computing Center Stuttgart, * Copyright (c) 2004-2006 High Performance Computing Center Stuttgart,
@ -29,13 +29,12 @@ int32_t ompi_datatype_create_contiguous( int count, const ompi_datatype_t* oldTy
{ {
ompi_datatype_t* pdt; ompi_datatype_t* pdt;
if( 0 == count ) { if( (0 == count) || (0 == oldType->super.size) ) {
pdt = ompi_datatype_create( 0 ); return ompi_datatype_duplicate( &ompi_mpi_datatype_null.dt, newType);
ompi_datatype_add( pdt, &ompi_mpi_datatype_null.dt, 0, 0, 0 );
} else {
pdt = ompi_datatype_create( oldType->super.desc.used + 2 );
opal_datatype_add( &(pdt->super), &(oldType->super), count, 0, (oldType->super.ub - oldType->super.lb) );
} }
pdt = ompi_datatype_create( oldType->super.desc.used + 2 );
opal_datatype_add( &(pdt->super), &(oldType->super), count, 0, (oldType->super.ub - oldType->super.lb) );
*newType = pdt; *newType = pdt;
return OMPI_SUCCESS; return OMPI_SUCCESS;
} }

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

@ -192,9 +192,7 @@ int32_t ompi_datatype_create_darray(int size,
if (ndims < 1) { if (ndims < 1) {
/* Don't just return MPI_DATATYPE_NULL as that can't be /* Don't just return MPI_DATATYPE_NULL as that can't be
MPI_TYPE_FREE()ed, and that seems bad */ MPI_TYPE_FREE()ed, and that seems bad */
*newtype = ompi_datatype_create(0); return ompi_datatype_duplicate( &ompi_mpi_datatype_null.dt, newtype);
ompi_datatype_add(*newtype, &ompi_mpi_datatype_null.dt, 0, 0, 0);
return MPI_SUCCESS;
} }
rc = ompi_datatype_type_extent(oldtype, &orig_extent); rc = ompi_datatype_type_extent(oldtype, &orig_extent);

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

@ -3,7 +3,7 @@
* Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana * Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana
* University Research and Technology * University Research and Technology
* Corporation. All rights reserved. * Corporation. All rights reserved.
* Copyright (c) 2004-2013 The University of Tennessee and The University * Copyright (c) 2004-2019 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights * of Tennessee Research Foundation. All rights
* reserved. * reserved.
* Copyright (c) 2004-2006 High Performance Computing Center Stuttgart, * Copyright (c) 2004-2006 High Performance Computing Center Stuttgart,
@ -34,24 +34,28 @@
int32_t ompi_datatype_create_indexed( int count, const int* pBlockLength, const int* pDisp, int32_t ompi_datatype_create_indexed( int count, const int* pBlockLength, const int* pDisp,
const ompi_datatype_t* oldType, ompi_datatype_t** newType ) const ompi_datatype_t* oldType, ompi_datatype_t** newType )
{ {
ompi_datatype_t* pdt;
int i;
ptrdiff_t extent, disp, endat; ptrdiff_t extent, disp, endat;
ompi_datatype_t* pdt;
size_t dLength; size_t dLength;
int i;
if( 0 == count ) { /* ignore all cases that lead to an empty type */
ompi_datatype_type_size(oldType, &dLength);
for( i = 0; (i < count) && (0 == pBlockLength[i]); i++ ); /* find first non zero */
if( (i == count) || (0 == dLength) ) {
return ompi_datatype_duplicate( &ompi_mpi_datatype_null.dt, newType); return ompi_datatype_duplicate( &ompi_mpi_datatype_null.dt, newType);
} }
disp = pDisp[0]; disp = pDisp[i];
dLength = pBlockLength[0]; dLength = pBlockLength[i];
endat = disp + dLength; endat = disp + dLength;
ompi_datatype_type_extent( oldType, &extent ); ompi_datatype_type_extent( oldType, &extent );
pdt = ompi_datatype_create( count * (2 + oldType->super.desc.used) ); pdt = ompi_datatype_create( (count - i) * (2 + oldType->super.desc.used) );
for( i = 1; i < count; i++ ) { for( i += 1; i < count; i++ ) {
if( endat == pDisp[i] ) { if( 0 == pBlockLength[i] ) /* ignore empty length */
/* contiguous with the previsious */ continue;
if( endat == pDisp[i] ) { /* contiguous with the previsious */
dLength += pBlockLength[i]; dLength += pBlockLength[i];
endat += pBlockLength[i]; endat += pBlockLength[i];
} else { } else {
@ -71,26 +75,28 @@ int32_t ompi_datatype_create_indexed( int count, const int* pBlockLength, const
int32_t ompi_datatype_create_hindexed( int count, const int* pBlockLength, const ptrdiff_t* pDisp, int32_t ompi_datatype_create_hindexed( int count, const int* pBlockLength, const ptrdiff_t* pDisp,
const ompi_datatype_t* oldType, ompi_datatype_t** newType ) const ompi_datatype_t* oldType, ompi_datatype_t** newType )
{ {
ompi_datatype_t* pdt;
int i;
ptrdiff_t extent, disp, endat; ptrdiff_t extent, disp, endat;
ompi_datatype_t* pdt;
size_t dLength; size_t dLength;
int i;
if( 0 == count ) { /* ignore all cases that lead to an empty type */
*newType = ompi_datatype_create( 0 ); ompi_datatype_type_size(oldType, &dLength);
ompi_datatype_add( *newType, &ompi_mpi_datatype_null.dt, 0, 0, 0); for( i = 0; (i < count) && (0 == pBlockLength[i]); i++ ); /* find first non zero */
return OMPI_SUCCESS; if( (i == count) || (0 == dLength) ) {
return ompi_datatype_duplicate( &ompi_mpi_datatype_null.dt, newType);
} }
ompi_datatype_type_extent( oldType, &extent ); disp = pDisp[i];
pdt = ompi_datatype_create( count * (2 + oldType->super.desc.used) ); dLength = pBlockLength[i];
disp = pDisp[0];
dLength = pBlockLength[0];
endat = disp + dLength * extent; endat = disp + dLength * extent;
ompi_datatype_type_extent( oldType, &extent );
for( i = 1; i < count; i++ ) { pdt = ompi_datatype_create( (count - i) * (2 + oldType->super.desc.used) );
if( endat == pDisp[i] ) { for( i += 1; i < count; i++ ) {
/* contiguous with the previsious */ if( 0 == pBlockLength[i] ) /* ignore empty length */
continue;
if( endat == pDisp[i] ) { /* contiguous with the previsious */
dLength += pBlockLength[i]; dLength += pBlockLength[i];
endat += pBlockLength[i] * extent; endat += pBlockLength[i] * extent;
} else { } else {
@ -110,21 +116,15 @@ int32_t ompi_datatype_create_hindexed( int count, const int* pBlockLength, const
int32_t ompi_datatype_create_indexed_block( int count, int bLength, const int* pDisp, int32_t ompi_datatype_create_indexed_block( int count, int bLength, const int* pDisp,
const ompi_datatype_t* oldType, ompi_datatype_t** newType ) const ompi_datatype_t* oldType, ompi_datatype_t** newType )
{ {
ompi_datatype_t* pdt;
int i;
ptrdiff_t extent, disp, endat; ptrdiff_t extent, disp, endat;
ompi_datatype_t* pdt;
size_t dLength; size_t dLength;
int i;
ompi_datatype_type_extent( oldType, &extent );
if( (count == 0) || (bLength == 0) ) { if( (count == 0) || (bLength == 0) ) {
if( 0 == count ) { return ompi_datatype_duplicate(&ompi_mpi_datatype_null.dt, newType);
return ompi_datatype_duplicate(&ompi_mpi_datatype_null.dt, newType);
} else {
*newType = ompi_datatype_create(1);
ompi_datatype_add( *newType, oldType, 0, pDisp[0] * extent, extent );
return OMPI_SUCCESS;
}
} }
ompi_datatype_type_extent( oldType, &extent );
pdt = ompi_datatype_create( count * (2 + oldType->super.desc.used) ); pdt = ompi_datatype_create( count * (2 + oldType->super.desc.used) );
disp = pDisp[0]; disp = pDisp[0];
dLength = bLength; dLength = bLength;
@ -150,20 +150,15 @@ int32_t ompi_datatype_create_indexed_block( int count, int bLength, const int* p
int32_t ompi_datatype_create_hindexed_block( int count, int bLength, const ptrdiff_t* pDisp, int32_t ompi_datatype_create_hindexed_block( int count, int bLength, const ptrdiff_t* pDisp,
const ompi_datatype_t* oldType, ompi_datatype_t** newType ) const ompi_datatype_t* oldType, ompi_datatype_t** newType )
{ {
ompi_datatype_t* pdt;
int i;
ptrdiff_t extent, disp, endat; ptrdiff_t extent, disp, endat;
ompi_datatype_t* pdt;
size_t dLength; size_t dLength;
int i;
ompi_datatype_type_extent( oldType, &extent );
if( (count == 0) || (bLength == 0) ) { if( (count == 0) || (bLength == 0) ) {
*newType = ompi_datatype_create(1); return ompi_datatype_duplicate(&ompi_mpi_datatype_null.dt, newType);
if( 0 == count )
ompi_datatype_add( *newType, &ompi_mpi_datatype_null.dt, 0, 0, 0 );
else
ompi_datatype_add( *newType, oldType, 0, pDisp[0] * extent, extent );
return OMPI_SUCCESS;
} }
ompi_datatype_type_extent( oldType, &extent );
pdt = ompi_datatype_create( count * (2 + oldType->super.desc.used) ); pdt = ompi_datatype_create( count * (2 + oldType->super.desc.used) );
disp = pDisp[0]; disp = pDisp[0];
dLength = bLength; dLength = bLength;

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

@ -3,7 +3,7 @@
* Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana * Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana
* University Research and Technology * University Research and Technology
* Corporation. All rights reserved. * Corporation. All rights reserved.
* Copyright (c) 2004-2013 The University of Tennessee and The University * Copyright (c) 2004-2019 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights * of Tennessee Research Foundation. All rights
* reserved. * reserved.
* Copyright (c) 2004-2006 High Performance Computing Center Stuttgart, * Copyright (c) 2004-2006 High Performance Computing Center Stuttgart,
@ -31,27 +31,27 @@
int32_t ompi_datatype_create_struct( int count, const int* pBlockLength, const ptrdiff_t* pDisp, int32_t ompi_datatype_create_struct( int count, const int* pBlockLength, const ptrdiff_t* pDisp,
ompi_datatype_t* const * pTypes, ompi_datatype_t** newType ) ompi_datatype_t* const * pTypes, ompi_datatype_t** newType )
{ {
int i;
ptrdiff_t disp = 0, endto, lastExtent, lastDisp; ptrdiff_t disp = 0, endto, lastExtent, lastDisp;
int lastBlock;
ompi_datatype_t *pdt, *lastType; ompi_datatype_t *pdt, *lastType;
int lastBlock;
int i, start_from;
if( 0 == count ) { /* Find first non-zero length element */
*newType = ompi_datatype_create( 0 ); for( i = 0; (i < count) && (0 == pBlockLength[i]); i++ );
ompi_datatype_add( *newType, &ompi_mpi_datatype_null.dt, 0, 0, 0); if( i == count ) { /* either nothing or nothing relevant */
return OMPI_SUCCESS; return ompi_datatype_duplicate( &ompi_mpi_datatype_null.dt, newType);
} }
/* compute the total number of elements before we can
/* if we compute the total number of elements before we can
* avoid increasing the size of the desc array often. * avoid increasing the size of the desc array often.
*/ */
lastType = (ompi_datatype_t*)pTypes[0]; start_from = i;
lastBlock = pBlockLength[0]; lastType = (ompi_datatype_t*)pTypes[start_from];
lastBlock = pBlockLength[start_from];
lastExtent = lastType->super.ub - lastType->super.lb; lastExtent = lastType->super.ub - lastType->super.lb;
lastDisp = pDisp[0]; lastDisp = pDisp[start_from];
endto = pDisp[0] + lastExtent * lastBlock; endto = pDisp[start_from] + lastExtent * lastBlock;
for( i = 1; i < count; i++ ) { for( i = (start_from + 1); i < count; i++ ) {
if( (pTypes[i] == lastType) && (pDisp[i] == endto) ) { if( (pTypes[i] == lastType) && (pDisp[i] == endto) ) {
lastBlock += pBlockLength[i]; lastBlock += pBlockLength[i];
endto = lastDisp + lastBlock * lastExtent; endto = lastDisp + lastBlock * lastExtent;
@ -68,16 +68,16 @@ int32_t ompi_datatype_create_struct( int count, const int* pBlockLength, const p
disp += lastType->super.desc.used; disp += lastType->super.desc.used;
if( lastBlock != 1 ) disp += 2; if( lastBlock != 1 ) disp += 2;
lastType = (ompi_datatype_t*)pTypes[0]; lastType = (ompi_datatype_t*)pTypes[start_from];
lastBlock = pBlockLength[0]; lastBlock = pBlockLength[start_from];
lastExtent = lastType->super.ub - lastType->super.lb; lastExtent = lastType->super.ub - lastType->super.lb;
lastDisp = pDisp[0]; lastDisp = pDisp[start_from];
endto = pDisp[0] + lastExtent * lastBlock; endto = pDisp[start_from] + lastExtent * lastBlock;
pdt = ompi_datatype_create( (int32_t)disp ); pdt = ompi_datatype_create( (int32_t)disp );
/* Do again the same loop but now add the elements */ /* Do again the same loop but now add the elements */
for( i = 1; i < count; i++ ) { for( i = (start_from + 1); i < count; i++ ) {
if( (pTypes[i] == lastType) && (pDisp[i] == endto) ) { if( (pTypes[i] == lastType) && (pDisp[i] == endto) ) {
lastBlock += pBlockLength[i]; lastBlock += pBlockLength[i];
endto = lastDisp + lastBlock * lastExtent; endto = lastDisp + lastBlock * lastExtent;

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

@ -3,7 +3,7 @@
* Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana * Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana
* University Research and Technology * University Research and Technology
* Corporation. All rights reserved. * Corporation. All rights reserved.
* Copyright (c) 2004-2013 The University of Tennessee and The University * Copyright (c) 2004-2019 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights * of Tennessee Research Foundation. All rights
* reserved. * reserved.
* Copyright (c) 2004-2006 High Performance Computing Center Stuttgart, * Copyright (c) 2004-2006 High Performance Computing Center Stuttgart,
@ -28,23 +28,14 @@
#include "ompi/datatype/ompi_datatype.h" #include "ompi/datatype/ompi_datatype.h"
/* Open questions ...
* - how to improuve the handling of these vectors (creating a temporary datatype
* can be ONLY a initial solution.
*
*/
int32_t ompi_datatype_create_vector( int count, int bLength, int stride, int32_t ompi_datatype_create_vector( int count, int bLength, int stride,
const ompi_datatype_t* oldType, ompi_datatype_t** newType ) const ompi_datatype_t* oldType, ompi_datatype_t** newType )
{ {
ompi_datatype_t *pTempData, *pData; ompi_datatype_t *pTempData, *pData;
ptrdiff_t extent = oldType->super.ub - oldType->super.lb; ptrdiff_t extent = oldType->super.ub - oldType->super.lb;
if( (0 == count) || (0 == bLength) ) {
if( 0 == count ) { return ompi_datatype_duplicate( &ompi_mpi_datatype_null.dt, newType);
*newType = ompi_datatype_create( 0 );
ompi_datatype_add( *newType, &ompi_mpi_datatype_null.dt, 0, 0, 0);
return OMPI_SUCCESS;
} }
pData = ompi_datatype_create( oldType->super.desc.used + 2 ); pData = ompi_datatype_create( oldType->super.desc.used + 2 );
@ -72,10 +63,8 @@ int32_t ompi_datatype_create_hvector( int count, int bLength, ptrdiff_t stride,
ompi_datatype_t *pTempData, *pData; ompi_datatype_t *pTempData, *pData;
ptrdiff_t extent = oldType->super.ub - oldType->super.lb; ptrdiff_t extent = oldType->super.ub - oldType->super.lb;
if( 0 == count ) { if( (0 == count) || (0 == bLength) ) {
*newType = ompi_datatype_create( 0 ); return ompi_datatype_duplicate( &ompi_mpi_datatype_null.dt, newType);
ompi_datatype_add( *newType, &ompi_mpi_datatype_null.dt, 0, 0, 0);
return OMPI_SUCCESS;
} }
pTempData = ompi_datatype_create( oldType->super.desc.used + 2 ); pTempData = ompi_datatype_create( oldType->super.desc.used + 2 );