⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 datatype_unpack.c

📁 MPI stands for the Message Passing Interface. Written by the MPI Forum (a large committee comprising
💻 C
📖 第 1 页 / 共 2 页
字号:
                                            pData, pConv->count );                DO_DEBUG( opal_output( 0, "4. unpack dest %p src %p length %lu\n",                                       user_memory, packed_buffer, (unsigned long)remaining ); );                MEMCPY_CSUM( user_memory, packed_buffer, remaining, pConv );                user_memory += remaining;            }        }        pConv->bConverted += bConverted;    }    *out_size = iov_count;    *max_data = (pConv->bConverted - initial_bytes_converted);    if( pConv->bConverted == pConv->local_size ) {        pConv->flags |= CONVERTOR_COMPLETED;        return 1;    }    return 0;}/** * This function handle partial types. Depending on the send operation it might happens * that we receive only a partial type (always predefined type). In fact the outcome is * that the unpack has to be done in 2 steps. As there is no way to know if the other * part of the datatype is already received, we need to use a trick to handle this special * case. The trick is to fill the missing part with some well known value, unpack the data * as if it was completely received, and then move into the user memory only the bytes * that don't match th wekk known value. This approach work as long as there is no need * for more than structural changes. They will not work for cases where we will have to * change the content of the data (as in all conversions that require changing the size * of the exponent or mantissa). */static inline uint32_tompi_unpack_partial_datatype( ompi_convertor_t* pConvertor, dt_elem_desc_t* pElem,                              char* partial_data,                              ptrdiff_t start_position, ptrdiff_t end_position,                              char** user_buffer ){    char unused_byte = 0x7F, saved_data[16];    char temporary[16], *temporary_buffer = temporary;    char* real_data = *user_buffer + pElem->elem.disp;    uint32_t i, length, count_desc = 1;    size_t data_length = ompi_ddt_basicDatatypes[pElem->elem.common.type]->size;    DO_DEBUG( opal_output( 0, "unpack partial data start %d end %d data_length %lu user %p\n"                           "\tbConverted %lu total_length %lu count %d\n",                           start_position, end_position, (unsigned long)data_length, *user_buffer,                           (unsigned long)pConvertor->bConverted, (unsigned long)pConvertor->local_size, pConvertor->count ); );    /* Find a byte that is not used in the partial buffer */ find_unused_byte:    length = (uint32_t)(end_position - start_position);    for( i = 0; i < length; i++ ) {        if( unused_byte == partial_data[i] ) {            unused_byte--;            goto find_unused_byte;        }    }    /* Copy and fill the rest of the buffer with the unused byte */    memset( temporary, unused_byte, data_length );    MEMCPY( temporary + start_position, partial_data, (end_position - start_position) );    /* Save the content of the user memory */    MEMCPY( saved_data, real_data, data_length );    /* Then unpack the data into the user memory */    UNPACK_PREDEFINED_DATATYPE( pConvertor, pElem, count_desc,                                temporary_buffer, *user_buffer, data_length );    /* reload the length as it is reset by the macro */    data_length = ompi_ddt_basicDatatypes[pElem->elem.common.type]->size;    /* For every occurence of the unused byte move data from the saved     * buffer back into the user memory.     */    for( i = 0; i < data_length; i++ ) {        if( unused_byte == real_data[i] )            real_data[i] = saved_data[i];    }    return 0;}/* The pack/unpack functions need a cleanup. I have to create a proper interface to access * all basic functionalities, hence using them as basic blocks for all conversion functions. * * But first let's make some global assumptions: * - a datatype (with the flag DT_DATA set) will have the contiguous flags set if and only if *   the data is really contiguous (extent equal with size) * - for the DT_LOOP type the DT_CONTIGUOUS flag set means that the content of the loop is *   contiguous but with a gap in the begining or at the end. * - the DT_CONTIGUOUS flag for the type DT_END_LOOP is meaningless. */int32_tompi_generic_simple_unpack_function( ompi_convertor_t* pConvertor,                                     struct iovec* iov, uint32_t* out_size,                                     size_t* max_data ){    dt_stack_t* pStack;                /* pointer to the position on the stack */    uint32_t pos_desc;                 /* actual position in the description of the derived datatype */    uint32_t count_desc;               /* the number of items already done in the actual pos_desc */    uint16_t type = DT_MAX_PREDEFINED; /* type at current position */    size_t total_unpacked = 0;         /* total size unpacked this time */    dt_elem_desc_t* description;    dt_elem_desc_t* pElem;    const ompi_datatype_t *pData = pConvertor->pDesc;    char *user_memory_base, *packed_buffer;    size_t iov_len_local;    uint32_t iov_count;    DO_DEBUG( opal_output( 0, "ompi_convertor_generic_simple_unpack( %p, {%p, %lu}, %u )\n",                           (void*)pConvertor, iov[0].iov_base, (unsigned long)iov[0].iov_len, *out_size ); );    description = pConvertor->use_desc->desc;    /* For the first step we have to add both displacement to the source. After in the     * main while loop we will set back the source_base to the correct value. This is     * due to the fact that the convertor can stop in the middle of a data with a count     */    pStack = pConvertor->pStack + pConvertor->stack_pos;    pos_desc          = pStack->index;    user_memory_base  = pConvertor->pBaseBuf + pStack->disp;    count_desc        = (uint32_t)pStack->count;    pStack--;    pConvertor->stack_pos--;    pElem = &(description[pos_desc]);     user_memory_base += pStack->disp;    DO_DEBUG( opal_output( 0, "unpack start pos_desc %d count_desc %d disp %ld\n"                           "stack_pos %d pos_desc %d count_desc %d disp %ld\n",                           pos_desc, count_desc, (long)(user_memory_base - pConvertor->pBaseBuf),                           pConvertor->stack_pos, pStack->index, (int)pStack->count, (long)(pStack->disp) ); );    for( iov_count = 0; iov_count < (*out_size); iov_count++ ) {        packed_buffer = iov[iov_count].iov_base;        iov_len_local = iov[iov_count].iov_len;        if( 0 != pConvertor->partial_length ) {            size_t element_length = ompi_ddt_basicDatatypes[pElem->elem.common.type]->size;            size_t missing_length = element_length - pConvertor->partial_length;            assert( pElem->elem.common.flags & DT_FLAG_DATA );            COMPUTE_CSUM( packed_buffer, missing_length, pConvertor );            ompi_unpack_partial_datatype( pConvertor, pElem,                                          packed_buffer,                                          pConvertor->partial_length, element_length,                                          &user_memory_base );            --count_desc;            if( 0 == count_desc ) {                user_memory_base = pConvertor->pBaseBuf + pStack->disp;                pos_desc++;  /* advance to the next data */                UPDATE_INTERNAL_COUNTERS( description, pos_desc, pElem, count_desc );            }            packed_buffer += missing_length;            iov_len_local -= missing_length;            pConvertor->partial_length = 0;  /* nothing more inside */        }        while( 1 ) {            while( pElem->elem.common.flags & DT_FLAG_DATA ) {                /* now here we have a basic datatype */                UNPACK_PREDEFINED_DATATYPE( pConvertor, pElem, count_desc,                                            packed_buffer, user_memory_base, iov_len_local );                if( 0 == count_desc ) {  /* completed */                    user_memory_base = pConvertor->pBaseBuf + pStack->disp;                    pos_desc++;  /* advance to the next data */                    UPDATE_INTERNAL_COUNTERS( description, pos_desc, pElem, count_desc );                    continue;                }                type = pElem->elem.common.type;                assert( type < DT_MAX_PREDEFINED );                if( 0 != iov_len_local ) {                    char* temp = user_memory_base;                    /* We have some partial data here. Let's copy it into the convertor                     * and keep it hot until the next round.                     */                    assert( iov_len_local < ompi_ddt_basicDatatypes[type]->size );                    COMPUTE_CSUM( packed_buffer, iov_len_local, pConvertor );                    ompi_unpack_partial_datatype( pConvertor, pElem,                                                  packed_buffer, 0, iov_len_local,                                                  &temp );                    pConvertor->partial_length = (uint32_t)iov_len_local;                    iov_len_local = 0;                }                goto complete_loop;            }            if( DT_END_LOOP == pElem->elem.common.type ) { /* end of the current loop */                DO_DEBUG( opal_output( 0, "unpack end_loop count %d stack_pos %d pos_desc %d disp %ld space %lu\n",                                       (int)pStack->count, pConvertor->stack_pos, pos_desc,                                      (long)pStack->disp, (unsigned long)iov_len_local ); );                if( --(pStack->count) == 0 ) { /* end of loop */                    if( pConvertor->stack_pos == 0 ) {                        /* Force the conversion to stop by lowering the number of iovecs. */                        *out_size = iov_count;                        goto complete_loop;  /* completed */                    }                    pConvertor->stack_pos--;                    pStack--;                    pos_desc++;                } else {                    pos_desc = pStack->index + 1;                    if( pStack->index == -1 ) {                        pStack->disp += (pData->ub - pData->lb);                    } else {                        assert( DT_LOOP == description[pStack->index].loop.common.type );                        pStack->disp += description[pStack->index].loop.extent;                    }                }                user_memory_base = pConvertor->pBaseBuf + pStack->disp;                UPDATE_INTERNAL_COUNTERS( description, pos_desc, pElem, count_desc );                DO_DEBUG( opal_output( 0, "unpack new_loop count %d stack_pos %d pos_desc %d disp %ld space %lu\n",                                       (int)pStack->count, pConvertor->stack_pos, pos_desc,                                       (long)pStack->disp, (unsigned long)iov_len_local ); );            }            if( DT_LOOP == pElem->elem.common.type ) {                ptrdiff_t local_disp = (ptrdiff_t)user_memory_base;                if( pElem->loop.common.flags & DT_FLAG_CONTIGUOUS ) {                    UNPACK_CONTIGUOUS_LOOP( pConvertor, pElem, count_desc,                                             packed_buffer, user_memory_base, iov_len_local );                    if( 0 == count_desc ) {  /* completed */                        pos_desc += pElem->loop.items + 1;                        goto update_loop_description;                    }                    /* Save the stack with the correct last_count value. */                }                local_disp = (ptrdiff_t)user_memory_base - local_disp;                PUSH_STACK( pStack, pConvertor->stack_pos, pos_desc, DT_LOOP, count_desc,                            pStack->disp + local_disp);                pos_desc++;            update_loop_description:  /* update the current state */                user_memory_base = pConvertor->pBaseBuf + pStack->disp;                UPDATE_INTERNAL_COUNTERS( description, pos_desc, pElem, count_desc );                DDT_DUMP_STACK( pConvertor->pStack, pConvertor->stack_pos, pElem, "advance loop" );                continue;            }        }    complete_loop:        iov[iov_count].iov_len -= iov_len_local;  /* update the amount of valid data */        total_unpacked += iov[iov_count].iov_len;    }    *max_data = total_unpacked;    pConvertor->bConverted += total_unpacked;  /* update the already converted bytes */    *out_size = iov_count;    if( pConvertor->bConverted == pConvertor->remote_size ) {        pConvertor->flags |= CONVERTOR_COMPLETED;        return 1;    }    /* I complete an element, next step I should go to the next one */    PUSH_STACK( pStack, pConvertor->stack_pos, pos_desc, DT_BYTE, count_desc,                user_memory_base - pStack->disp - pConvertor->pBaseBuf );    DO_DEBUG( opal_output( 0, "unpack save stack stack_pos %d pos_desc %d count_desc %d disp %ld\n",                           pConvertor->stack_pos, pStack->index, (int)pStack->count, (long)pStack->disp ); );    return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -