[cig-commits] r4323 - in long/3D/Gale/trunk/src/StGermain: .
Base/Container/src
walter at geodynamics.org
walter at geodynamics.org
Thu Aug 17 17:17:03 PDT 2006
Author: walter
Date: 2006-08-17 17:17:02 -0700 (Thu, 17 Aug 2006)
New Revision: 4323
Added:
long/3D/Gale/trunk/src/StGermain/Base/Container/src/MPIRoutines.c
long/3D/Gale/trunk/src/StGermain/Base/Container/src/MPIRoutines.h
long/3D/Gale/trunk/src/StGermain/Base/Container/src/UIntMap.c
long/3D/Gale/trunk/src/StGermain/Base/Container/src/UIntMap.h
Modified:
long/3D/Gale/trunk/src/StGermain/
long/3D/Gale/trunk/src/StGermain/Base/Container/src/Container.h
long/3D/Gale/trunk/src/StGermain/Base/Container/src/types.h
Log:
r2701 at earth: boo | 2006-08-17 17:14:16 -0700
r2655 at earth (orig r3736): LukeHodkinson | 2006-08-01 21:40:17 -0700
* Adding a set of utilities for simplifying some MPI
operations involving arrays. These allow 'gathering',
'gathering to all' and 'all to all' operations to be
performed on arbitrary length arrays without the need
to construct the displacement, offset and size arrays
typically required by MPI. Included in this is a couple
of array conversion routines for moving between one and
two dimensionally packed arrays.
* Adding a class for mapping unsigned integers to
unsigned integers. Internally a binary tree is used
to represent the map.
Property changes on: long/3D/Gale/trunk/src/StGermain
___________________________________________________________________
Name: svk:merge
- 1ef209d2-b310-0410-a72d-e20c9eb0015c:/cig:2700
afb6c753-b9d0-0310-b4e7-dbd8d91cdd35:/trunk/StGermain:3735
+ 1ef209d2-b310-0410-a72d-e20c9eb0015c:/cig:2701
afb6c753-b9d0-0310-b4e7-dbd8d91cdd35:/trunk/StGermain:3736
Modified: long/3D/Gale/trunk/src/StGermain/Base/Container/src/Container.h
===================================================================
--- long/3D/Gale/trunk/src/StGermain/Base/Container/src/Container.h 2006-08-18 00:16:57 UTC (rev 4322)
+++ long/3D/Gale/trunk/src/StGermain/Base/Container/src/Container.h 2006-08-18 00:17:02 UTC (rev 4323)
@@ -62,6 +62,8 @@
#include "Map.h"
#include "Heap.h"
#include "MaxHeap.h"
+ #include "MPIRoutines.h"
+ #include "UIntMap.h"
#include "Init.h"
#include "Finalise.h"
Added: long/3D/Gale/trunk/src/StGermain/Base/Container/src/MPIRoutines.c
===================================================================
--- long/3D/Gale/trunk/src/StGermain/Base/Container/src/MPIRoutines.c 2006-08-18 00:16:57 UTC (rev 4322)
+++ long/3D/Gale/trunk/src/StGermain/Base/Container/src/MPIRoutines.c 2006-08-18 00:17:02 UTC (rev 4323)
@@ -0,0 +1,316 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+** Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+** Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+** Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+** Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+** Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+** Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+** This library is free software; you can redistribute it and/or
+** modify it under the terms of the GNU Lesser General Public
+** License as published by the Free Software Foundation; either
+** version 2.1 of the License, or (at your option) any later version.
+**
+** This library is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+** Lesser General Public License for more details.
+**
+** You should have received a copy of the GNU Lesser General Public
+** License along with this library; if not, write to the Free Software
+** Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+**
+** $Id: MPIRoutines.c 2276 2004-11-04 02:01:18Z AlanLo $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <mpi.h>
+
+#include "Base/Foundation/Foundation.h"
+
+#include "types.h"
+#include "MPIRoutines.h"
+
+void MPIArray_Gather( unsigned arraySize, void* array,
+ unsigned** dstSizes, void** dstArray,
+ size_t itemSize, unsigned root, MPI_Comm comm )
+{
+ unsigned nProcs;
+ unsigned rank;
+ unsigned* tmpSizes;
+ unsigned* disps;
+ unsigned netSize;
+ unsigned p_i;
+
+ /* Get basic MPI info. */
+ MPI_Comm_size( comm, (int*)&nProcs );
+ MPI_Comm_rank( comm, (int*)&rank );
+
+ /*
+ ** Send a 1D array of arbitrary length to root process in supplied communicator. This means we also
+ ** need to receive arrays of arbitrary length from all others. As the array from this proc is already stored
+ ** elsewhere we will remove it from the received array, setting its length to zero.
+ */
+ if( rank == root )
+ *dstSizes = Memory_Alloc_Array_Unnamed( unsigned, nProcs );
+ else
+ *dstSizes = NULL;
+ MPI_Gather( &arraySize, 1, MPI_UNSIGNED, *dstSizes, 1, MPI_UNSIGNED, root, comm );
+
+ /* Factor in 'itemSize'. */
+ if( rank == root ) {
+ tmpSizes = Memory_Alloc_Array_Unnamed( unsigned, nProcs );
+ for( p_i = 0; p_i < nProcs; p_i++ )
+ tmpSizes[p_i] = (*dstSizes)[p_i] * itemSize;
+
+ /* Allocate space for the coming arrays and build a displacement list. */
+ disps = Memory_Alloc_Array_Unnamed( unsigned, nProcs );
+ disps[0] = 0;
+ netSize = (*dstSizes)[0];
+ for( p_i = 1; p_i < nProcs; p_i++ ) {
+ disps[p_i] = disps[p_i - 1] + tmpSizes[p_i - 1];
+ netSize += (*dstSizes)[p_i];
+ }
+
+ if( netSize )
+ *dstArray = Memory_Alloc_Array_Bytes_Unnamed( itemSize, netSize, "unknown" );
+ else
+ *dstArray = NULL;
+ }
+ else {
+ *dstArray = NULL;
+ tmpSizes = NULL;
+ disps = NULL;
+ }
+
+ /* Send/receive array/s. */
+ MPI_Gatherv( array, arraySize * itemSize, MPI_BYTE,
+ *dstArray, (int*)tmpSizes, (int*)disps, MPI_BYTE,
+ root, comm );
+
+ /* Free the displacements and temporary-sizes. */
+ FreeArray( disps );
+ FreeArray( tmpSizes );
+}
+
+void MPIArray_Allgather( unsigned arraySize, void* array,
+ unsigned** dstSizes, void*** dstArrays,
+ size_t itemSize, MPI_Comm comm )
+{
+ unsigned nProcs;
+ unsigned rank;
+ unsigned* tmpSizes;
+ void* tmpArray1D;
+ unsigned* disps;
+ unsigned netSize;
+ unsigned p_i;
+
+ /* Get basic MPI info. */
+ MPI_Comm_size( comm, (int*)&nProcs );
+ MPI_Comm_rank( comm, (int*)&rank );
+
+ /*
+ ** Send a 1D array of arbitrary length to all other processes in the supplied communicator. This means we also
+ ** need to receive arrays of arbitrary length from all others. As the array from this proc is already stored
+ ** elsewhere we will remove it from the received array, setting its length to zero.
+ */
+ *dstSizes = Memory_Alloc_Array_Unnamed( unsigned, nProcs );
+ MPI_Allgather( &arraySize, 1, MPI_UNSIGNED, *dstSizes, 1, MPI_UNSIGNED, comm );
+
+ /* Factor in 'itemSize'. */
+ tmpSizes = Memory_Alloc_Array_Unnamed( unsigned, nProcs );
+ for( p_i = 0; p_i < nProcs; p_i++ )
+ tmpSizes[p_i] = (*dstSizes)[p_i] * itemSize;
+
+ /* Allocate space for the coming arrays and build a displacement list. */
+ disps = Memory_Alloc_Array_Unnamed( unsigned, nProcs );
+ disps[0] = 0;
+ netSize = (*dstSizes)[0];
+ for( p_i = 1; p_i < nProcs; p_i++ ) {
+ disps[p_i] = disps[p_i - 1] + tmpSizes[p_i - 1];
+ netSize += (*dstSizes)[p_i];
+ }
+
+ if( netSize )
+ tmpArray1D = Memory_Alloc_Array_Bytes_Unnamed( itemSize, netSize, "unknown" );
+ else
+ tmpArray1D = NULL;
+
+ /* Send/receive array/s. */
+ MPI_Allgatherv( array, arraySize * itemSize, MPI_BYTE,
+ tmpArray1D, (int*)tmpSizes, (int*)disps,
+ MPI_BYTE, comm );
+
+ /* Free the displacements and temp-sizes. */
+ FreeArray( disps );
+ FreeArray( tmpSizes );
+
+ /* Unpack the 1D array into the 2D destination. */
+ Array_1DTo2D( nProcs, *dstSizes, tmpArray1D, dstArrays, sizeof(unsigned) );
+
+ /* Free resources. */
+ FreeArray( tmpArray1D );
+}
+
+void MPIArray2D_Alltoall( unsigned* arraySizes, void** arrays,
+ unsigned** dstSizes, void*** dstArrays,
+ size_t itemSize, MPI_Comm comm )
+{
+ unsigned nProcs;
+ unsigned rank;
+ unsigned* tmpDstSizes;
+ unsigned* tmpDstArray1D;
+ unsigned* dstDisps;
+ unsigned netSize;
+ unsigned* tmpSizes;
+ void* tmpSrcArray1D;
+ unsigned* disps;
+ unsigned p_i;
+
+ /* Get basic MPI info. */
+ MPI_Comm_size( comm, (int*)&nProcs );
+ MPI_Comm_rank( comm, (int*)&rank );
+
+ /*
+ ** Blah, blah, sick of comments.
+ */
+ *dstSizes = Memory_Alloc_Array_Unnamed( unsigned, nProcs );
+ MPI_Alltoall( arraySizes, 1, MPI_UNSIGNED, *dstSizes, 1, MPI_UNSIGNED, comm );
+
+ /* Copy sizes into a new array and modify to include 'itemSize'. */
+ tmpDstSizes = Memory_Alloc_Array_Unnamed( unsigned, nProcs );
+ for( p_i = 0; p_i < nProcs; p_i++ )
+ tmpDstSizes[p_i] = (*dstSizes)[p_i] * itemSize;
+
+ /* Allocate space for the coming arrays and build a displacement list. */
+ dstDisps = Memory_Alloc_Array_Unnamed( unsigned, nProcs );
+ dstDisps[0] = 0;
+ netSize = (*dstSizes)[0];
+ for( p_i = 1; p_i < nProcs; p_i++ ) {
+ dstDisps[p_i] = dstDisps[p_i - 1] + tmpDstSizes[p_i - 1];
+ netSize += (*dstSizes)[p_i];
+ }
+
+ if( netSize )
+ tmpDstArray1D = Memory_Alloc_Array_Bytes_Unnamed( itemSize, netSize, "unknown" );
+ else
+ tmpDstArray1D = NULL;
+
+ /* Pack the supplied 2D array into a 1D array and send/receive. */
+ Array_2DTo1D( nProcs, arraySizes, arrays, &tmpSrcArray1D, sizeof(unsigned), &disps );
+
+ /* Generate a temporary set of sizes to include 'itemSize'. Modify 'dists' while we're at it. */
+ tmpSizes = Memory_Alloc_Array_Unnamed( unsigned, nProcs );
+ for( p_i = 0; p_i < nProcs; p_i++ ) {
+ disps[p_i] *= itemSize;
+ tmpSizes[p_i] = arraySizes[p_i] * itemSize;
+ }
+
+ /* Send/recv. */
+ MPI_Alltoallv( tmpSrcArray1D, (int*)tmpSizes, (int*)disps, MPI_BYTE,
+ tmpDstArray1D, (int*)tmpDstSizes, (int*)dstDisps, MPI_BYTE,
+ comm );
+
+ /* Free memory. */
+ FreeArray( tmpSizes );
+ FreeArray( disps );
+ FreeArray( dstDisps );
+ FreeArray( tmpDstSizes );
+ FreeArray( tmpSrcArray1D );
+
+ /* Unpack the 1D array into the 2D destination. */
+ Array_1DTo2D( nProcs, *dstSizes, tmpDstArray1D, dstArrays, sizeof(unsigned) );
+
+ /* Free resources. */
+ FreeArray( tmpDstArray1D );
+}
+
+void Array_1DTo2D( unsigned nBlocks, unsigned* sizes, void* srcArray,
+ void*** dstArrays, size_t itemSize )
+{
+ if( nBlocks == 0 ) {
+ *dstArrays = NULL;
+ return;
+ }
+
+ /*
+ ** Dump a 1D array of definite block sizes into a 2D equivalent for easy access.
+ */
+
+ {
+ void** tmp;
+ unsigned curPos = 0;
+ unsigned block_i;
+
+ tmp = Memory_Alloc_Array_Unnamed( void*, nBlocks );
+ for( block_i = 0; block_i < nBlocks; block_i++ ) {
+ if( sizes[block_i] == 0 ) {
+ tmp[block_i] = NULL;
+ continue;
+ }
+
+ tmp[block_i] = Memory_Alloc_Array( unsigned char, sizes[block_i] * itemSize, "" );
+ memcpy( tmp[block_i], (unsigned char*)srcArray + curPos * itemSize, itemSize * sizes[block_i] );
+ curPos += sizes[block_i];
+ }
+
+ *dstArrays = tmp;
+ }
+}
+
+void Array_2DTo1D( unsigned nBlocks, unsigned* sizes, void** srcArrays,
+ void** dstArray, size_t itemSize, unsigned** disps )
+{
+ if( nBlocks == 0 ) {
+ dstArray = NULL;
+ disps = NULL;
+ return;
+ }
+
+ /*
+ ** Dump a 2D array into a 1D array and build a displacement array to accompany it.
+ */
+
+ {
+ unsigned netSize;
+ unsigned block_i;
+ unsigned* tmpDisps;
+
+ tmpDisps = Memory_Alloc_Array_Unnamed( unsigned, nBlocks );
+
+ tmpDisps[0] = 0;
+ netSize = sizes[0];
+ for( block_i = 1; block_i < nBlocks; block_i++ ) {
+ tmpDisps[block_i] = tmpDisps[block_i - 1] + sizes[block_i - 1];
+ netSize += sizes[block_i];
+ }
+
+ if( netSize > 0 ) {
+ void* tmpArray;
+ char* dest;
+
+ tmpArray = Memory_Alloc_Array_Bytes_Unnamed( itemSize, netSize, "unknown" );
+
+ for( block_i = 0; block_i < nBlocks; block_i++ ) {
+ dest = tmpArray;
+ dest += (tmpDisps[block_i] * itemSize);
+ memcpy( dest, srcArrays[block_i], itemSize * sizes[block_i] );
+ }
+
+ *dstArray = tmpArray;
+ }
+ else {
+ *dstArray = NULL;
+ }
+
+ *disps = tmpDisps;
+ }
+}
Added: long/3D/Gale/trunk/src/StGermain/Base/Container/src/MPIRoutines.h
===================================================================
--- long/3D/Gale/trunk/src/StGermain/Base/Container/src/MPIRoutines.h 2006-08-18 00:16:57 UTC (rev 4322)
+++ long/3D/Gale/trunk/src/StGermain/Base/Container/src/MPIRoutines.h 2006-08-18 00:17:02 UTC (rev 4323)
@@ -0,0 +1,62 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+** Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+** Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+** Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+** Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+** Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+** Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+** This library is free software; you can redistribute it and/or
+** modify it under the terms of the GNU Lesser General Public
+** License as published by the Free Software Foundation; either
+** version 2.1 of the License, or (at your option) any later version.
+**
+** This library is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+** Lesser General Public License for more details.
+**
+** You should have received a copy of the GNU Lesser General Public
+** License along with this library; if not, write to the Free Software
+** Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+/** \file
+** <b>Role:</b>
+** Collection of commonly used functions
+**
+** <b>Assumptions:</b>
+** None
+**
+** <b>Comments:</b>
+** None
+**
+** $Id: MPIRoutines.h 2276 2004-11-04 02:01:18Z AlanLo $
+**
+**/
+
+#ifndef __Base_Foundation_MPIRoutines_h__
+#define __Base_Foundation_MPIRoutines_h__
+
+void MPIArray_Gather( unsigned arraySize, void* array,
+ unsigned** dstSizes, void** dstArray,
+ size_t itemSize, unsigned root, MPI_Comm comm );
+
+void MPIArray_Allgather( unsigned arraySize, void* array,
+ unsigned** dstSizes, void*** dstArrays,
+ size_t itemSize, MPI_Comm comm );
+
+void MPIArray2D_Alltoall( unsigned* arraySizes, void** arrays,
+ unsigned** dstSizes, void*** dstArrays,
+ size_t itemSize, MPI_Comm comm );
+
+void Array_1DTo2D( unsigned nBlocks, unsigned* sizes, void* srcArray,
+ void*** dstArrays, size_t itemSize );
+
+void Array_2DTo1D( unsigned nBlocks, unsigned* sizes, void** srcArrays,
+ void** dstArray, size_t itemSize, unsigned** disps );
+
+#endif /* __Base_Foundation_MPIRoutines_h__ */
Added: long/3D/Gale/trunk/src/StGermain/Base/Container/src/UIntMap.c
===================================================================
--- long/3D/Gale/trunk/src/StGermain/Base/Container/src/UIntMap.c 2006-08-18 00:16:57 UTC (rev 4322)
+++ long/3D/Gale/trunk/src/StGermain/Base/Container/src/UIntMap.c 2006-08-18 00:17:02 UTC (rev 4323)
@@ -0,0 +1,199 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+** Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+** Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+** Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+** Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+** Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+** Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+** This library is free software; you can redistribute it and/or
+** modify it under the terms of the GNU Lesser General Public
+** License as published by the Free Software Foundation; either
+** version 2.1 of the License, or (at your option) any later version.
+**
+** This library is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+** Lesser General Public License for more details.
+**
+** You should have received a copy of the GNU Lesser General Public
+** License along with this library; if not, write to the Free Software
+** Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+**
+** $Id: UIntMap.c 3584 2006-05-16 11:11:07Z PatrickSunter $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <mpi.h>
+
+#include "Base/Foundation/Foundation.h"
+#include "Base/IO/IO.h"
+
+#include "types.h"
+#include "BTreeNode.h"
+#include "BTree.h"
+#include "UIntMap.h"
+
+
+/* Textual name of this class */
+const Type UIntMap_Type = "UIntMap";
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Constructors
+*/
+
+UIntMap* UIntMap_New() {
+ return _UIntMap_New( sizeof(UIntMap),
+ UIntMap_Type,
+ _UIntMap_Delete,
+ _UIntMap_Print,
+ _UIntMap_Copy );
+}
+
+UIntMap* _UIntMap_New( UINTMAP_DEFARGS ) {
+ UIntMap* self;
+
+ /* Allocate memory */
+ assert( sizeOfSelf >= sizeof(UIntMap) );
+ self = (UIntMap*)_Stg_Class_New( STG_CLASS_PASSARGS );
+
+ /* Virtual info */
+
+ /* UIntMap info */
+ _UIntMap_Init( self );
+
+ return self;
+}
+
+void _UIntMap_Init( UIntMap* self ) {
+ self->btree = BTree_New( UIntMap_DataCompare, UIntMap_DataCopy, UIntMap_DataDelete, NULL,
+ BTREE_NO_DUPLICATES );
+}
+
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _UIntMap_Delete( void* generator ) {
+ UIntMap* self = (UIntMap*)generator;
+
+ FreeObject( self->btree );
+
+ /* Delete the parent. */
+ _Stg_Class_Delete( self );
+}
+
+void _UIntMap_Print( void* generator, Stream* stream ) {
+ UIntMap* self = (UIntMap*)generator;
+
+ /* Set the Journal for printing informations */
+ Stream* generatorStream;
+ generatorStream = Journal_Register( InfoStream_Type, "UIntMapStream" );
+
+ /* Print parent */
+ Journal_Printf( stream, "UIntMap (ptr): (%p)\n", self );
+ _Stg_Class_Print( self, stream );
+}
+
+void* _UIntMap_Copy( void* generator, void* destProc_I, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+#if 0
+ UIntMap* self = (UIntMap*)generator;
+ UIntMap* newUIntMap;
+ PtrMap* map = ptrMap;
+ Bool ownMap = False;
+
+ /* Damn me for making copying so difficult... what was I thinking? */
+
+ /* We need to create a map if it doesn't already exist. */
+ if( !map ) {
+ map = PtrMap_New( 10 );
+ ownMap = True;
+ }
+
+ newUIntMap = (UIntMap*)_Mesh_Copy( self, destProc_I, deep, nameExt, map );
+
+ /* Copy the virtual methods here. */
+
+ /* Deep or shallow? */
+ if( deep ) {
+ }
+ else {
+ }
+
+ /* If we own the map, get rid of it here. */
+ if( ownMap ) Stg_Class_Delete( map );
+
+ return (void*)newUIntMap;
+#endif
+
+ return NULL;
+}
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Public Functions
+*/
+
+void UIntMap_Insert( void* map, unsigned key, unsigned val ) {
+ UIntMap* self = (UIntMap*)map;
+ unsigned data[2];
+
+ assert( self );
+
+ data[0] = key;
+ data[1] = val;
+ BTree_InsertNode( self->btree, data, 2 * sizeof(unsigned) );
+ self->size = self->btree->nodeCount;
+}
+
+Bool UIntMap_HasKey( void* map, unsigned key ) {
+ UIntMap* self = (UIntMap*)map;
+ BTreeNode* node;
+
+ assert( self );
+
+ return (BTree_FindNode( self->btree, &key ) != NULL) ? True : False;
+}
+
+unsigned UIntMap_Map( void* map, unsigned key ) {
+ UIntMap* self = (UIntMap*)map;
+ BTreeNode* node;
+
+ assert( self );
+
+ node = BTree_FindNode( self->btree, &key );
+ assert( node );
+
+ return ((unsigned*)node->data)[1];
+}
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Private Functions
+*/
+
+int UIntMap_DataCompare( void* left, void* right ) {
+ if( ((unsigned*)left)[0] > ((unsigned*)right)[0] )
+ return 1;
+ else if( ((unsigned*)left)[0] < ((unsigned*)right)[0] )
+ return -1;
+ else
+ return 0;
+}
+
+void UIntMap_DataCopy( void** dstData, void* data, SizeT size ) {
+ *dstData = malloc( 2 * sizeof(unsigned) );
+ ((unsigned*)(*dstData))[0] = ((unsigned*)data)[0];
+ ((unsigned*)(*dstData))[1] = ((unsigned*)data)[1];
+}
+
+void UIntMap_DataDelete( void* data ) {
+ free( data );
+}
Added: long/3D/Gale/trunk/src/StGermain/Base/Container/src/UIntMap.h
===================================================================
--- long/3D/Gale/trunk/src/StGermain/Base/Container/src/UIntMap.h 2006-08-18 00:16:57 UTC (rev 4322)
+++ long/3D/Gale/trunk/src/StGermain/Base/Container/src/UIntMap.h 2006-08-18 00:17:02 UTC (rev 4323)
@@ -0,0 +1,105 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+** Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+** Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+** Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+** Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+** Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+** Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+** This library is free software; you can redistribute it and/or
+** modify it under the terms of the GNU Lesser General Public
+** License as published by the Free Software Foundation; either
+** version 2.1 of the License, or (at your option) any later version.
+**
+** This library is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+** Lesser General Public License for more details.
+**
+** You should have received a copy of the GNU Lesser General Public
+** License along with this library; if not, write to the Free Software
+** Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+**
+*/
+/** \file
+** Role:
+**
+** Assumptions:
+**
+** Invariants:
+**
+** Comments:
+**
+** $Id: UIntMap.h 3584 2006-05-16 11:11:07Z PatrickSunter $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#ifndef __Base_Container_UIntMap_h__
+#define __Base_Container_UIntMap_h__
+
+ /** Textual name of this class */
+ extern const Type UIntMap_Type;
+
+ /** Virtual function types */
+
+ /** Mesh class contents */
+ #define __UIntMap \
+ /* General info */ \
+ __Stg_Class \
+ \
+ /* Virtual info */ \
+ \
+ /* UIntMap info */ \
+ BTree* btree; \
+ size_t size;
+
+ struct UIntMap { __UIntMap };
+
+ /*--------------------------------------------------------------------------------------------------------------------------
+ ** Constructors
+ */
+
+ #define UINTMAP_DEFARGS \
+ STG_CLASS_DEFARGS
+
+ #define UINTMAP_PASSARGS \
+ STG_CLASS_PASSARGS
+
+ UIntMap* UIntMap_New();
+ UIntMap* _UIntMap_New( UINTMAP_DEFARGS );
+ void _UIntMap_Init( UIntMap* self );
+
+ /*--------------------------------------------------------------------------------------------------------------------------
+ ** Virtual functions
+ */
+
+ void _UIntMap_Delete( void* map );
+ void _UIntMap_Print( void* map, Stream* stream );
+
+ #define UIntMap_Copy( self ) \
+ (Mesh*)Stg_Class_Copy( self, NULL, False, NULL, NULL )
+ #define UIntMap_DeepCopy( self ) \
+ (Mesh*)Stg_Class_Copy( self, NULL, True, NULL, NULL )
+ void* _UIntMap_Copy( void* map, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap );
+
+ /*--------------------------------------------------------------------------------------------------------------------------
+ ** Public functions
+ */
+
+ void UIntMap_Insert( void* map, unsigned key, unsigned val );
+ Bool UIntMap_HasKey( void* map, unsigned key );
+ unsigned UIntMap_Map( void* map, unsigned key );
+
+ /*--------------------------------------------------------------------------------------------------------------------------
+ ** Private Member functions
+ */
+
+ int UIntMap_DataCompare( void* left, void* right );
+ void UIntMap_DataCopy( void** dstData, void* data, SizeT size );
+ void UIntMap_DataDelete( void* data );
+
+#endif /* __Base_Container_UIntMap_h__ */
Modified: long/3D/Gale/trunk/src/StGermain/Base/Container/src/types.h
===================================================================
--- long/3D/Gale/trunk/src/StGermain/Base/Container/src/types.h 2006-08-18 00:16:57 UTC (rev 4322)
+++ long/3D/Gale/trunk/src/StGermain/Base/Container/src/types.h 2006-08-18 00:17:02 UTC (rev 4323)
@@ -63,6 +63,7 @@
typedef struct Map Map;
typedef struct _Heap _Heap;
typedef struct MaxHeap MaxHeap;
+ typedef struct UIntMap UIntMap;
typedef char BitField;
More information about the cig-commits
mailing list