[cig-commits] r4352 - in long/3D/Gale/trunk/src/StGermain: .
Base/Container/src Base/Container/tests
walter at geodynamics.org
walter at geodynamics.org
Thu Aug 17 17:18:05 PDT 2006
Author: walter
Date: 2006-08-17 17:18:04 -0700 (Thu, 17 Aug 2006)
New Revision: 4352
Modified:
long/3D/Gale/trunk/src/StGermain/
long/3D/Gale/trunk/src/StGermain/Base/Container/src/RangeSet.c
long/3D/Gale/trunk/src/StGermain/Base/Container/src/RangeSet.h
long/3D/Gale/trunk/src/StGermain/Base/Container/tests/testRangeSet.0of1.expected
long/3D/Gale/trunk/src/StGermain/Base/Container/tests/testRangeSet.c
Log:
r2721 at earth: boo | 2006-08-17 17:14:28 -0700
r2675 at earth (orig r3756): LukeHodkinson | 2006-08-07 23:25:37 -0700
* Added some interface routines to RangeSet.
* Added an intersection facility to RangeSet,
allowing the intersection of two sets of indices
to be taken.
* Added a pickle/unpickle facility to RangeSet. This
should make transferral between processes easier.
* Updated tests accordingly.
Property changes on: long/3D/Gale/trunk/src/StGermain
___________________________________________________________________
Name: svk:merge
- 1ef209d2-b310-0410-a72d-e20c9eb0015c:/cig:2720
afb6c753-b9d0-0310-b4e7-dbd8d91cdd35:/trunk/StGermain:3755
+ 1ef209d2-b310-0410-a72d-e20c9eb0015c:/cig:2721
afb6c753-b9d0-0310-b4e7-dbd8d91cdd35:/trunk/StGermain:3756
Modified: long/3D/Gale/trunk/src/StGermain/Base/Container/src/RangeSet.c
===================================================================
--- long/3D/Gale/trunk/src/StGermain/Base/Container/src/RangeSet.c 2006-08-18 00:18:02 UTC (rev 4351)
+++ long/3D/Gale/trunk/src/StGermain/Base/Container/src/RangeSet.c 2006-08-18 00:18:04 UTC (rev 4352)
@@ -204,6 +204,60 @@
}
+void RangeSet_Clear( void* rangeSet ) {
+ RangeSet* self = (RangeSet*)rangeSet;
+
+ assert( self );
+
+ RangeSet_Destruct( self );
+}
+
+
+void RangeSet_Intersection( void* rangeSet, RangeSet* rSet ) {
+ RangeSet* self = (RangeSet*)rangeSet;
+ unsigned maxInds;
+ unsigned nInds;
+ unsigned* inds;
+ unsigned r_i;
+
+ assert( self );
+ assert( rSet );
+
+ maxInds = (rSet->nInds > self->nInds) ? rSet->nInds : self->nInds;
+ inds = Memory_Alloc_Array_Unnamed( unsigned, maxInds );
+
+ for( r_i = 0; r_i < self->nRanges; r_i++ ) {
+ RangeSet_Range* range = self->ranges + r_i;
+ unsigned ind_i;
+
+ for( ind_i = range->begin; ind_i < range->end; ind_i += range->step ) {
+ if( RangeSet_HasIndex( rSet, ind_i ) )
+ inds[nInds++] = ind_i;
+ }
+ }
+
+ RangeSet_SetIndices( self, nInds, inds );
+ FreeArray( inds );
+}
+
+
+void RangeSet_Unpickle( void* rangeSet, unsigned nBytes, Byte* bytes ) {
+ RangeSet* self = (RangeSet*)rangeSet;
+
+ assert( self );
+ assert( nBytes >= sizeof(unsigned) );
+ assert( (nBytes - sizeof(unsigned)) % sizeof(RangeSet_Range) == 0 );
+ assert( bytes );
+
+ RangeSet_Destruct( self );
+
+ self->nInds = ((unsigned*)bytes)[0];
+ self->nRanges = (nBytes - sizeof(unsigned)) / sizeof(RangeSet_Range);
+ self->ranges = Memory_Alloc_Array( RangeSet_Range, self->nRanges, "RangeSet::ranges" );
+ memcpy( self->ranges, bytes + sizeof(unsigned), nBytes - sizeof(unsigned) );
+}
+
+
Bool RangeSet_HasIndex( void* rangeSet, unsigned ind ) {
RangeSet* self = (RangeSet*)rangeSet;
unsigned r_i;
@@ -217,12 +271,58 @@
if( !((ind - range->begin) % range->step) )
return True;
}
+ else if( ind < range->begin )
+ break;
}
return False;
}
+unsigned RangeSet_GetNIndices( void* rangeSet ) {
+ RangeSet* self = (RangeSet*)rangeSet;
+
+ assert( self );
+
+ return self->nInds;
+}
+
+
+unsigned RangeSet_GetNRanges( void* rangeSet ) {
+ RangeSet* self = (RangeSet*)rangeSet;
+
+ assert( self );
+
+ return self->nRanges;
+}
+
+
+void RangeSet_GetRange( void* rangeSet, unsigned ind, RangeSet_Range* range ) {
+ RangeSet* self = (RangeSet*)rangeSet;
+
+ assert( self );
+ assert( ind < self->nRanges );
+ assert( range );
+
+ memcpy( range, self->ranges + ind, sizeof(RangeSet_Range) );
+}
+
+
+void RangeSet_Pickle( void* rangeSet, unsigned* nBytes, Byte** bytes ) {
+ RangeSet* self = (RangeSet*)rangeSet;
+
+ assert( self );
+ assert( nBytes );
+ assert( bytes );
+
+ *nBytes = sizeof(unsigned) + self->nRanges * sizeof(RangeSet_Range);
+ *bytes = Memory_Alloc_Array_Unnamed( Byte, *nBytes );
+ ((unsigned*)*bytes)[0] = self->nInds;
+ if( self->nRanges )
+ memcpy( *bytes + sizeof(unsigned), self->ranges, *nBytes - sizeof(unsigned) );
+}
+
+
/*----------------------------------------------------------------------------------------------------------------------------------
** Private Functions
*/
Modified: long/3D/Gale/trunk/src/StGermain/Base/Container/src/RangeSet.h
===================================================================
--- long/3D/Gale/trunk/src/StGermain/Base/Container/src/RangeSet.h 2006-08-18 00:18:02 UTC (rev 4351)
+++ long/3D/Gale/trunk/src/StGermain/Base/Container/src/RangeSet.h 2006-08-18 00:18:04 UTC (rev 4352)
@@ -53,6 +53,8 @@
unsigned step;
} RangeSet_Range;
+ typedef unsigned char Byte;
+
#define __RangeSet \
/* General info */ \
__Stg_Class \
@@ -98,7 +100,15 @@
*/
void RangeSet_SetIndices( void* rangeSet, unsigned nInds, unsigned* inds );
+ void RangeSet_Clear( void* rangeSet );
+ void RangeSet_Intersection( void* rangeSet, RangeSet* rSet );
+ void RangeSet_Unpickle( void* rangeSet, unsigned nBytes, Byte* bytes );
+
Bool RangeSet_HasIndex( void* rangeSet, unsigned ind );
+ unsigned RangeSet_GetNIndices( void* rangeSet );
+ unsigned RangeSet_GetNRanges( void* rangeSet );
+ void RangeSet_GetRange( void* rangeSet, unsigned ind, RangeSet_Range* range );
+ void RangeSet_Pickle( void* rangeSet, unsigned* nBytes, Byte** bytes );
/*--------------------------------------------------------------------------------------------------------------------------
** Private Member functions
Modified: long/3D/Gale/trunk/src/StGermain/Base/Container/tests/testRangeSet.0of1.expected
===================================================================
--- long/3D/Gale/trunk/src/StGermain/Base/Container/tests/testRangeSet.0of1.expected 2006-08-18 00:18:02 UTC (rev 4351)
+++ long/3D/Gale/trunk/src/StGermain/Base/Container/tests/testRangeSet.0of1.expected 2006-08-18 00:18:04 UTC (rev 4352)
@@ -1,3 +1,5 @@
Running test 'construct'... passed
Running test 'set indices'... passed
Running test 'ranges'... passed
+ Running test 'intersection'... passed
+ Running test 'pickle'... passed
Modified: long/3D/Gale/trunk/src/StGermain/Base/Container/tests/testRangeSet.c
===================================================================
--- long/3D/Gale/trunk/src/StGermain/Base/Container/tests/testRangeSet.c 2006-08-18 00:18:02 UTC (rev 4351)
+++ long/3D/Gale/trunk/src/StGermain/Base/Container/tests/testRangeSet.c 2006-08-18 00:18:04 UTC (rev 4352)
@@ -42,6 +42,8 @@
Bool testConstruct( unsigned rank, unsigned nProcs, unsigned watch );
Bool testSetIndices( unsigned rank, unsigned nProcs, unsigned watch );
Bool testRanges( unsigned rank, unsigned nProcs, unsigned watch );
+Bool testIntersection( unsigned rank, unsigned nProcs, unsigned watch );
+Bool testPickle( unsigned rank, unsigned nProcs, unsigned watch );
void runTest( const char* desc, Bool (test)( unsigned, unsigned, unsigned ),
@@ -103,6 +105,8 @@
runTest( "construct", testConstruct, 10, rank, nProcs, watch );
runTest( "set indices", testSetIndices, 10, rank, nProcs, watch );
runTest( "ranges", testRanges, 10, rank, nProcs, watch );
+ runTest( "intersection", testIntersection, 10, rank, nProcs, watch );
+ runTest( "pickle", testPickle, 10, rank, nProcs, watch );
/* Finalise StGermain. */
BaseContainer_Finalise();
@@ -188,3 +192,79 @@
return True;
}
+
+
+Bool testIntersection( unsigned rank, unsigned nProcs, unsigned watch ) {
+ unsigned nInds = 100;
+ unsigned inds[100];
+ RangeSet* set0;
+ RangeSet* set1;
+ unsigned i;
+
+ for( i = 0; i < nInds; i++ )
+ inds[i] = (i/10)*10 + i;
+ set0 = RangeSet_New();
+ RangeSet_SetIndices( set0, nInds, inds );
+
+ for( i = 0; i < nInds; i++ )
+ inds[i] = (i/10)*10 + 100 + i;
+ set1 = RangeSet_New();
+ RangeSet_SetIndices( set1, nInds, inds );
+
+ RangeSet_Intersection( set0, set1 );
+ FreeObject( set1 );
+ if( rank == watch ) {
+ if( RangeSet_GetNIndices( set0 ) != nInds / 2 ||
+ RangeSet_GetNRanges( set0 ) != nInds / 20 )
+ {
+ FreeObject( set0 );
+ return False;
+ }
+ }
+
+ FreeObject( set0 );
+
+ return True;
+}
+
+
+Bool testPickle( unsigned rank, unsigned nProcs, unsigned watch ) {
+ unsigned nInds = 100;
+ unsigned inds[100];
+ RangeSet* set;
+ unsigned nBytes;
+ Byte* bytes;
+ unsigned i;
+
+ for( i = 0; i < nInds; i++ )
+ inds[i] = (i/10)*10 + i;
+ set = RangeSet_New();
+ RangeSet_SetIndices( set, nInds, inds );
+
+ RangeSet_Pickle( set, &nBytes, &bytes );
+ RangeSet_Clear( set );
+ RangeSet_Unpickle( set, nBytes, bytes );
+
+ if( rank == watch ) {
+ if( set->nInds != nInds ||
+ set->nRanges != nInds/10 )
+ {
+ FreeObject( set );
+ return False;
+ }
+
+ for( i = 0; i < nInds; i++ ) {
+ if( set->ranges[i/10].begin != (i/10)*20 ||
+ set->ranges[i/10].end != (i/10)*20 + 10 ||
+ set->ranges[i/10].step != 1 )
+ {
+ FreeObject( set );
+ return False;
+ }
+ }
+ }
+
+ FreeObject( set );
+
+ return True;
+}
More information about the cig-commits
mailing list