Skip to content

Commit

Permalink
Start optimizing the code.
Browse files Browse the repository at this point in the history
Signed-off-by: George Bosilca <bosilca@icl.utk.edu>
  • Loading branch information
bosilca committed Jul 10, 2019
1 parent 3562d70 commit db8d2d0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
20 changes: 9 additions & 11 deletions opal/datatype/opal_datatype_pack.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ pack_predefined_data( opal_convertor_t* CONVERTOR,
/* premptively update the number of COUNT we will return. */
*(COUNT) -= cando_count;

if( 1 == _elem->count ) { /* Everything is contiguous, handle it as a prologue */
if( 1 == _elem->count ) { /* Everything is contiguous, handle it as the last contiguous piece */
goto do_epilog;
}
if( 1 == _elem->blocklen ) { /* Do as many full blocklen as possible */
for(; cando_count > 0; cando_count--) {
OPAL_DATATYPE_SAFEGUARD_POINTER( _memory, blocklen_bytes, (CONVERTOR)->pBaseBuf,
(CONVERTOR)->pDesc, (CONVERTOR)->count );
DO_DEBUG( opal_output( 0, "pack 2. memcpy( %p, %p, %lu ) => space %lu\n",
DO_DEBUG( opal_output( 0, "pack memcpy( %p, %p, %lu ) => space %lu [blen = 1]\n",
(void*)_packed, (void*)_memory, (unsigned long)blocklen_bytes, (unsigned long)(*(SPACE) - (_packed - *(packed))) ); );
MEMCPY_CSUM( _packed, _memory, blocklen_bytes, (CONVERTOR) );
_packed += blocklen_bytes;
Expand All @@ -75,23 +75,21 @@ pack_predefined_data( opal_convertor_t* CONVERTOR,
* should be manipulated in the current call (this number is instead reflected on the
* SPACE).
*/
do_now = do_now % _elem->blocklen; /* any partial elements ? */

if( 0 != do_now ) {
if( 0 != (do_now = do_now % _elem->blocklen) ) { /* any partial elements ? */
size_t left_in_block = do_now; /* left in the current blocklen */
do_now = (do_now > cando_count ) ? cando_count : do_now;
do_now = (do_now > cando_count) ? cando_count : do_now;
do_now_bytes = do_now * opal_datatype_basicDatatypes[_elem->common.type]->size;

OPAL_DATATYPE_SAFEGUARD_POINTER( _memory, do_now_bytes, (CONVERTOR)->pBaseBuf,
(CONVERTOR)->pDesc, (CONVERTOR)->count );
DO_DEBUG( opal_output( 0, "pack 1. memcpy( %p, %p, %lu ) => space %lu [prolog]\n",
DO_DEBUG( opal_output( 0, "pack memcpy( %p, %p, %lu ) => space %lu [prolog]\n",
_packed, (void*)_memory, (unsigned long)do_now_bytes, (unsigned long)(*(SPACE)) ); );
MEMCPY_CSUM( _packed, _memory, do_now_bytes, (CONVERTOR) );
_packed += do_now_bytes;
_memory += (ptrdiff_t)do_now_bytes;
/* compensate if we just completed a blocklen */
if( do_now == left_in_block )

if( do_now == left_in_block ) /* compensate if completed a blocklen */
_memory += _elem->extent - blocklen_bytes;
_packed += do_now_bytes;
cando_count -= do_now;
}

Expand Down Expand Up @@ -119,7 +117,7 @@ pack_predefined_data( opal_convertor_t* CONVERTOR,
OPAL_DATATYPE_SAFEGUARD_POINTER( _memory, do_now_bytes, (CONVERTOR)->pBaseBuf,
(CONVERTOR)->pDesc, (CONVERTOR)->count );
DO_DEBUG( opal_output( 0, "pack 3. memcpy( %p, %p, %lu ) => space %lu [epilog]\n",
(void*)_packed, (void*)_memory, (unsigned long)do_now_bytes, (unsigned long)(*(SPACE)) ); );
(void*)_packed, (void*)_memory, (unsigned long)do_now_bytes, (unsigned long)(*(SPACE) - (_packed - *(packed))) ); );
MEMCPY_CSUM( _packed, _memory, do_now_bytes, (CONVERTOR) );
_memory += do_now_bytes;
_packed += do_now_bytes;
Expand Down
20 changes: 9 additions & 11 deletions opal/datatype/opal_datatype_unpack.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ unpack_predefined_data( opal_convertor_t* CONVERTOR,
/* premptively update the number of COUNT we will return. */
*(COUNT) -= cando_count;

if( 1 == _elem->count ) { /* Everything is contiguous, handle it as a prologue */
if( 1 == _elem->count ) { /* Everything is contiguous, handle it as the last contiguous piece */
goto do_epilog;
}
if( 1 == _elem->blocklen ) { /* Do as many full blocklen as possible */
for(; cando_count > 0; cando_count--) {
OPAL_DATATYPE_SAFEGUARD_POINTER( _memory, blocklen_bytes, (CONVERTOR)->pBaseBuf,
(CONVERTOR)->pDesc, (CONVERTOR)->count );
DO_DEBUG( opal_output( 0, "unpack 2. memcpy( %p, %p, %lu ) => space %lu\n",
DO_DEBUG( opal_output( 0, "unpack memcpy( %p, %p, %lu ) => space %lu [blen = 1]\n",
(void*)_memory, (void*)_packed, (unsigned long)blocklen_bytes, (unsigned long)(*(SPACE) - (_packed - *(packed))) ); );
MEMCPY_CSUM( _memory, _packed, blocklen_bytes, (CONVERTOR) );
_packed += blocklen_bytes;
Expand All @@ -76,23 +76,21 @@ unpack_predefined_data( opal_convertor_t* CONVERTOR,
* should be manipulated in the current call (this number is instead reflected on the
* SPACE).
*/
do_now = do_now % _elem->blocklen; /* any partial elements ? */

if( 0 != do_now ) {
if( 0 != (do_now = do_now % _elem->blocklen) ) { /* any partial elements ? */
size_t left_in_block = do_now; /* left in the current blocklen */
do_now = (do_now > cando_count ) ? cando_count : do_now;
do_now = (do_now > cando_count) ? cando_count : do_now;
do_now_bytes = do_now * opal_datatype_basicDatatypes[_elem->common.type]->size;

OPAL_DATATYPE_SAFEGUARD_POINTER( _memory, do_now_bytes, (CONVERTOR)->pBaseBuf,
(CONVERTOR)->pDesc, (CONVERTOR)->count );
DO_DEBUG( opal_output( 0, "unpack 1. memcpy( %p, %p, %lu ) => space %lu [prolog]\n",
DO_DEBUG( opal_output( 0, "unpack memcpy( %p, %p, %lu ) => space %lu [prolog]\n",
(void*)_memory, (void*)_packed, (unsigned long)do_now_bytes, (unsigned long)(*(SPACE)) ); );
MEMCPY_CSUM( _memory, _packed, do_now_bytes, (CONVERTOR) );
_memory += (ptrdiff_t)do_now_bytes;
/* compensate if we just completed a blocklen */
if( do_now == left_in_block )
_memory += _elem->extent - blocklen_bytes;
_packed += do_now_bytes;
_memory += (ptrdiff_t)do_now_bytes;

if( do_now == left_in_block ) /* compensate if completed a blocklen */
_memory += _elem->extent - blocklen_bytes;
cando_count -= do_now;
}

Expand Down

0 comments on commit db8d2d0

Please sign in to comment.