1
1

Add a function to allow extraction of the iovec covering

the mmory layout of the convertor.

This commit was SVN r20372.
Этот коммит содержится в:
George Bosilca 2009-01-28 15:40:15 +00:00
родитель 33fc6bc408
Коммит 321ac99814
3 изменённых файлов: 216 добавлений и 3 удалений

Просмотреть файл

@ -3,7 +3,7 @@
# Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
# University Research and Technology
# Corporation. All rights reserved.
# Copyright (c) 2004-2005 The University of Tennessee and The University
# Copyright (c) 2004-2009 The University of Tennessee and The University
# of Tennessee Research Foundation. All rights
# reserved.
# Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
@ -56,7 +56,7 @@ libdatatype_la_SOURCES = \
dt_copy.c \
dt_external32.c \
dt_match_size.c \
convertor.c position.c \
convertor.c convertor_raw.c position.c \
copy_functions.c \
copy_functions_heterogeneous.c \
dt_get_count.c

Просмотреть файл

@ -3,7 +3,7 @@
* Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2006 The University of Tennessee and The University
* Copyright (c) 2004-2009 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2006 High Performance Computing Center Stuttgart,
@ -256,6 +256,15 @@ ompi_convertor_copy_and_prepare_for_recv( const ompi_convertor_t* pSrcConv,
return ompi_convertor_prepare_for_recv( convertor, datatype, count, pUserBuf );
}
/*
* Give access to the raw memory layout based on the datatype.
*/
OMPI_DECLSPEC int32_t
ompi_convertor_raw( ompi_convertor_t* convertor, /* [IN/OUT] */
struct iovec* iov, /* [IN/OUT] */
uint32_t* iov_count, /* [IN/OUT] */
size_t* length ); /* [OUT] */
/*
* Upper level does not need to call the _nocheck function directly.
*/

204
ompi/datatype/convertor_raw.c Обычный файл
Просмотреть файл

