1
1

Smarter computation of the required space for the struct.

This commit was SVN r1090.
Этот коммит содержится в:
George Bosilca 2004-04-27 18:06:07 +00:00
родитель 1fb66840e1
Коммит 434ebd2dfc

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

@ -5,40 +5,49 @@
int lam_ddt_create_struct( int count, int* pBlockLength, long* pDisp, int lam_ddt_create_struct( int count, int* pBlockLength, long* pDisp,
dt_desc_t** pTypes, dt_desc_t** newType ) dt_desc_t** pTypes, dt_desc_t** newType )
{ {
int i; int i;
long disp, endto, lastExtent, lastDisp; long disp, endto, lastExtent, lastDisp;
int lastBlock; int lastBlock;
dt_desc_t *pdt, *lastType; dt_desc_t *pdt, *lastType;
/* if we compute the total number of elements before we can /* if we compute the total number of elements before we can
* avoid increasing the size of the desc array often. * avoid increasing the size of the desc array often.
*/ */
for( disp = 0, i = 0; i < count; i++ ) { for( lastType = pTypes[0], lastBlock = 0, disp = 0, i = 0; i < count; i++ ) {
disp += pTypes[i]->desc.used; if( lastType == pTypes[i] ) {
if( pBlockLength[i] != 1 ) disp += 2; lastBlock += pBlockLength[i];
} } else {
lastType = pTypes[0]; disp += lastType->desc.used;
lastBlock = pBlockLength[0]; if( lastBlock != 1 ) disp += 2;
lastExtent = lastType->ub - lastType->lb; lastType = pTypes[i];
lastDisp = pDisp[0]; lastBlock = pBlockLength[i];
endto = pDisp[0] + lastExtent * lastBlock; }
}
disp += lastType->desc.used;
if( lastBlock != 1 ) disp += 2;
pdt = lam_ddt_create( disp ); lastType = pTypes[0];
lastBlock = pBlockLength[0];
lastExtent = lastType->ub - lastType->lb;
lastDisp = pDisp[0];
endto = pDisp[0] + lastExtent * lastBlock;
for( i = 1; i < count; i++ ) { pdt = lam_ddt_create( disp );
if( (pTypes[i] == lastType) && (pDisp[i] == endto) ) {
lastBlock += pBlockLength[i];
endto = lastDisp + lastBlock * lastExtent;
} else {
lam_ddt_add( pdt, lastType, lastBlock, lastDisp, lastExtent );
lastType = pTypes[i];
lastExtent = lastType->ub - lastType->lb;
lastBlock = pBlockLength[i];
lastDisp = pDisp[i];
endto = lastDisp + lastExtent * lastBlock;
}
}
lam_ddt_add( pdt, lastType, lastBlock, lastDisp, lastExtent );
*newType = pdt; for( i = 1; i < count; i++ ) {
return 0; if( (pTypes[i] == lastType) && (pDisp[i] == endto) ) {
lastBlock += pBlockLength[i];
endto = lastDisp + lastBlock * lastExtent;
} else {
lam_ddt_add( pdt, lastType, lastBlock, lastDisp, lastExtent );
lastType = pTypes[i];
lastExtent = lastType->ub - lastType->lb;
lastBlock = pBlockLength[i];
lastDisp = pDisp[i];
endto = lastDisp + lastExtent * lastBlock;
}
}
lam_ddt_add( pdt, lastType, lastBlock, lastDisp, lastExtent );
*newType = pdt;
return 0;
} }