1
1

Nearly a complete rewrite. Not the logic is more clean, and the overall execution time a lot smaller. And I think

I remove all (hmmm almost) bugs.

This commit was SVN r1089.
Этот коммит содержится в:
George Bosilca 2004-04-27 18:04:17 +00:00
родитель 977ef57289
Коммит 1fb66840e1

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

@ -1,281 +1,283 @@
/* -*- Mode: C; c-basic-offset:4 ; -*- */ /* -*- Mode: C; c-basic-offset:4 ; -*- */
#include "lam_config.h" #include "lam_config.h"
#include "datatype.h" #include "datatype.h"
#include "datatype_internal.h" #include "datatype_internal.h"
#ifdef HAVE_ALLOCA_H #ifdef HAVE_ALLOCA_H
#include <alloca.h> #include <alloca.h>
#endif #endif
#include <stdlib.h> #include <stdlib.h>
static inline long GET_LOOP_DISP( dt_elem_desc_t* _pElem ) static inline long GET_LOOP_DISP( dt_elem_desc_t* _pElem )
{ {
while( _pElem->type == DT_LOOP ) ++_pElem; while( _pElem->type == DT_LOOP ) ++_pElem;
return _pElem->disp; return _pElem->disp;
} }
int lam_create_stack_with_pos( lam_convertor_t* pConvertor, int lam_create_stack_with_pos( lam_convertor_t* pConvertor,
int starting_point, int* sizes ); int starting_point, int* sizes );
int lam_create_stack_with_pos_general( lam_convertor_t* pConvertor, int lam_create_stack_with_pos_general( lam_convertor_t* pConvertor,
int starting_point, int* sizes ); int starting_point, int* sizes );
int lam_create_stack_with_pos_general( lam_convertor_t* pConvertor, int lam_create_stack_with_pos_general( lam_convertor_t* pConvertor,
int starting_point, int* sizes ) int starting_point, int* sizes )
{ {
dt_stack_t* pStack; /* pointer to the position on the stack */ dt_stack_t* pStack; /* pointer to the position on the stack */
int pos_desc; /* actual position in the description of the derived datatype */ int pos_desc; /* actual position in the description of the derived datatype */
int type, lastLength = 0; int type, lastLength = 0;
long totalDisp; long totalDisp;
lam_datatype_t* pData = pConvertor->pDesc; lam_datatype_t* pData = pConvertor->pDesc;
int* remoteLength; int* remoteLength;
int loop_length; int loop_length;
int resting_place = starting_point; int resting_place = starting_point;
dt_elem_desc_t* pElems; dt_elem_desc_t* pElems;
if( starting_point == 0 ) { if( starting_point == 0 ) {
pConvertor->stack_pos = 1; pConvertor->stack_pos = 1;
pConvertor->pStack[0].index = 0; pConvertor->pStack[0].index = -1;
pConvertor->pStack[0].count = pConvertor->count; pConvertor->pStack[0].count = pConvertor->count;
pConvertor->pStack[0].disp = 0; pConvertor->pStack[0].disp = 0;
/* first here we should select which data representation will be used for /* first here we should select which data representation will be used for
* this operation: normal one or the optimized version ? */ * this operation: normal one or the optimized version ? */
if( pData->opt_desc.used > 0 ) { if( pData->opt_desc.used > 0 ) {
pElems = pData->opt_desc.desc; pElems = pData->opt_desc.desc;
pConvertor->pStack[0].end_loop = pData->opt_desc.used; pConvertor->pStack[0].end_loop = pData->opt_desc.used;
} else { } else {
pElems = pData->desc.desc; pElems = pData->desc.desc;
pConvertor->pStack[0].end_loop = pData->desc.used; pConvertor->pStack[0].end_loop = pData->desc.used;
} }
pConvertor->pStack[1].index = 0; pConvertor->pStack[1].index = 0;
pConvertor->pStack[1].count = pElems->count; pConvertor->pStack[1].count = pElems->count;
pConvertor->pStack[1].disp = pElems->disp; pConvertor->pStack[1].disp = pElems->disp;
pConvertor->pStack[1].end_loop = pConvertor->pStack[0].end_loop; pConvertor->pStack[1].end_loop = pConvertor->pStack[0].end_loop;
return 0; return 0;
} }
/* if the convertor continue from the last position /* if the convertor continue from the last position
* there is nothing to do. * there is nothing to do.
*/ */
if( pConvertor->bConverted == starting_point ) return 0; if( pConvertor->bConverted == starting_point ) return 0;
remoteLength = (int*)alloca( sizeof(int) * pConvertor->pDesc->btypes[DT_LOOP] ); remoteLength = (int*)alloca( sizeof(int) * pConvertor->pDesc->btypes[DT_LOOP] );
pStack = pConvertor->pStack; pStack = pConvertor->pStack;
pStack->count = pConvertor->count; pStack->count = pConvertor->count;
pStack->index = -1; pStack->index = -1;
pStack->end_loop = pData->desc.used - 1; pStack->end_loop = pData->desc.used;
pStack->disp = 0; pStack->disp = 0;
pos_desc = 0; pos_desc = 0;
remoteLength[0] = 0; /* initial value set to ZERO */ remoteLength[0] = 0; /* initial value set to ZERO */
pConvertor->stack_pos = 0; pConvertor->stack_pos = 0;
pElems = &(pData->desc.desc[pos_desc]); pElems = &(pData->desc.desc[pos_desc]);
next_loop: next_loop:
totalDisp = pStack->disp; totalDisp = pStack->disp;
loop_length = remoteLength[pConvertor->stack_pos]; loop_length = remoteLength[pConvertor->stack_pos];
while( pConvertor->stack_pos >= 0 ) { while( pos_desc < pStack->end_loop ) {
if( pElems->type == DT_END_LOOP ) { /* end of the current loop */ if( pElems->type == DT_END_LOOP ) { /* end of the current loop */
/* now we know the length of the loop. We can compute /* now we know the length of the loop. We can compute
* if the the starting_position will happend in one of the * if the the starting_position will happend in one of the
* iterations of this loop. * iterations of this loop.
*/ */
remoteLength[pConvertor->stack_pos] = loop_length; remoteLength[pConvertor->stack_pos] = loop_length;
if( (loop_length * pStack->count) > resting_place ) { if( (loop_length * pStack->count) > resting_place ) {
/* OK here we stop in this loop. First save the loop /* OK here we stop in this loop. First save the loop
* on the stack, then save the position of the last * on the stack, then save the position of the last
* data */ * data */
int cnt = resting_place / loop_length; int cnt = resting_place / loop_length;
pStack->count -= cnt; pStack->count -= cnt;
resting_place -= cnt * loop_length; resting_place -= cnt * loop_length;
pStack->disp += cnt * pElems->extent; pStack->disp += cnt * pElems->extent;
pConvertor->bConverted += (cnt * loop_length); pConvertor->bConverted += (cnt * loop_length);
goto next_loop; goto next_loop;
} }
/* Not in this loop. Cleanup the stack and advance to the /* Not in this loop. Cleanup the stack and advance to the
* next data description. * next data description.
*/ */
pConvertor->stack_pos--; pConvertor->stack_pos--;
pStack--; pStack--;
pos_desc++; pos_desc++;
pElems++; pElems++;
goto next_loop; goto next_loop;
} }
if( pElems->type == DT_LOOP ) { if( pElems->type == DT_LOOP ) {
remoteLength[pConvertor->stack_pos + 1] = 0; remoteLength[pConvertor->stack_pos + 1] = 0;
totalDisp = pElems->disp; totalDisp = pElems->disp;
PUSH_STACK( pStack, pConvertor->stack_pos, pos_desc, PUSH_STACK( pStack, pConvertor->stack_pos, pos_desc,
pData->desc.desc[pos_desc].count, pData->desc.desc[pos_desc].count,
totalDisp, pos_desc + pElems->disp ); totalDisp, pos_desc + pElems->disp );
pos_desc++; pos_desc++;
pElems++; pElems++;
loop_length = 0; /* starting a new loop */ loop_length = 0; /* starting a new loop */
goto next_loop; goto next_loop;
} }
/* now here we have a basic datatype */ /* now here we have a basic datatype */
type = pElems->type; type = pElems->type;
lastLength = pElems->count * basicDatatypes[type].size; lastLength = pElems->count * basicDatatypes[type].size;
if( resting_place > lastLength ) { if( resting_place > lastLength ) {
resting_place -= lastLength; resting_place -= lastLength;
loop_length += lastLength; loop_length += lastLength;
} else { } else {
int cnt = resting_place / basicDatatypes[type].size; int cnt = resting_place / basicDatatypes[type].size;
resting_place -= cnt * basicDatatypes[type].size; resting_place -= cnt * basicDatatypes[type].size;
PUSH_STACK( pStack, pConvertor->stack_pos, pos_desc, PUSH_STACK( pStack, pConvertor->stack_pos, pos_desc,
pElems->count - cnt, pElems->count - cnt,
totalDisp + pElems->disp + cnt * pElems->extent, totalDisp + pElems->disp + cnt * pElems->extent,
pos_desc ); pos_desc );
pConvertor->bConverted += (starting_point - resting_place); pConvertor->bConverted += (starting_point - resting_place);
return 0; return 0;
} }
pos_desc++; /* advance to the next data */ pos_desc++; /* advance to the next data */
pElems++; pElems++;
} }
return 0; return 0;
} }
/* This function works for homogeneous architectures. As we keep /* This function works for homogeneous architectures. As we keep
* trace of the size inside the loop in the END_LOOP element * trace of the size inside the loop in the END_LOOP element
* we can easily jump directly where we need. It works only * we can easily jump directly where we need. It works only
* because we can split a basic data in the middle if we * because we can split a basic data in the middle if we
* have a optimized representation. * have a optimized representation.
*/ */
int lam_create_stack_with_pos( lam_convertor_t* pConvertor, int lam_create_stack_with_pos( lam_convertor_t* pConvertor,
int starting_point, int* sizes ) int starting_point, int* sizes )
{ {
dt_stack_t* pStack; /* pointer to the position on the stack */ dt_stack_t* pStack; /* pointer to the position on the stack */
int pos_desc; /* actual position in the description of the derived datatype */ int pos_desc; /* actual position in the description of the derived datatype */
int type, lastLength = 0; int type, lastLength = 0;
long totalDisp; long totalDisp;
lam_datatype_t* pData = pConvertor->pDesc; lam_datatype_t* pData = pConvertor->pDesc;
int* remoteLength; int* remoteLength;
int loop_length; int loop_length;
int resting_place = starting_point; int resting_place = starting_point;
dt_elem_desc_t* pElems; dt_elem_desc_t* pElems;
if( starting_point == 0 ) { if( starting_point == 0 ) {
pConvertor->stack_pos = 1; pConvertor->stack_pos = 1;
pConvertor->pStack[0].index = 0; pConvertor->pStack[0].index = -1;
pConvertor->pStack[0].count = pConvertor->count; pConvertor->pStack[0].count = pConvertor->count;
pConvertor->pStack[0].disp = 0; pConvertor->pStack[0].disp = 0;
/* first here we should select which data representation will be used for /* first here we should select which data representation will be used for
* this operation: normal one or the optimized version ? */ * this operation: normal one or the optimized version ? */
if( pData->opt_desc.used > 0 ) { if( pData->opt_desc.used > 0 ) {
pElems = pData->opt_desc.desc; pElems = pData->opt_desc.desc;
pConvertor->pStack[0].end_loop = pData->opt_desc.used; pConvertor->pStack[0].end_loop = pData->opt_desc.used;
} else { } else {
pElems = pData->desc.desc; pElems = pData->desc.desc;
pConvertor->pStack[0].end_loop = pData->desc.used; pConvertor->pStack[0].end_loop = pData->desc.used;
} }
pConvertor->pStack[1].index = 0; pConvertor->pStack[1].index = 0;
pConvertor->pStack[1].count = pElems->count; pConvertor->pStack[1].count = pElems->count;
pConvertor->pStack[1].disp = pElems->disp; if( pElems->flags & DT_FLAG_DATA )
pConvertor->pStack[1].end_loop = pConvertor->pStack[0].end_loop; pConvertor->pStack[1].count *= basicDatatypes[pElems->type].size;
pConvertor->converted = 0; pConvertor->pStack[1].disp = pElems->disp;
pConvertor->bConverted = 0; pConvertor->pStack[1].end_loop = pConvertor->pStack[0].end_loop;
return 0; pConvertor->converted = 0;
} pConvertor->bConverted = 0;
/* if the convertor continue from the last position return 0;
* there is nothing to do. }
*/ /* if the convertor continue from the last position
if( pConvertor->bConverted == starting_point ) return 0; * there is nothing to do.
if( pConvertor->flags & DT_FLAG_CONTIGUOUS ) { */
int cnt; if( pConvertor->bConverted == starting_point ) return 0;
if( pConvertor->flags & DT_FLAG_CONTIGUOUS ) {
cnt = starting_point / pData->size; int cnt;
pConvertor->stack_pos = 1;
pConvertor->pStack[0].index = 0; cnt = starting_point / pData->size;
pConvertor->pStack[0].count = pConvertor->count - cnt; pConvertor->stack_pos = 1;
pConvertor->pStack[0].disp = 0; pConvertor->pStack[0].index = 0;
/* first here we should select which data representation will be used for pConvertor->pStack[0].count = pConvertor->count - cnt;
* this operation: normal one or the optimized version ? */ pConvertor->pStack[0].disp = 0;
if( pData->opt_desc.used > 0 ) { /* first here we should select which data representation will be used for
pElems = pData->opt_desc.desc; * this operation: normal one or the optimized version ? */
pConvertor->pStack[0].end_loop = pData->opt_desc.used; if( pData->opt_desc.used > 0 ) {
} else { pElems = pData->opt_desc.desc;
pElems = pData->desc.desc; pConvertor->pStack[0].end_loop = pData->opt_desc.used;
pConvertor->pStack[0].end_loop = pData->desc.used; } else {
} pElems = pData->desc.desc;
cnt = starting_point - cnt * pData->size; pConvertor->pStack[0].end_loop = pData->desc.used;
pConvertor->pStack[1].index = 0; }
pConvertor->pStack[1].count = pElems->count - cnt; cnt = starting_point - cnt * pData->size;
pConvertor->pStack[1].disp = pElems->disp + cnt; pConvertor->pStack[1].index = 0;
pConvertor->pStack[1].end_loop = pConvertor->pStack[0].end_loop; pConvertor->pStack[1].count = pElems->count - cnt;
pConvertor->bConverted = starting_point; pConvertor->pStack[1].disp = pElems->disp + cnt;
return 0; pConvertor->pStack[1].end_loop = pConvertor->pStack[0].end_loop;
} pConvertor->bConverted = starting_point;
remoteLength = (int*)alloca( sizeof(int) * pConvertor->pDesc->btypes[DT_LOOP] ); return 0;
pStack = pConvertor->pStack; }
pStack->count = pConvertor->count; remoteLength = (int*)alloca( sizeof(int) * pConvertor->pDesc->btypes[DT_LOOP] );
pStack->index = -1; pStack = pConvertor->pStack;
pStack->end_loop = pData->desc.used - 1; pStack->count = pConvertor->count;
pStack->disp = 0; pStack->index = -1;
pos_desc = 0; pStack->end_loop = pData->desc.used;
remoteLength[0] = 0; /* initial value set to ZERO */ pStack->disp = 0;
pConvertor->stack_pos = 0; pos_desc = 0;
pElems = &(pData->desc.desc[pos_desc]); remoteLength[0] = 0; /* initial value set to ZERO */
pConvertor->stack_pos = 0;
next_loop: pElems = &(pData->desc.desc[pos_desc]);
totalDisp = pStack->disp;
loop_length = remoteLength[pConvertor->stack_pos]; next_loop:
while( pos_desc <= pStack->end_loop ) { totalDisp = pStack->disp;
if( pElems->type == DT_END_LOOP ) { /* end of the current loop */ loop_length = remoteLength[pConvertor->stack_pos];
/* now we know the length of the loop. We can compute while( pos_desc < pStack->end_loop ) {
* if the the starting_position will happend in one of the if( pElems->type == DT_END_LOOP ) { /* end of the current loop */
* iterations of this loop. /* now we know the length of the loop. We can compute
*/ * if the the starting_position will happend in one of the
remoteLength[pConvertor->stack_pos] = loop_length; * iterations of this loop.
if( (loop_length * pStack->count) > resting_place ) { */
/* OK here we stop in this loop. First save the loop remoteLength[pConvertor->stack_pos] = loop_length;
* on the stack, then save the position of the last if( (loop_length * pStack->count) > resting_place ) {
* data */ /* OK here we stop in this loop. First save the loop
int cnt = resting_place / loop_length; * on the stack, then save the position of the last
pStack->count -= cnt; * data */
resting_place -= cnt * loop_length; int cnt = resting_place / loop_length;
pStack->disp += cnt * pElems->extent; pStack->count -= cnt;
pConvertor->bConverted += (cnt * loop_length); resting_place -= cnt * loop_length;
goto next_loop; pStack->disp += cnt * pElems->extent;
} pConvertor->bConverted += (cnt * loop_length);
/* Not in this loop. Cleanup the stack and advance to the goto next_loop;
* next data description. }
*/ /* Not in this loop. Cleanup the stack and advance to the
pConvertor->stack_pos--; * next data description.
pStack--; */
pos_desc++; pConvertor->stack_pos--;
pElems++; pStack--;
goto next_loop; pos_desc++;
} pElems++;
if( pElems->type == DT_LOOP ) { goto next_loop;
remoteLength[pConvertor->stack_pos + 1] = 0; }
totalDisp = pElems->disp; if( pElems->type == DT_LOOP ) {
PUSH_STACK( pStack, pConvertor->stack_pos, pos_desc, remoteLength[pConvertor->stack_pos + 1] = 0;
pData->desc.desc[pos_desc].count, totalDisp = pElems->disp;
totalDisp, pos_desc + pElems->disp ); PUSH_STACK( pStack, pConvertor->stack_pos, pos_desc,
pos_desc++; pData->desc.desc[pos_desc].count,
pElems++; totalDisp, pos_desc + pElems->disp );
loop_length = 0; /* starting a new loop */ pos_desc++;
goto next_loop; pElems++;
} loop_length = 0; /* starting a new loop */
/* now here we have a basic datatype */ goto next_loop;
type = pElems->type; }
lastLength = pElems->count * basicDatatypes[type].size; /* now here we have a basic datatype */
if( resting_place > lastLength ) { type = pElems->type;
resting_place -= lastLength; lastLength = pElems->count * basicDatatypes[type].size;
loop_length += lastLength; if( resting_place > lastLength ) {
} else { resting_place -= lastLength;
int cnt = resting_place / basicDatatypes[type].size; loop_length += lastLength;
resting_place -= cnt * basicDatatypes[type].size; } else {
PUSH_STACK( pStack, pConvertor->stack_pos, pos_desc, int cnt = resting_place / basicDatatypes[type].size;
pElems->count - cnt, resting_place -= cnt * basicDatatypes[type].size;
totalDisp + pElems->disp + cnt * pElems->extent, PUSH_STACK( pStack, pConvertor->stack_pos, pos_desc,
pos_desc ); pElems->count - cnt,
pConvertor->bConverted += (starting_point - resting_place); totalDisp + pElems->disp + cnt * pElems->extent,
return 0; pos_desc );
} pConvertor->bConverted += (starting_point - resting_place);
pos_desc++; /* advance to the next data */ return 0;
pElems++; }
} pos_desc++; /* advance to the next data */
pElems++;
return 0; }
}
return 0;
}