From 5214e3751bb5b47304eb60af2c2f08492a834651 Mon Sep 17 00:00:00 2001 From: George Bosilca Date: Tue, 13 Feb 2007 09:28:05 +0000 Subject: [PATCH] Correctly handle the pack and unpack for contiguous types with gaps. Th pack/unpack let the convertor in a consistent state, such that the next operation will succeed. This commit was SVN r13630. --- ompi/datatype/datatype_pack.c | 29 +++++++++++++++++------------ ompi/datatype/datatype_unpack.c | 15 +++++++++------ 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/ompi/datatype/datatype_pack.c b/ompi/datatype/datatype_pack.c index 36d784ef4f..1d65c74305 100644 --- a/ompi/datatype/datatype_pack.c +++ b/ompi/datatype/datatype_pack.c @@ -186,18 +186,16 @@ ompi_pack_homogeneous_contig_with_gaps_function( ompi_convertor_t* pConv, size_t done; packed_buffer = iov[iov_count].iov_base; - done = pConv->bConverted - i * pData->size; /* how much data left last time */ - user_memory += done; + done = pConv->bConverted - i * pData->size; /* partial data from last pack */ if( done != 0 ) { /* still some data to copy from the last time */ done = pData->size - done; OMPI_DDT_SAFEGUARD_POINTER( user_memory, done, pConv->pBaseBuf, pData, pConv->count ); MEMCPY_CSUM( packed_buffer, user_memory, done, pConv ); packed_buffer += done; max_allowed -= done; - i++; /* just to compute the correct source pointer */ total_bytes_converted += done; + user_memory += (extent - pData->size + done); } - user_memory = pConv->pBaseBuf + initial_displ + i * extent; counter = (uint32_t)(max_allowed / pData->size); if( counter > pConv->count ) counter = pConv->count; for( i = 0; i < counter; i++ ) { @@ -206,16 +204,23 @@ ompi_pack_homogeneous_contig_with_gaps_function( ompi_convertor_t* pConv, packed_buffer+= pData->size; user_memory += extent; } - max_allowed -= (counter * pData->size); - iov[iov_count].iov_len -= max_allowed; - total_bytes_converted += iov[iov_count].iov_len; + done = (counter * pData->size); + max_allowed -= done; + total_bytes_converted += done; + /* If there is anything pending ... */ + if( 0 != max_allowed ) { + done = max_allowed; + OMPI_DDT_SAFEGUARD_POINTER( user_memory, done, pConv->pBaseBuf, pData, pConv->count ); + MEMCPY_CSUM( packed_buffer, user_memory, done, pConv ); + packed_buffer += done; + max_allowed = 0; + total_bytes_converted += done; + user_memory += done; + } } - /* Now update the user_memory pointer. At the end of each parth we have to update - * the pStack[0].disp field. BEWARE here we remove the pStack[1].disp as - * it's supposed to be useless from now. - */ - user_memory = pConv->pBaseBuf + initial_displ + pStack[0].disp; } + pStack[0].disp = (intptr_t)user_memory - (intptr_t)pConv->pBaseBuf - initial_displ; + pStack[1].disp = max_allowed; *max_data = total_bytes_converted; pConv->bConverted += total_bytes_converted; *out_size = iov_count; diff --git a/ompi/datatype/datatype_unpack.c b/ompi/datatype/datatype_unpack.c index 615003f958..14c31cd17b 100644 --- a/ompi/datatype/datatype_unpack.c +++ b/ompi/datatype/datatype_unpack.c @@ -189,7 +189,7 @@ ompi_unpack_homogeneous_contig_function( ompi_convertor_t* pConv, char *user_memory, *packed_buffer; uint32_t iov_count, i; size_t bConverted, remaining, length, initial_bytes_converted = pConv->bConverted; - dt_stack_t* stack = &(pConv->pStack[1]); + dt_stack_t* stack = pConv->pStack; ptrdiff_t extent = pData->ub - pData->lb; ptrdiff_t initial_displ = pConv->use_desc->desc[pConv->use_desc->used].end_loop.first_elem_disp; @@ -203,11 +203,10 @@ ompi_unpack_homogeneous_contig_function( ompi_convertor_t* pConv, bConverted = remaining; /* how much will get unpacked this time */ user_memory = pConv->pBaseBuf + initial_displ; - DO_DEBUG( opal_output( 0, "unpack_homogeneous_contig( user_memory %p, packed_buffer %p length %lu\n", - user_memory, packed_buffer, (unsigned long)remaining ); ); - if( (ptrdiff_t)pData->size == extent ) { user_memory += pConv->bConverted; + DO_DEBUG( opal_output( 0, "unpack_homogeneous_contig( user_memory %p, packed_buffer %p length %lu\n", + user_memory, packed_buffer, (unsigned long)remaining ); ); /* contiguous data or basic datatype with count */ OMPI_DDT_SAFEGUARD_POINTER( user_memory, remaining, @@ -216,7 +215,10 @@ ompi_unpack_homogeneous_contig_function( ompi_convertor_t* pConv, user_memory, packed_buffer, (unsigned long)remaining ); ); MEMCPY_CSUM( user_memory, packed_buffer, remaining, pConv ); } else { - user_memory += stack->disp; + user_memory += stack[0].disp + stack[1].disp; + + DO_DEBUG( opal_output( 0, "unpack_homogeneous_contig( user_memory %p, packed_buffer %p length %lu\n", + user_memory, packed_buffer, (unsigned long)remaining ); ); length = pConv->bConverted / pData->size; /* already done */ length = pConv->bConverted - length * pData->size; /* how much of the last data we convert */ @@ -245,6 +247,8 @@ ompi_unpack_homogeneous_contig_function( ompi_convertor_t* pConv, user_memory += extent; remaining -= pData->size; } + stack[0].disp = (intptr_t)user_memory - (intptr_t)pConv->pBaseBuf - initial_displ; + stack[1].disp = remaining; /* copy the last bits */ if( remaining != 0 ) { OMPI_DDT_SAFEGUARD_POINTER( user_memory, remaining, pConv->pBaseBuf, @@ -254,7 +258,6 @@ ompi_unpack_homogeneous_contig_function( ompi_convertor_t* pConv, MEMCPY_CSUM( user_memory, packed_buffer, remaining, pConv ); user_memory += remaining; } - stack->disp = user_memory - pConv->pBaseBuf; /* save the position */ } pConv->bConverted += bConverted; }