@ -0,0 +1,204 @@
/* -*- Mode: C; c-basic-offset:4 ; -*- */
/*
* Copyright (c) 2004-2009 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "ompi_config.h"
#include "ompi/datatype/convertor_internal.h"
#include "ompi/datatype/datatype_internal.h"
#if OMPI_ENABLE_DEBUG
extern int ompi_pack_debug;
#define DO_DEBUG(INST) if( ompi_pack_debug ) { INST }
#else
#define DO_DEBUG(INST)
#endif /* OMPI_ENABLE_DEBUG */
#include "ompi/datatype/datatype_pack.h"
/**
* This function always work in local representation. This means no representation
* conversion (i.e. no heterogeneity) has to be taken into account, and that all
* length we're working on are local.
*/
int32_t
ompi_convertor_raw( ompi_convertor_t* pConvertor,
struct iovec* iov, uint32_t* iov_count,
size_t* length )
{
const ompi_datatype_t *pData = pConvertor->pDesc;
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 */
dt_elem_desc_t* description, *pElem;
unsigned char *source_base; /* origin of the data */
size_t raw_data = 0; /* sum of raw data lengths in the iov_len fields */
uint32_t index = 0, i; /* the iov index and a simple counter */
assert( (*iov_count) > 0 );
if( OPAL_LIKELY(pConvertor->flags & CONVERTOR_NO_OP) ) {
/* The convertor contain minimal informations, we only use the bConverted
* to manage the conversion. This function work even after the convertor
* was moved to a specific position.
*/
ompi_convertor_get_current_pointer( pConvertor, (void**)&iov[0].iov_base );
iov[0].iov_len = pConvertor->local_size - pConvertor->bConverted;
*length = iov[0].iov_len;
pConvertor->bConverted = pConvertor->local_size;
pConvertor->flags |= CONVERTOR_COMPLETED;
*iov_count = 1;
return 1; /* we're done */
}
DO_DEBUG( opal_output( 0, "ompi_convertor_raw( %p, {%p, %lu}, %p )\n", (void*)pConvertor,
iov, *iov_count, *length ); );
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;
source_base = pConvertor->pBaseBuf + pStack->disp;
count_desc = (uint32_t)pStack->count;
pStack--;
pConvertor->stack_pos--;
pElem = &(description[pos_desc]);
source_base += pStack->disp;
DO_DEBUG( opal_output( 0, "raw 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)(source_base - pConvertor->pBaseBuf),
pConvertor->stack_pos, pStack->index, (int)pStack->count, (long)pStack->disp ); );
while( 1 ) {
while( pElem->elem.common.flags & DT_FLAG_DATA ) {
size_t blength = ompi_ddt_basicDatatypes[pElem->elem.common.type]->size;
source_base += pElem->elem.disp;
if( blength == pElem->elem.extent ) { /* no resized data */
blength *= count_desc;
/* now here we have a basic datatype */
OMPI_DDT_SAFEGUARD_POINTER( source_base, blength, pConvertor->pBaseBuf,
pConvertor->pDesc, pConvertor->count );
DO_DEBUG( opal_output( 0, "raw 1. iov[%d] = {base %p, length %lu}\n",
index, source_base, (unsigned long)blength ); );
iov[index].iov_base = source_base;
iov[index].iov_len = blength;
source_base += blength;
raw_data += blength;
index++;
} else {
for( i = count_desc; (i > 0) && (index < *iov_count); i--, index++ ) {
OMPI_DDT_SAFEGUARD_POINTER( source_base, blength, pConvertor->pBaseBuf,
pConvertor->pDesc, pConvertor->count );
DO_DEBUG( opal_output( 0, "raw 2. iov[%d] = {base %p, length %lu}\n",
index, source_base, (unsigned long)blength ); );
iov[index].iov_base = source_base;
iov[index].iov_len = blength;
source_base += blength;
raw_data += blength;
count_desc--;
}
}
source_base -= pElem->elem.disp;
if( 0 == count_desc ) { /* completed */
source_base = pConvertor->pBaseBuf + pStack->disp;
pos_desc++; /* advance to the next data */
UPDATE_INTERNAL_COUNTERS( description, pos_desc, pElem, count_desc );
continue;
}
goto complete_loop;
}
if( DT_END_LOOP == pElem->elem.common.type ) { /* end of the current loop */
DO_DEBUG( opal_output( 0, "raw 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)raw_data ); );
if( --(pStack->count) == 0 ) { /* end of loop */
if( pConvertor->stack_pos == 0 ) {
/* we lie about the size of the next element in order to
* make sure we exit the main loop.
*/
*iov_count = index;
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;
}
}
source_base = pConvertor->pBaseBuf + pStack->disp;
UPDATE_INTERNAL_COUNTERS( description, pos_desc, pElem, count_desc );
DO_DEBUG( opal_output( 0, "raw 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)raw_data ); );
}
if( DT_LOOP == pElem->elem.common.type ) {
ptrdiff_t local_disp = (ptrdiff_t)source_base;
ddt_endloop_desc_t* end_loop = (ddt_endloop_desc_t*)(pElem + pElem->loop.items);
if( pElem->loop.common.flags & DT_FLAG_CONTIGUOUS ) {
uint32_t i;
source_base += end_loop->first_elem_disp;
for( i = count_desc; (i > 0) && (index < *iov_count); i--, index++ ) {
OMPI_DDT_SAFEGUARD_POINTER( source_base, end_loop->size, pConvertor->pBaseBuf,
pConvertor->pDesc, pConvertor->count );
iov[index].iov_base = source_base;
iov[index].iov_len = end_loop->size;
source_base += pElem->loop.extent;
raw_data += end_loop->size;
count_desc--;
}
source_base -= end_loop->first_elem_disp;
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)source_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 */
source_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:
pConvertor->bConverted += raw_data; /* update the already converted bytes */
*length = raw_data;
*iov_count = index;
if( pConvertor->bConverted == pConvertor->local_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,
source_base - pStack->disp - pConvertor->pBaseBuf );
DO_DEBUG( opal_output( 0, "raw 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;
}