From 54476382e6ef75d9e3880274b84b057d856598d0 Mon Sep 17 00:00:00 2001 From: George Bosilca Date: Wed, 4 Oct 2006 23:56:10 +0000 Subject: [PATCH] Remove all useless asserts and correct one of the comments. Correctly compute the length to be unpacked. Protect all outputs (only on debug mode and only if mpi_ddt_unpack is set). This commit was SVN r11984. --- ompi/datatype/datatype_unpack.c | 40 +++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/ompi/datatype/datatype_unpack.c b/ompi/datatype/datatype_unpack.c index a84a7c905a..7511af8390 100644 --- a/ompi/datatype/datatype_unpack.c +++ b/ompi/datatype/datatype_unpack.c @@ -195,6 +195,8 @@ ompi_unpack_homogeneous_contig_function( ompi_convertor_t* pConv, dt_stack_t* stack = &(pConv->pStack[1]); long initial_displ = pConv->use_desc->desc[pConv->use_desc->used].end_loop.first_elem_disp; + DO_DEBUG( opal_output( 0, "unpack_homogeneous_contig( pBaseBuf %p, iov_count %d )\n", + pConv->pBaseBuf, *out_size ); ); for( iov_count = 0; iov_count < (*out_size); iov_count++ ) { packed_buffer = (char*)iov[iov_count].iov_base; remaining = pConv->local_size - pConv->bConverted; @@ -203,8 +205,8 @@ ompi_unpack_homogeneous_contig_function( ompi_convertor_t* pConv, bConverted = remaining; /* how much will get unpacked this time */ user_memory = pConv->pBaseBuf + initial_displ; - /*opal_output( 0, "unpack_homogeneous_contig( user_memory %p, packed_buffer %p length %d\n", - user_memory, packed_buffer, remaining );*/ + DO_DEBUG( opal_output( 0, "unpack_homogeneous_contig( user_memory %p, packed_buffer %p length %d\n", + user_memory, packed_buffer, remaining ); ); if( (long)pData->size == extent ) { user_memory += pConv->bConverted; @@ -212,30 +214,34 @@ ompi_unpack_homogeneous_contig_function( ompi_convertor_t* pConv, /* contiguous data or basic datatype with count */ OMPI_DDT_SAFEGUARD_POINTER( user_memory, remaining, pConv->pBaseBuf, pData, pConv->count ); - /*opal_output( 0, "1. unpack contig dest %p src %p length %d\n", - user_memory, packed_buffer, remaining );*/ + DO_DEBUG( opal_output( 0, "1. unpack contig dest %p src %p length %d\n", + user_memory, packed_buffer, remaining ); ); MEMCPY_CSUM( user_memory, packed_buffer, remaining, pConv ); } else { user_memory += stack->disp; length = pConv->bConverted / pData->size; /* already done */ - length = pConv->bConverted - length * pData->size; /* still left on the last element */ + length = pConv->bConverted - length * pData->size; /* how much of the last data we convert */ + /* complete the last copy */ if( length != 0 ) { - OMPI_DDT_SAFEGUARD_POINTER( user_memory, length, pConv->pBaseBuf, - pData, pConv->count ); - /*opal_output( 0, "1. unpack dest %p src %p length %d\n", - user_memory, packed_buffer, length );*/ - MEMCPY_CSUM( user_memory, packed_buffer, length, pConv ); - packed_buffer += length; - user_memory += (extent - (pData->size - length)); - remaining -= length; + length = pData->size - length; + if( length <= remaining ) { + OMPI_DDT_SAFEGUARD_POINTER( user_memory, length, pConv->pBaseBuf, + pData, pConv->count ); + DO_DEBUG( opal_output( 0, "2. unpack dest %p src %p length %d\n", + user_memory, packed_buffer, length ); ); + MEMCPY_CSUM( user_memory, packed_buffer, length, pConv ); + packed_buffer += length; + user_memory += (extent - (pData->size - length)); + remaining -= length; + } } for( i = 0; pData->size <= remaining; i++ ) { OMPI_DDT_SAFEGUARD_POINTER( user_memory, pData->size, pConv->pBaseBuf, pData, pConv->count ); - /*opal_output( 0, "2. unpack dest %p src %p length %d\n", - user_memory, packed_buffer, pData->size );*/ + DO_DEBUG( opal_output( 0, "3. unpack dest %p src %p length %d\n", + user_memory, packed_buffer, pData->size ); ); MEMCPY_CSUM( user_memory, packed_buffer, pData->size, pConv ); packed_buffer += pData->size; user_memory += extent; @@ -245,8 +251,8 @@ ompi_unpack_homogeneous_contig_function( ompi_convertor_t* pConv, if( remaining != 0 ) { OMPI_DDT_SAFEGUARD_POINTER( user_memory, remaining, pConv->pBaseBuf, pData, pConv->count ); - /*opal_output( 0, "3. unpack dest %p src %p length %d\n", - user_memory, packed_buffer, remaining );*/ + DO_DEBUG( opal_output( 0, "4. unpack dest %p src %p length %d\n", + user_memory, packed_buffer, remaining ); ); MEMCPY_CSUM( user_memory, packed_buffer, remaining, pConv ); user_memory += remaining; }