Remove some memory leaks in the test program. (Thanks valgrind).
This commit was SVN r1096.
Этот коммит содержится в:
родитель
258677c453
Коммит
a82a47a33e
@ -1,6 +1,7 @@
|
||||
/* -*- Mode: C; c-basic-offset:4 ; -*- */
|
||||
|
||||
#include "datatype.h"
|
||||
#include "datatype_internal.h"
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/time.h>
|
||||
@ -116,7 +117,7 @@ int mpich_typeub2( void )
|
||||
}
|
||||
else
|
||||
printf("Example 3.26 type1 correct\n" );
|
||||
|
||||
OBJ_RELEASE( dt2 ); assert( dt2 == NULL );
|
||||
lam_ddt_create_contiguous(2,dt1,&dt2);
|
||||
lam_ddt_type_lb(dt2, &lb); lam_ddt_type_ub(dt2, &ub);
|
||||
lam_ddt_type_extent(dt2,&ex2); lam_ddt_type_size(dt2,&sz2);
|
||||
@ -147,12 +148,9 @@ int mpich_typeub2( void )
|
||||
else
|
||||
printf( "type3 correct\n" );
|
||||
|
||||
OBJ_RELEASE( dt1 );
|
||||
assert( dt1 == NULL );
|
||||
OBJ_RELEASE( dt2 );
|
||||
assert( dt2 == NULL );
|
||||
OBJ_RELEASE( dt3 );
|
||||
assert( dt3 == NULL );
|
||||
OBJ_RELEASE( dt1 ); assert( dt1 == NULL );
|
||||
OBJ_RELEASE( dt2 ); assert( dt2 == NULL );
|
||||
OBJ_RELEASE( dt3 ); assert( dt3 == NULL );
|
||||
return err;
|
||||
}
|
||||
|
||||
@ -177,8 +175,7 @@ int mpich_typeub3( void )
|
||||
lam_ddt_create_struct(3,blocklen,disp, types,&dt1);
|
||||
lam_ddt_commit(&dt1);
|
||||
|
||||
/* This type is the same as in typeub2, and is tested there */
|
||||
|
||||
/* This type is the same as in typeub2, and is tested there */
|
||||
types[0]=dt1; types[1]=dt1;
|
||||
blocklen[0]=1; blocklen[1]=1;
|
||||
disp[0]=-4; disp[1]=7;
|
||||
@ -232,7 +229,6 @@ int mpich_typeub3( void )
|
||||
lam_ddt_type_lb( dt5, &lb ); lam_ddt_type_ub( dt5, &ub );
|
||||
lam_ddt_type_extent( dt5, &ex ); lam_ddt_type_size( dt5, &sz );
|
||||
|
||||
|
||||
if (lb != -3 || ub != 132 || ex != 135) {
|
||||
printf("vector lb %d ub %d extent %d size %d\n", (int)-3, (int)132, (int)135, sz);
|
||||
printf("vector lb %d ub %d extent %d size %d\n", (int)lb, (int)ub, (int)ex, sz);
|
||||
@ -267,15 +263,17 @@ void print_double_mat( size_t N, double* mat )
|
||||
|
||||
int init_random_upper_matrix( size_t N, double* mat )
|
||||
{
|
||||
int i, j;
|
||||
int i, j;
|
||||
|
||||
srand( time(NULL) );
|
||||
for( i = 0; i < N; i++ )
|
||||
for( j = i; j < N; j++ ) {
|
||||
*mat = (double)random();
|
||||
mat++;
|
||||
}
|
||||
return 0;
|
||||
srand( time(NULL) );
|
||||
for( i = 0; i < N; i++ ) {
|
||||
mat += i;
|
||||
for( j = i; j < N; j++ ) {
|
||||
*mat = (double)random();
|
||||
mat++;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int check_diag_matrix( size_t N, double* mat1, double* mat2 )
|
||||
@ -361,7 +359,7 @@ int test_upper( size_t length )
|
||||
init_random_upper_matrix( length, mat1 );
|
||||
mat2 = calloc( length * length, sizeof(double) );
|
||||
|
||||
total_length = length * (length + 1) / 2 * sizeof(double);
|
||||
total_length = length * (length + 1) * ( sizeof(double) / 2);
|
||||
inbuf = (double*)malloc( total_length );
|
||||
ptr = (char*)inbuf;
|
||||
/* copy upper matrix in the array simulating the input buffer */
|
||||
@ -375,8 +373,8 @@ int test_upper( size_t length )
|
||||
lam_convertor_init_for_recv( pConv, 0, pdt, 1, mat2, 0 );
|
||||
|
||||
/* test the automatic destruction pf the data */
|
||||
OBJ_RELEASE( pdt ); assert( pdt == NULL );
|
||||
OBJ_RELEASE( pdt1 ); assert( pdt1 == NULL );
|
||||
lam_ddt_destroy( &pdt ); assert( pdt == NULL );
|
||||
lam_ddt_destroy( &pdt1 ); assert( pdt1 == NULL );
|
||||
|
||||
GET_TIME( start );
|
||||
split_chunk = (length + 1) * sizeof(double);
|
||||
@ -388,6 +386,7 @@ int test_upper( size_t length )
|
||||
lam_convertor_unpack( pConv, &a, 1 );
|
||||
ptr += split_chunk;
|
||||
i -= split_chunk;
|
||||
if( mat2[0] != inbuf[0] ) assert(0);
|
||||
}
|
||||
GET_TIME( end );
|
||||
total_time = ELAPSED_TIME( start, end );
|
||||
@ -398,6 +397,7 @@ int test_upper( size_t length )
|
||||
rc = check_diag_matrix( length, mat1, mat2 );
|
||||
free( mat1 );
|
||||
free( mat2 );
|
||||
OBJ_RELEASE( pConv );
|
||||
return rc;
|
||||
}
|
||||
|
||||
@ -479,51 +479,52 @@ typedef struct {
|
||||
|
||||
dt_desc_t* create_strange_dt( void )
|
||||
{
|
||||
sdata_intern v[2];
|
||||
long displ[3];
|
||||
dt_desc_t* types[3] = { &(basicDatatypes[DT_INT]) };
|
||||
sstrange t[2];
|
||||
int pBlock[3] = {1, 10, 1}, dispi[3];
|
||||
dt_desc_t *pdt, *pdt1, *pdt2, *pdtTemp;
|
||||
sdata_intern v[2];
|
||||
long displ[3];
|
||||
dt_desc_t* types[3] = { &(basicDatatypes[DT_INT]) };
|
||||
sstrange t[2];
|
||||
int pBlock[3] = {1, 10, 1}, dispi[3];
|
||||
dt_desc_t *pdt, *pdt1, *pdt2, *pdtTemp;
|
||||
|
||||
dispi[0] = (int)((char*)&(v[0].i1) - (char*)&(v[0])); /* 0 */
|
||||
dispi[1] = (int)(((char*)(&(v[0].i2)) - (char*)&(v[0])) / sizeof(int)); /* 2 */
|
||||
lam_ddt_create_indexed_block( 2, 1, dispi, &(basicDatatypes[DT_INT]), &pdtTemp );
|
||||
dispi[0] = (int)((char*)&(v[0].i1) - (char*)&(v[0])); /* 0 */
|
||||
dispi[1] = (int)(((char*)(&(v[0].i2)) - (char*)&(v[0])) / sizeof(int)); /* 2 */
|
||||
lam_ddt_create_indexed_block( 2, 1, dispi, &(basicDatatypes[DT_INT]), &pdtTemp );
|
||||
#ifdef USE_RESIZED
|
||||
/* optional */
|
||||
displ[0] = 0;
|
||||
displ[1] = (char*)&(v[1]) - (char*)&(v[0]);
|
||||
lam_ddt_create_resized( pdtTemp, displ[0], displ[1], &pdt1 );
|
||||
OBJ_RELEASE( pdtTemp ); assert( pdtTemp == NULL );
|
||||
/* optional */
|
||||
displ[0] = 0;
|
||||
displ[1] = (char*)&(v[1]) - (char*)&(v[0]);
|
||||
lam_ddt_create_resized( pdtTemp, displ[0], displ[1], &pdt1 );
|
||||
OBJ_RELEASE( pdtTemp ); assert( pdtTemp == NULL );
|
||||
#else
|
||||
pdt1 = pdtTemp;
|
||||
pdt1 = pdtTemp;
|
||||
#endif /* USE_RESIZED */
|
||||
|
||||
types[1] = pdt1;
|
||||
types[2] = &(basicDatatypes[DT_INT]);
|
||||
displ[0] = 0;
|
||||
displ[1] = (long)((char*)&(t[0].v[0]) - (char*)&(t[0]));
|
||||
displ[2] = (long)((char*)&(t[0].last) - (char*)&(t[0]));
|
||||
lam_ddt_create_struct( 3, pBlock, displ, types, &pdtTemp );
|
||||
types[1] = pdt1;
|
||||
types[2] = &(basicDatatypes[DT_INT]);
|
||||
displ[0] = 0;
|
||||
displ[1] = (long)((char*)&(t[0].v[0]) - (char*)&(t[0]));
|
||||
displ[2] = (long)((char*)&(t[0].last) - (char*)&(t[0]));
|
||||
lam_ddt_create_struct( 3, pBlock, displ, types, &pdtTemp );
|
||||
#ifdef USE_RESIZED
|
||||
/* optional */
|
||||
displ[1] = (char*)&(t[1]) - (char*)&(t[0]);
|
||||
lam_ddt_create_resized( pdtTemp, displ[0], displ[1], &pdt2 );
|
||||
OBJ_RELEASE( pdtTemp ); assert( pdtTemp == NULL );
|
||||
/* optional */
|
||||
displ[1] = (char*)&(t[1]) - (char*)&(t[0]);
|
||||
lam_ddt_create_resized( pdtTemp, displ[0], displ[1], &pdt2 );
|
||||
OBJ_RELEASE( pdtTemp ); assert( pdtTemp == NULL );
|
||||
#else
|
||||
pdt2 = pdtTemp;
|
||||
pdt2 = pdtTemp;
|
||||
#endif /* USE_RESIZED */
|
||||
|
||||
lam_ddt_create_contiguous( SSTRANGE_CNT, pdt2, &pdt );
|
||||
lam_ddt_create_contiguous( SSTRANGE_CNT, pdt2, &pdt );
|
||||
|
||||
OBJ_RELEASE( pdt1 ); assert( pdt1 == NULL );
|
||||
OBJ_RELEASE( pdt2 ); assert( pdt2 == NULL );
|
||||
lam_ddt_dump( pdt );
|
||||
{
|
||||
dt_type_desc_t pElemDesc;
|
||||
lam_ddt_optimize_short( pdt, 1, &pElemDesc );
|
||||
}
|
||||
return pdt;
|
||||
OBJ_RELEASE( pdt1 ); assert( pdt1 == NULL );
|
||||
OBJ_RELEASE( pdt2 ); assert( pdt2 == NULL );
|
||||
lam_ddt_dump( pdt );
|
||||
{
|
||||
dt_type_desc_t pElemDesc = { 0, 0, NULL };
|
||||
lam_ddt_optimize_short( pdt, 1, &pElemDesc );
|
||||
if( pElemDesc.desc != NULL ) free( pElemDesc.desc );
|
||||
}
|
||||
return pdt;
|
||||
}
|
||||
|
||||
int local_copy_ddt_count( dt_desc_t* pdt, int count )
|
||||
@ -539,8 +540,10 @@ int local_copy_ddt_count( dt_desc_t* pdt, int count )
|
||||
|
||||
lam_ddt_copy_content_same_ddt( pdt, count, pdst, psrc );
|
||||
|
||||
free(pdst );
|
||||
free( pdst );
|
||||
free( psrc );
|
||||
|
||||
OBJ_RELEASE( pdt ); assert( pdt == NULL );
|
||||
return 0;
|
||||
}
|
||||
int main( int argc, char* argv[] )
|
||||
@ -551,17 +554,11 @@ int main( int argc, char* argv[] )
|
||||
lam_ddt_init();
|
||||
|
||||
pdt = create_strange_dt();
|
||||
return 0;
|
||||
/*
|
||||
local_copy_ddt_count(pdt, 10);
|
||||
OBJ_RELEASE( pdt ); assert( pdt == NULL );
|
||||
*/
|
||||
OBJ_RELEASE( pdt ); assert( pdt == NULL );
|
||||
|
||||
pdt = upper_matrix(100);
|
||||
local_copy_ddt_count(pdt, 1);
|
||||
OBJ_RELEASE( pdt ); assert( pdt == NULL );
|
||||
return 0;
|
||||
|
||||
return 0;
|
||||
|
||||
mpich_typeub();
|
||||
mpich_typeub2();
|
||||
@ -607,5 +604,9 @@ int main( int argc, char* argv[] )
|
||||
OBJ_RELEASE( pdt1 ); assert( pdt1 == NULL );
|
||||
OBJ_RELEASE( pdt2 ); assert( pdt2 == NULL );
|
||||
OBJ_RELEASE( pdt3 ); assert( pdt3 == NULL );
|
||||
|
||||
/* clean-ups all data allocations */
|
||||
lam_ddt_finalize();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user