Skip to content

Commit 4c79d0d

Browse files
committed
Bring pack and unpack in sync
Signed-off-by: George Bosilca <[email protected]>
1 parent dbe69f9 commit 4c79d0d

File tree

1 file changed

+35
-33
lines changed

1 file changed

+35
-33
lines changed

opal/datatype/opal_datatype_unpack.c

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana
44
* University Research and Technology
55
* Corporation. All rights reserved.
6-
* Copyright (c) 2004-2017 The University of Tennessee and The University
6+
* Copyright (c) 2004-2019 The University of Tennessee and The University
77
* of Tennessee Research Foundation. All rights
88
* reserved.
99
* Copyright (c) 2004-2006 High Performance Computing Center Stuttgart,
@@ -71,97 +71,99 @@ opal_unpack_homogeneous_contig_function( opal_convertor_t* pConv,
7171
const opal_datatype_t *pData = pConv->pDesc;
7272
unsigned char *user_memory, *packed_buffer;
7373
uint32_t iov_count, i;
74-
size_t bConverted, remaining, length, initial_bytes_converted = pConv->bConverted;
74+
size_t remaining, length, initial_bytes_converted = pConv->bConverted;
7575
dt_stack_t* stack = pConv->pStack;
7676
ptrdiff_t extent = pData->ub - pData->lb;
77-
ptrdiff_t initial_displ = pConv->use_desc->desc[pConv->use_desc->used].end_loop.first_elem_disp;
7877

7978
DO_DEBUG( opal_output( 0, "unpack_homogeneous_contig( pBaseBuf %p, iov_count %d )\n",
8079
(void*)pConv->pBaseBuf, *out_size ); );
8180
if( stack[1].type != opal_datatype_uint1.id ) {
8281
stack[1].count *= opal_datatype_basicDatatypes[stack[1].type]->size;
8382
stack[1].type = opal_datatype_uint1.id;
8483
}
84+
8585
for( iov_count = 0; iov_count < (*out_size); iov_count++ ) {
8686
remaining = pConv->local_size - pConv->bConverted;
8787
if( 0 == remaining ) break; /* we're done this time */
8888
if( remaining > iov[iov_count].iov_len )
8989
remaining = iov[iov_count].iov_len;
9090
packed_buffer = (unsigned char*)iov[iov_count].iov_base;
91-
bConverted = remaining; /* how much will get unpacked this time */
92-
user_memory = pConv->pBaseBuf + initial_displ;
91+
pConv->bConverted += remaining; /* how much will get unpacked this time */
92+
user_memory = pConv->pBaseBuf + pData->true_lb;
9393

9494
if( (ptrdiff_t)pData->size == extent ) {
9595
user_memory += pConv->bConverted;
96-
DO_DEBUG( opal_output( 0, "unpack_homogeneous_contig( user_memory %p, packed_buffer %p length %lu\n",
97-
(void*)user_memory, (void*)packed_buffer, (unsigned long)remaining ); );
96+
DO_DEBUG( opal_output( 0, "unpack_homogeneous_contig( user_memory %p, packed_buffer %p length %" PRIsize_t "\n",
97+
(void*)user_memory, (void*)packed_buffer, remaining ); );
9898

9999
/* contiguous data or basic datatype with count */
100100
OPAL_DATATYPE_SAFEGUARD_POINTER( user_memory, remaining,
101101
pConv->pBaseBuf, pData, pConv->count );
102-
DO_DEBUG( opal_output( 0, "1. unpack contig dest %p src %p length %lu\n",
103-
(void*)user_memory, (void*)packed_buffer, (unsigned long)remaining ); );
102+
DO_DEBUG( opal_output( 0, "1. unpack contig dest %p src %p length %" PRIsize_t "\n",
103+
(void*)user_memory, (void*)packed_buffer, remaining ); );
104104
MEMCPY_CSUM( user_memory, packed_buffer, remaining, pConv );
105105
} else {
106106
user_memory += stack[0].disp + stack[1].disp;
107107

108-
DO_DEBUG( opal_output( 0, "unpack_homogeneous_contig( user_memory %p, packed_buffer %p length %lu\n",
109-
(void*)user_memory, (void*)packed_buffer, (unsigned long)remaining ); );
108+
DO_DEBUG( opal_output( 0, "unpack_homogeneous_contig( user_memory %p, packed_buffer %p length %" PRIsize_t "\n",
109+
(void*)user_memory, (void*)packed_buffer, remaining ); );
110110

111111
length = (0 == pConv->stack_pos ? 0 : stack[1].count); /* left over from the last unpack */
112112
/* complete the last copy */
113-
if( (0 != length) && (length <= remaining) ) {
113+
if( (pData->size != length) && (length <= remaining) ) {
114114
OPAL_DATATYPE_SAFEGUARD_POINTER( user_memory, length, pConv->pBaseBuf,
115115
pData, pConv->count );
116-
DO_DEBUG( opal_output( 0, "2. unpack dest %p src %p length %lu\n",
117-
(void*)user_memory, (void*)packed_buffer, (unsigned long)length ); );
116+
DO_DEBUG( opal_output( 0, "2. unpack dest %p src %p length %" PRIsize_t "\n",
117+
(void*)user_memory, (void*)packed_buffer, length ); );
118118
MEMCPY_CSUM( user_memory, packed_buffer, length, pConv );
119119
packed_buffer += length;
120-
user_memory += (extent - (pData->size - length));
121120
remaining -= length;
122121
stack[1].count -= length;
122+
stack[1].disp += length; /* just in case, we overwrite this below */
123123
if( 0 == stack[1].count) { /* one completed element */
124124
stack[0].count--;
125125
stack[0].disp += extent;
126-
if( 0 != stack[0].count ) { /* not yet done */
127-
stack[1].count = pData->size;
128-
stack[1].disp = 0;
129-
}
126+
if( 0 == stack[0].count )
127+
break;
128+
stack[1].count = pData->size;
129+
stack[1].disp = 0;
130130
}
131+
user_memory = pConv->pBaseBuf + pData->true_lb + stack[0].disp + stack[1].disp;
131132
}
133+
132134
for( i = 0; pData->size <= remaining; i++ ) {
133135
OPAL_DATATYPE_SAFEGUARD_POINTER( user_memory, pData->size, pConv->pBaseBuf,
134136
pData, pConv->count );
135-
DO_DEBUG( opal_output( 0, "3. unpack dest %p src %p length %lu\n",
136-
(void*)user_memory, (void*)packed_buffer, (unsigned long)pData->size ); );
137+
DO_DEBUG( opal_output( 0, "3. unpack dest %p src %p length %" PRIsize_t "\n",
138+
(void*)user_memory, (void*)packed_buffer, pData->size ); );
137139
MEMCPY_CSUM( user_memory, packed_buffer, pData->size, pConv );
138140
packed_buffer += pData->size;
139141
user_memory += extent;
140142
remaining -= pData->size;
141143
}
142144
stack[0].count -= i;
143145
stack[0].disp += (i * extent);
144-
stack[1].disp += remaining;
145-
/* copy the last bits */
146+
147+
/* Copy the last bits */
146148
if( 0 != remaining ) {
147149
OPAL_DATATYPE_SAFEGUARD_POINTER( user_memory, remaining, pConv->pBaseBuf,
148150
pData, pConv->count );
149-
DO_DEBUG( opal_output( 0, "4. unpack dest %p src %p length %lu\n",
150-
(void*)user_memory, (void*)packed_buffer, (unsigned long)remaining ); );
151+
DO_DEBUG( opal_output( 0, "4. unpack dest %p src %p length %" PRIsize_t "\n",
152+
(void*)user_memory, (void*)packed_buffer, remaining ); );
151153
MEMCPY_CSUM( user_memory, packed_buffer, remaining, pConv );
152-
user_memory += remaining;
153154
stack[1].count -= remaining;
155+
stack[1].disp += remaining; /* keep the += in case we are copying less that the datatype size */
156+
if( 0 == stack[1].count ) { /* prepare for the next element */
157+
stack[1].count = pData->size;
158+
stack[1].disp = 0;
159+
}
154160
}
155161
}
156-
pConv->bConverted += bConverted;
157162
}
158163
*out_size = iov_count; /* we only reach this line after the for loop succesfully complete */
159-
*max_data = (pConv->bConverted - initial_bytes_converted);
160-
if( pConv->bConverted == pConv->local_size ) {
161-
pConv->flags |= CONVERTOR_COMPLETED;
162-
return 1;
163-
}
164-
return 0;
164+
*max_data = pConv->bConverted - initial_bytes_converted;
165+
if( pConv->bConverted == pConv->local_size ) pConv->flags |= CONVERTOR_COMPLETED;
166+
return !!(pConv->flags & CONVERTOR_COMPLETED); /* done or not */
165167
}
166168

167169
/**

0 commit comments

Comments
 (0)