[cig-commits] r4826 - in long/3D/Gale/trunk/src/StGermain: .
Discretisation/Mesh/tests
walter at geodynamics.org
walter at geodynamics.org
Wed Oct 11 13:46:15 PDT 2006
Author: walter
Date: 2006-10-11 13:46:14 -0700 (Wed, 11 Oct 2006)
New Revision: 4826
Added:
long/3D/Gale/trunk/src/StGermain/Discretisation/Mesh/tests/testCommTopology.c
long/3D/Gale/trunk/src/StGermain/Discretisation/Mesh/tests/testDecomp_Sync.c
Modified:
long/3D/Gale/trunk/src/StGermain/
long/3D/Gale/trunk/src/StGermain/Discretisation/Mesh/tests/testDecomp.c
Log:
r2883 at earth: boo | 2006-10-11 13:42:30 -0700
r2799 at earth (orig r3787): LukeHodkinson | 2006-09-07 17:09:10 -0700
Modifying/adding tests for new decomposition system.
Property changes on: long/3D/Gale/trunk/src/StGermain
___________________________________________________________________
Name: svk:merge
- 1ef209d2-b310-0410-a72d-e20c9eb0015c:/cig:2882
afb6c753-b9d0-0310-b4e7-dbd8d91cdd35:/trunk/StGermain:3786
+ 1ef209d2-b310-0410-a72d-e20c9eb0015c:/cig:2883
afb6c753-b9d0-0310-b4e7-dbd8d91cdd35:/trunk/StGermain:3787
Added: long/3D/Gale/trunk/src/StGermain/Discretisation/Mesh/tests/testCommTopology.c
===================================================================
--- long/3D/Gale/trunk/src/StGermain/Discretisation/Mesh/tests/testCommTopology.c 2006-10-11 20:46:11 UTC (rev 4825)
+++ long/3D/Gale/trunk/src/StGermain/Discretisation/Mesh/tests/testCommTopology.c 2006-10-11 20:46:14 UTC (rev 4826)
@@ -0,0 +1,176 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** 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: testRangeSet.c 2136 2004-09-30 02:47:13Z PatrickSunter $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <mpi.h>
+
+#include "Base/Base.h"
+#include "Discretisation/Geometry/Geometry.h"
+#include "Discretisation/Mesh/Mesh.h"
+
+
+Bool testConstruct( unsigned rank, unsigned nProcs, unsigned watch ) {
+ CommTopology* topo;
+
+ topo = CommTopology_New( "" );
+ FreeObject( topo );
+
+ return True;
+}
+
+
+Bool testSetComm( unsigned rank, unsigned nProcs, unsigned watch ) {
+ CommTopology* topo;
+
+ topo = CommTopology_New( "" );
+
+ CommTopology_SetComm( topo, MPI_COMM_WORLD );
+ if( rank == watch ) {
+ if( topo->comm != MPI_COMM_WORLD ||
+ topo->nInc != 0 ||
+ topo->inc != NULL )
+ {
+ FreeObject( topo );
+ return False;
+ }
+ }
+
+ FreeObject( topo );
+
+ return True;
+}
+
+
+Bool testIncidence( unsigned rank, unsigned nProcs, unsigned watch ) {
+ CommTopology* topo;
+ unsigned nInc = nProcs - 1;
+ unsigned* inc;
+ unsigned inc_i;
+
+ topo = CommTopology_New( "" );
+
+ if( nInc )
+ inc = Memory_Alloc_Array_Unnamed( unsigned, nInc );
+ else
+ inc = NULL;
+ for( inc_i = 0; inc_i < nInc; inc_i++ )
+ inc[inc_i] = (rank + 1) % nProcs;
+
+ CommTopology_SetIncidence( topo, nInc, inc );
+
+ if( rank == watch ) {
+ if( topo->comm != MPI_COMM_WORLD ||
+ topo->nInc != nInc )
+ {
+ FreeArray( inc );
+ FreeObject( topo );
+ return False;
+ }
+
+ for( inc_i = 0; inc_i < nInc; inc_i++ )
+ if( inc[inc_i] != (rank + 1) % nProcs ) break;
+ if( inc_i < nInc ) {
+ FreeArray( inc );
+ FreeObject( topo );
+ return False;
+ }
+ }
+
+ FreeObject( topo );
+
+ return True;
+}
+
+
+Bool testAllgather( unsigned rank, unsigned nProcs, unsigned watch ) {
+ CommTopology* topo;
+ unsigned nInc = nProcs - 1;
+ unsigned* inc;
+ unsigned inc_i;
+
+ topo = CommTopology_New( "" );
+
+ if( nInc )
+ inc = Memory_Alloc_Array_Unnamed( unsigned, nInc );
+ else
+ inc = NULL;
+ for( inc_i = 0; inc_i < nInc; inc_i++ )
+ inc[inc_i] = (rank + 1) % nProcs;
+
+ CommTopology_SetIncidence( topo, nInc, inc );
+
+ /* TODO */
+
+ FreeObject( topo );
+
+ return True;
+}
+
+
+int main( int argc, char* argv[] ) {
+ TestSuite* suite;
+ unsigned nTests = 4;
+ TestSuite_Test tests[4] = {{"construct", testConstruct},
+ {"set communicator", testSetComm},
+ {"incidence", testIncidence},
+ {"all gather", testAllgather}};
+
+ /* Initialise MPI, get world info. */
+ MPI_Init( &argc, &argv );
+
+ /* Initialise StGermain. */
+ BaseFoundation_Init( &argc, &argv );
+ BaseIO_Init( &argc, &argv );
+ BaseContainer_Init( &argc, &argv );
+
+ /* Create the test suite. */
+ suite = TestSuite_New();
+ TestSuite_SetProcToWatch( suite, (argc >= 2) ? atoi( argv[1] ) : 0 );
+ TestSuite_SetTests( suite, nTests, tests );
+
+ /* Run the tests. */
+ TestSuite_Run( suite );
+
+ /* Destroy test suites. */
+ FreeObject( suite );
+
+ /* Finalise StGermain. */
+ BaseContainer_Finalise();
+ BaseIO_Finalise();
+ BaseFoundation_Finalise();
+
+ /* Close off MPI */
+ MPI_Finalize();
+
+ return MPI_SUCCESS;
+}
Modified: long/3D/Gale/trunk/src/StGermain/Discretisation/Mesh/tests/testDecomp.c
===================================================================
--- long/3D/Gale/trunk/src/StGermain/Discretisation/Mesh/tests/testDecomp.c 2006-10-11 20:46:11 UTC (rev 4825)
+++ long/3D/Gale/trunk/src/StGermain/Discretisation/Mesh/tests/testDecomp.c 2006-10-11 20:46:14 UTC (rev 4826)
@@ -24,591 +24,127 @@
** 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: testDecomp.c 2136 2004-09-30 02:47:13Z PatrickSunter $
+** $Id: testRangeSet.c 2136 2004-09-30 02:47:13Z PatrickSunter $
**
**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <assert.h>
#include <mpi.h>
#include "Base/Base.h"
+#include "Discretisation/Geometry/Geometry.h"
+#include "Discretisation/Mesh/Mesh.h"
-#include "Discretisation/Mesh/types.h"
-#include "Discretisation/Mesh/Decomp.h"
+#define nTests 2
-Bool testSetLocals( unsigned rank, unsigned nProcs, unsigned watch );
-Bool testSetLeased( unsigned rank, unsigned nProcs, unsigned watch );
-Bool testSetRemotes( unsigned rank, unsigned nProcs, unsigned watch );
-Bool testMappings( unsigned rank, unsigned nProcs, unsigned watch );
-Bool testLocals( unsigned rank, unsigned nProcs, unsigned watch );
-Bool testRemotes( unsigned rank, unsigned nProcs, unsigned watch );
-Bool testArrays( unsigned rank, unsigned nProcs, unsigned watch );
-int main( int argc, char* argv[] ) {
- unsigned rank;
- unsigned nProcs;
- unsigned watch;
- Bool result;
-
- /* Initialise MPI, get world info. */
- MPI_Init( &argc, &argv );
- MPI_Comm_size( MPI_COMM_WORLD, (int*)&nProcs );
- MPI_Comm_rank( MPI_COMM_WORLD, (int*)&rank );
-
- /* Initialise StGermain. */
- BaseFoundation_Init( &argc, &argv );
- BaseIO_Init( &argc, &argv );
- BaseContainer_Init( &argc, &argv );
-
- /* Watching a particular processor? */
- watch = (argc >= 2) ? atoi( argv[1] ) : 0;
-
- /* Run some tests. */
- result = testSetLocals( rank, nProcs, watch );
- if( rank == watch )
- printf( "Testing local setting/negotiation... %s\n", result ? "passed" : "failed" );
-
- result = testSetLeased( rank, nProcs, watch );
- if( rank == watch )
- printf( "Testing leased setting/negotiation... %s\n", result ? "passed" : "failed" );
-
- result = testSetRemotes( rank, nProcs, watch );
- if( rank == watch )
- printf( "Testing remotes setting/negotiation... %s\n", result ? "passed" : "failed" );
-
- result = testMappings( rank, nProcs, watch );
- if( rank == watch )
- printf( "Testing mappings... %s\n", result ? "passed" : "failed" );
-
- result = testArrays( rank, nProcs, watch );
- if( rank == watch )
- printf( "Testing arrays... %s\n", result ? "passed" : "failed" );
-
- /* Finalise StGermain. */
- BaseContainer_Finalise();
- BaseIO_Finalise();
- BaseFoundation_Finalise();
-
- /* Close off MPI */
- MPI_Finalize();
-
- return MPI_SUCCESS;
-}
-
-Bool testSetLocals( unsigned rank, unsigned nProcs, unsigned watch ) {
+Bool testLocals( unsigned rank, unsigned nProcs, unsigned watch ) {
Decomp* decomp = Decomp_New( "" );
unsigned nLocals = 100;
unsigned nGlobals = nProcs * nLocals;
unsigned* locals;
- unsigned nReps = 10;
- unsigned l_i, r_i;
+ unsigned l_i;
locals = Memory_Alloc_Array_Unnamed( unsigned, nLocals );
for( l_i = 0; l_i < nLocals; l_i++ )
locals[l_i] = rank * nLocals + l_i;
- Decomp_SetNGlobals( decomp, nGlobals );
- for( r_i = 0; r_i < nReps; r_i++ ) {
- Decomp_SetLocals( decomp, nLocals, locals, 0, NULL );
- if( rank == watch ) {
- for( l_i = 0; l_i < nLocals; l_i++ )
- if( decomp->locals[l_i] != locals[l_i] ) break;
- if( l_i < nLocals ) {
- FreeArray( locals );
- FreeObject( decomp );
- return False;
- }
- }
+ Decomp_SetLocals( decomp, nLocals, locals );
- Decomp_Negotiate( decomp );
- if( rank == watch ) {
- for( l_i = 0; l_i < nLocals; l_i++ )
- if( decomp->locals[l_i] != locals[l_i] ) break;
- if( l_i < nLocals ) {
- FreeArray( locals );
- FreeObject( decomp );
- return False;
- }
- }
+ if( decomp->nGlobals != nGlobals ) {
+ FreeArray( locals );
+ FreeObject( decomp );
+ return False;
}
- FreeArray( locals );
- FreeObject( decomp );
-
- return True;
-}
-
-Bool testSetLeased( unsigned rank, unsigned nProcs, unsigned watch ) {
- Decomp* decomp = Decomp_New( "" );
- unsigned nLocals = 100;
- unsigned nGlobals = nProcs * nLocals;
- unsigned nLeased = 0;
- unsigned* locals;
- unsigned* leased;
- unsigned nReps = 10;
- unsigned l_i, r_i;
-
- locals = Memory_Alloc_Array_Unnamed( unsigned, nLocals );
- leased = Memory_Alloc_Array_Unnamed( unsigned, nLocals );
for( l_i = 0; l_i < nLocals; l_i++ ) {
- locals[l_i] = rank * nLocals + l_i;
-
- if( rank > 0 && l_i >= nLocals / 2 )
- leased[nLeased++] = locals[l_i] - nLocals;
- if( rank < nProcs - 1 && l_i < nLocals / 2 )
- leased[nLeased++] = locals[l_i] + nLocals;
- }
-
- Decomp_SetNGlobals( decomp, nGlobals );
- for( r_i = 0; r_i < nReps; r_i++ ) {
- Decomp_SetLocals( decomp, nLocals, locals, nLeased, leased );
- if( rank == watch ) {
- for( l_i = 0; l_i < nLocals; l_i++ )
- if( decomp->locals[l_i] != locals[l_i] ) break;
- if( l_i < nLocals ) {
- FreeArray( locals );
- FreeArray( leased );
- FreeObject( decomp );
- return False;
- }
-
- for( l_i = 0; l_i < nLeased; l_i++ )
- if( decomp->leased[l_i] != leased[l_i] ) break;
- if( l_i < nLeased ) {
- FreeArray( locals );
- FreeArray( leased );
- FreeObject( decomp );
- return False;
- }
+ if( decomp->locals[l_i] != locals[l_i] ) {
+ FreeArray( locals );
+ FreeObject( decomp );
+ return False;
}
-
- Decomp_Negotiate( decomp );
- if( rank == watch ) {
- for( l_i = 0; l_i < nLocals; l_i++ )
- if( decomp->locals[l_i] != locals[l_i] ) break;
- if( l_i < nLocals ) {
- FreeArray( locals );
- FreeArray( leased );
- FreeObject( decomp );
- return False;
- }
-
- for( l_i = 0; l_i < nLeased; l_i++ )
- if( decomp->leased[l_i] != leased[l_i] ) break;
- if( l_i < nLeased ) {
- FreeArray( locals );
- FreeArray( leased );
- FreeObject( decomp );
- return False;
- }
- }
}
FreeArray( locals );
- FreeArray( leased );
FreeObject( decomp );
return True;
}
-Bool testSetRemotes( unsigned rank, unsigned nProcs, unsigned watch ) {
+Bool testMaps( unsigned rank, unsigned nProcs, unsigned watch ) {
Decomp* decomp = Decomp_New( "" );
unsigned nLocals = 100;
unsigned nGlobals = nProcs * nLocals;
- unsigned nLeased = 0;
- unsigned nRemotes = 0;
unsigned* locals;
- unsigned* leased;
- unsigned* remotes;
- unsigned nReps = 10;
- unsigned success = 0;
- unsigned failure = 1;
- unsigned l_i, r_i, rem_i;
+ unsigned l_i, g_i;
locals = Memory_Alloc_Array_Unnamed( unsigned, nLocals );
- leased = Memory_Alloc_Array_Unnamed( unsigned, nLocals );
- remotes = Memory_Alloc_Array_Unnamed( unsigned, nLocals );
- for( l_i = 0; l_i < nLocals; l_i++ ) {
+ for( l_i = 0; l_i < nLocals; l_i++ )
locals[l_i] = rank * nLocals + l_i;
- if( rank > 0 && l_i >= nLocals / 2 )
- leased[nLeased++] = locals[l_i] - nLocals;
- if( rank < nProcs - 1 && l_i < nLocals / 2 )
- leased[nLeased++] = locals[l_i] + nLocals;
-
- if( rank > 0 && l_i < nLocals / 2 )
- remotes[nRemotes++] = locals[l_i] - nLocals;
- if( rank < nProcs - 1 && l_i >= nLocals / 2 )
- remotes[nRemotes++] = locals[l_i] + nLocals;
- }
-
- Decomp_SetNGlobals( decomp, nGlobals );
- for( r_i = 0; r_i < nReps; r_i++ ) {
- Decomp_SetLocals( decomp, nLocals, locals, nLeased, leased );
- if( rank == watch ) {
- for( l_i = 0; l_i < nLocals; l_i++ )
- if( decomp->locals[l_i] != locals[l_i] ) break;
- if( l_i < nLocals ) {
- FreeArray( locals );
- FreeArray( leased );
- FreeArray( remotes );
- FreeObject( decomp );
- MPI_Bcast( &failure, 1, MPI_UNSIGNED, watch, MPI_COMM_WORLD );
- return False;
- }
-
- for( l_i = 0; l_i < nLeased; l_i++ )
- if( decomp->leased[l_i] != leased[l_i] ) break;
- if( l_i < nLeased ) {
- FreeArray( locals );
- FreeArray( leased );
- FreeArray( remotes );
- FreeObject( decomp );
- MPI_Bcast( &failure, 1, MPI_UNSIGNED, watch, MPI_COMM_WORLD );
- return False;
- }
-
- MPI_Bcast( &success, 1, MPI_UNSIGNED, watch, MPI_COMM_WORLD );
- }
- else {
- unsigned status;
-
- MPI_Bcast( &status, 1, MPI_UNSIGNED, watch, MPI_COMM_WORLD );
- if( status == failure ) break;
- }
-
- Decomp_SetRemotes( decomp, nRemotes, remotes );
- if( rank == watch ) {
- for( l_i = 0; l_i < nLocals; l_i++ )
- if( decomp->locals[l_i] != locals[l_i] ) break;
- if( l_i < nLocals ) {
- FreeArray( locals );
- FreeArray( leased );
- FreeArray( remotes );
- FreeObject( decomp );
- MPI_Bcast( &failure, 1, MPI_UNSIGNED, watch, MPI_COMM_WORLD );
- return False;
- }
-
- for( l_i = 0; l_i < nLeased; l_i++ )
- if( decomp->leased[l_i] != leased[l_i] ) break;
- if( l_i < nLeased ) {
- FreeArray( locals );
- FreeArray( leased );
- FreeArray( remotes );
- FreeObject( decomp );
- MPI_Bcast( &failure, 1, MPI_UNSIGNED, watch, MPI_COMM_WORLD );
- return False;
- }
-
- for( rem_i = 0; rem_i < nRemotes; rem_i++ )
- if( decomp->remotes[rem_i] != remotes[rem_i] ) break;
- if( rem_i < nRemotes ) {
- FreeArray( locals );
- FreeArray( leased );
- FreeArray( remotes );
- FreeObject( decomp );
- MPI_Bcast( &failure, 1, MPI_UNSIGNED, watch, MPI_COMM_WORLD );
- return False;
- }
-
- MPI_Bcast( &success, 1, MPI_UNSIGNED, watch, MPI_COMM_WORLD );
- }
- else {
- unsigned status;
-
- MPI_Bcast( &status, 1, MPI_UNSIGNED, watch, MPI_COMM_WORLD );
- if( status == failure ) break;
- }
-
- Decomp_Negotiate( decomp );
- if( rank == watch ) {
- for( l_i = 0; l_i < nLocals; l_i++ )
- if( decomp->locals[l_i] != locals[l_i] ) break;
- if( l_i < nLocals ) {
- FreeArray( locals );
- FreeArray( leased );
- FreeArray( remotes );
- FreeObject( decomp );
- MPI_Bcast( &failure, 1, MPI_UNSIGNED, watch, MPI_COMM_WORLD );
- return False;
- }
-
- for( l_i = 0; l_i < nLeased; l_i++ )
- if( decomp->leased[l_i] != leased[l_i] ) break;
- if( l_i < nLeased ) {
- FreeArray( locals );
- FreeArray( leased );
- FreeArray( remotes );
- FreeObject( decomp );
- MPI_Bcast( &failure, 1, MPI_UNSIGNED, watch, MPI_COMM_WORLD );
- return False;
- }
-
- for( rem_i = 0; rem_i < nRemotes; rem_i++ )
- if( decomp->remotes[rem_i] != remotes[rem_i] ) break;
- if( rem_i < nRemotes ) {
- FreeArray( locals );
- FreeArray( leased );
- FreeArray( remotes );
- FreeObject( decomp );
- MPI_Bcast( &failure, 1, MPI_UNSIGNED, watch, MPI_COMM_WORLD );
- return False;
- }
-
- MPI_Bcast( &success, 1, MPI_UNSIGNED, watch, MPI_COMM_WORLD );
- }
- else {
- unsigned status;
-
- MPI_Bcast( &status, 1, MPI_UNSIGNED, watch, MPI_COMM_WORLD );
- if( status == failure ) break;
- }
- }
-
+ Decomp_SetLocals( decomp, nLocals, locals );
FreeArray( locals );
- FreeArray( leased );
- FreeArray( remotes );
- FreeObject( decomp );
- return True;
-}
-
-Bool testMappings( unsigned rank, unsigned nProcs, unsigned watch ) {
- Decomp* decomp = Decomp_New( "" );
- unsigned nLocals = 100;
- unsigned nGlobals = nProcs * nLocals;
- unsigned nLeased = 0;
- unsigned nRemotes = 0;
- unsigned* locals;
- unsigned* leased;
- unsigned* remotes;
- unsigned nReps = 10;
- unsigned success = 0;
- unsigned failure = 1;
- unsigned l_i, r_i;
-
- locals = Memory_Alloc_Array_Unnamed( unsigned, nLocals );
- leased = Memory_Alloc_Array_Unnamed( unsigned, nLocals );
- remotes = Memory_Alloc_Array_Unnamed( unsigned, nLocals );
for( l_i = 0; l_i < nLocals; l_i++ ) {
- locals[l_i] = rank * nLocals + l_i;
-
- if( rank > 0 && l_i >= nLocals / 2 )
- leased[nLeased++] = locals[l_i] - nLocals;
- if( rank < nProcs - 1 && l_i < nLocals / 2 )
- leased[nLeased++] = locals[l_i] + nLocals;
-
- if( rank > 0 && l_i < nLocals / 2 )
- remotes[nRemotes++] = locals[l_i] - nLocals;
- if( rank < nProcs - 1 && l_i >= nLocals / 2 )
- remotes[nRemotes++] = locals[l_i] + nLocals;
+ if( !Decomp_IsLocal( decomp, locals[l_i] ) ||
+ Decomp_LocalToGlobal( decomp, l_i ) != locals[l_i] )
+ {
+ FreeObject( decomp );
+ return False;
+ }
}
- for( r_i = 0; r_i < nReps; r_i++ ) {
- Decomp_SetNGlobals( decomp, nGlobals );
- Decomp_SetLocals( decomp, nLocals, locals, nLeased, leased );
- Decomp_SetRemotes( decomp, nRemotes, remotes );
- Decomp_Negotiate( decomp );
+ for( g_i = 0; g_i < nGlobals; g_i++ ) {
+ if( !Decomp_IsLocal( decomp, g_i ) )
+ continue;
- if( rank == watch ) {
- unsigned curLeased = 0;
- unsigned curRemote = 0;
-
- for( l_i = 0; l_i < nLocals; l_i++ ) {
- unsigned global = rank * nLocals + l_i;
-
- if( Decomp_GlobalToDomain( decomp, global ) != l_i ||
- Decomp_DomainToGlobal( decomp, l_i ) != global )
- {
- break;
- }
-
- if( rank > 0 && l_i >= nLocals / 2 &&
- (Decomp_GlobalToDomain( decomp, global - nLocals ) != nLocals + curLeased ||
- Decomp_DomainToGlobal( decomp, nLocals + curLeased++ ) != global - nLocals) )
- {
- break;
- }
- if( rank < nProcs - 1 && l_i < nLocals / 2 &&
- (Decomp_GlobalToDomain( decomp, global + nLocals ) != nLocals + curLeased ||
- Decomp_DomainToGlobal( decomp, nLocals + curLeased++ ) != global + nLocals) )
- {
- break;
- }
-
- if( rank > 0 && l_i < nLocals / 2 &&
- (Decomp_GlobalToDomain( decomp, global - nLocals ) != nLocals + nLeased + curRemote ||
- Decomp_DomainToGlobal( decomp, nLocals + nLeased + curRemote++ ) != global - nLocals) )
- {
- break;
- }
- if( rank < nProcs - 1 && l_i >= nLocals / 2 &&
- (Decomp_GlobalToDomain( decomp, global + nLocals ) != nLocals + nLeased + curRemote ||
- Decomp_DomainToGlobal( decomp, nLocals + nLeased + curRemote++ ) != global + nLocals) )
- {
- break;
- }
- }
- if( l_i < nLocals ) {
- FreeArray( locals );
- FreeArray( leased );
- FreeArray( remotes );
- FreeObject( decomp );
- MPI_Bcast( &failure, 1, MPI_UNSIGNED, watch, MPI_COMM_WORLD );
- return False;
- }
-
- MPI_Bcast( &success, 1, MPI_UNSIGNED, watch, MPI_COMM_WORLD );
+ if( Decomp_GlobalToLocal( decomp, g_i ) != g_i % nLocals ) {
+ FreeObject( decomp );
+ return False;
}
- else {
- unsigned status;
-
- MPI_Bcast( &status, 1, MPI_UNSIGNED, watch, MPI_COMM_WORLD );
- if( status == failure ) break;
- }
}
- FreeArray( locals );
- FreeArray( leased );
- FreeArray( remotes );
FreeObject( decomp );
return True;
}
-typedef struct {
- int one;
- int two;
- int three;
-} aStruct;
-Bool testArrays( unsigned rank, unsigned nProcs, unsigned watch ) {
- Decomp* decomp = Decomp_New( "" );
- unsigned nLocals = 100;
- unsigned nGlobals = nProcs * nLocals;
- unsigned nLeased = 0;
- unsigned nRemotes = 0;
- unsigned* locals;
- unsigned* leased;
- unsigned* remotes;
- unsigned* intLocals;
- aStruct* structLocals;
- unsigned* intShadows;
- aStruct* structShadows;
- unsigned nReps = 10;
- unsigned success = 0;
- unsigned failure = 1;
- unsigned l_i, s_i, r_i;
+int main( int argc, char* argv[] ) {
+ TestSuite* suite;
+ TestSuite_Test tests[nTests] = {{"set locals", testLocals},
+ {"mappings", testMaps}};
- locals = Memory_Alloc_Array_Unnamed( unsigned, nLocals );
- leased = Memory_Alloc_Array_Unnamed( unsigned, nLocals );
- remotes = Memory_Alloc_Array_Unnamed( unsigned, nLocals );
- for( l_i = 0; l_i < nLocals; l_i++ ) {
- locals[l_i] = rank * nLocals + l_i;
+ /* Initialise MPI, get world info. */
+ MPI_Init( &argc, &argv );
- if( rank > 0 && l_i >= nLocals / 2 )
- leased[nLeased++] = locals[l_i] - nLocals;
- if( rank < nProcs - 1 && l_i < nLocals / 2 )
- leased[nLeased++] = locals[l_i] + nLocals;
+ /* Initialise StGermain. */
+ BaseFoundation_Init( &argc, &argv );
+ BaseIO_Init( &argc, &argv );
+ BaseContainer_Init( &argc, &argv );
- if( rank > 0 && l_i < nLocals / 2 )
- remotes[nRemotes++] = locals[l_i] - nLocals;
- if( rank < nProcs - 1 && l_i >= nLocals / 2 )
- remotes[nRemotes++] = locals[l_i] + nLocals;
- }
+ /* Create the test suite. */
+ suite = TestSuite_New();
+ TestSuite_SetProcToWatch( suite, (argc >= 2) ? atoi( argv[1] ) : 0 );
+ TestSuite_SetTests( suite, nTests, tests );
- intLocals = Memory_Alloc_Array_Unnamed( unsigned, nLocals );
- structLocals = Memory_Alloc_Array_Unnamed( aStruct, nLocals );
- intShadows = Memory_Alloc_Array_Unnamed( unsigned, nLeased + nRemotes );
- structShadows = Memory_Alloc_Array_Unnamed( aStruct, nLeased + nRemotes );
- for( l_i = 0; l_i < nLocals; l_i++ ) {
- intLocals[l_i] = rank;
- structLocals[l_i].two = rank;
- }
+ /* Run the tests. */
+ TestSuite_Run( suite );
- for( r_i = 0; r_i < nReps; r_i++ ) {
- Decomp_SetNGlobals( decomp, nGlobals );
- Decomp_SetLocals( decomp, nLocals, locals, nLeased, leased );
- Decomp_SetRemotes( decomp, nRemotes, remotes );
- Decomp_Negotiate( decomp );
- Decomp_AddArray( decomp, intLocals, intShadows, sizeof(int), sizeof(int), sizeof(int) );
- Decomp_AddArray( decomp, &structLocals[0].two, &structShadows[0].two, sizeof(aStruct), sizeof(aStruct),
- sizeof(int) );
+ /* Destroy test suites. */
+ FreeObject( suite );
- for( s_i = 0; s_i < nLeased + nRemotes; s_i++ ) {
- intShadows[s_i] = rank;
- structShadows[s_i].two = rank;
- }
+ /* Finalise StGermain. */
+ BaseContainer_Finalise();
+ BaseIO_Finalise();
+ BaseFoundation_Finalise();
- Decomp_Sync( decomp );
+ /* Close off MPI */
+ MPI_Finalize();
- if( rank == watch ) {
- unsigned curLeased = 0;
- unsigned curRemote = 0;
-
- for( l_i = 0; l_i < nLocals; l_i++ ) {
- if( intLocals[l_i] != rank || structLocals[l_i].two != rank )
- break;
-
- if( rank > 0 && l_i >= nLocals / 2 &&
- (intShadows[curLeased] != rank - 1 || structShadows[curLeased++].two != rank - 1) )
- {
- break;
- }
- if( rank < nProcs - 1 && l_i < nLocals / 2 &&
- (intShadows[curLeased] != rank + 1 || structShadows[curLeased++].two != rank + 1) )
- {
- break;
- }
-
- if( rank > 0 && l_i < nLocals / 2 &&
- (intShadows[nLeased + curRemote] != rank - 1 ||
- structShadows[nLeased + curRemote++].two != rank - 1) )
- {
- break;
- }
- if( rank < nProcs - 1 && l_i >= nLocals / 2 &&
- (intShadows[nLeased + curRemote] != rank + 1 ||
- structShadows[nLeased + curRemote++].two != rank + 1) )
- {
- break;
- }
- }
- if( l_i < nLocals ) {
- FreeArray( locals );
- FreeArray( leased );
- FreeArray( remotes );
- FreeArray( intLocals );
- FreeArray( intShadows );
- FreeArray( structLocals );
- FreeArray( structShadows );
- FreeObject( decomp );
- MPI_Bcast( &failure, 1, MPI_UNSIGNED, watch, MPI_COMM_WORLD );
- return False;
- }
-
- MPI_Bcast( &success, 1, MPI_UNSIGNED, watch, MPI_COMM_WORLD );
- }
- else {
- unsigned status;
-
- MPI_Bcast( &status, 1, MPI_UNSIGNED, watch, MPI_COMM_WORLD );
- if( status == failure ) break;
- }
- }
-
- FreeArray( locals );
- FreeArray( leased );
- FreeArray( remotes );
- FreeArray( intLocals );
- FreeArray( intShadows );
- FreeArray( structLocals );
- FreeArray( structShadows );
- FreeObject( decomp );
-
- return True;
+ return MPI_SUCCESS;
}
Added: long/3D/Gale/trunk/src/StGermain/Discretisation/Mesh/tests/testDecomp_Sync.c
===================================================================
--- long/3D/Gale/trunk/src/StGermain/Discretisation/Mesh/tests/testDecomp_Sync.c 2006-10-11 20:46:11 UTC (rev 4825)
+++ long/3D/Gale/trunk/src/StGermain/Discretisation/Mesh/tests/testDecomp_Sync.c 2006-10-11 20:46:14 UTC (rev 4826)
@@ -0,0 +1,401 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** 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: testDecomp_Sync.c 2136 2004-09-30 02:47:13Z PatrickSunter $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <mpi.h>
+
+#include "Base/Base.h"
+#include "Discretisation/Geometry/Geometry.h"
+#include "Discretisation/Mesh/Mesh.h"
+
+
+Bool testRemotes( unsigned rank, unsigned nProcs, unsigned watch );
+Bool testSnkSrc( unsigned rank, unsigned nProcs, unsigned watch );
+Bool testArrays( unsigned rank, unsigned nProcs, unsigned watch );
+Bool testClaim( unsigned rank, unsigned nProcs, unsigned watch );
+
+Decomp* buildDecomp( unsigned rank, unsigned nProcs, unsigned nLocals );
+void buildRequired( unsigned rank, unsigned nProcs,
+ unsigned* nRequired, unsigned** required );
+
+
+#define nTests 4
+
+TestSuite* suite;
+TestSuite_Test tests[nTests] = {{"set remotes", testRemotes},
+ {"sink/sources", testSnkSrc},
+ {"arrays", testArrays},
+ {"claim", testClaim}};
+
+
+Bool testRemotes( unsigned rank, unsigned nProcs, unsigned watch ) {
+ Decomp* decomp;
+ Decomp_Sync* sync;
+ unsigned nLocals = 100;
+ unsigned remPerSide = nLocals / 10;
+ unsigned nRemotes = remPerSide * ((rank > 0 && rank < nProcs - 1) ? 2 : 1) * ((nProcs > 1) ? 1 : 0);
+ unsigned* remotes;
+ unsigned r_i;
+
+ decomp = buildDecomp( rank, nProcs, nLocals );
+ sync = Decomp_Sync_New( "" );
+ Decomp_Sync_SetDecomp( sync, decomp );
+
+ if( nRemotes ) {
+ remotes = Memory_Alloc_Array_Unnamed( unsigned, nRemotes );
+ if( rank > 0 ) {
+ for( r_i = 0; r_i < remPerSide; r_i++ )
+ remotes[r_i] = rank * nLocals - remPerSide + r_i;
+ }
+ if( rank < nProcs - 1 ) {
+ for( r_i = 0; r_i < remPerSide; r_i++ ) {
+ unsigned ind = r_i + ((rank > 0) ? remPerSide : 0);
+
+ remotes[ind] = (rank + 1) * nLocals + r_i;
+ }
+ }
+ }
+ else
+ remotes = NULL;
+
+ Decomp_Sync_SetRemotes( sync, nRemotes, remotes );
+
+ if( rank == watch ) {
+ if( sync->nRemotes != nRemotes ) {
+ FreeArray( remotes );
+ FreeObject( sync );
+ FreeObject( decomp );
+ return False;
+ }
+
+ if( rank > 0 ) {
+ for( r_i = 0; r_i < remPerSide; r_i++ ) {
+ if( sync->remotes[r_i] != remotes[r_i] ) {
+ FreeArray( remotes );
+ FreeObject( sync );
+ FreeObject( decomp );
+ return False;
+ }
+ }
+ }
+ if( rank < nProcs - 1 ) {
+ for( r_i = 0; r_i < remPerSide; r_i++ ) {
+ unsigned ind = r_i + ((rank > 0) ? remPerSide : 0);
+
+ if( sync->remotes[ind] != remotes[ind] ) {
+ FreeArray( remotes );
+ FreeObject( sync );
+ FreeObject( decomp );
+ return False;
+ }
+ }
+ }
+ }
+
+ FreeArray( remotes );
+ FreeObject( sync );
+ FreeObject( decomp );
+
+ return True;
+}
+
+Bool testSnkSrc( unsigned rank, unsigned nProcs, unsigned watch ) {
+ Decomp* decomp;
+ Decomp_Sync* sync;
+ unsigned nLocals = 100;
+ unsigned remPerSide = nLocals / 10;
+ unsigned nRemotes = remPerSide * ((rank > 0 && rank < nProcs - 1) ? 2 : 1) * ((nProcs > 1) ? 1 : 0);
+ unsigned* remotes;
+ unsigned r_i;
+
+ decomp = buildDecomp( rank, nProcs, nLocals );
+ sync = Decomp_Sync_New( "" );
+ Decomp_Sync_SetDecomp( sync, decomp );
+
+ if( nRemotes ) {
+ remotes = Memory_Alloc_Array_Unnamed( unsigned, nRemotes );
+ if( rank > 0 ) {
+ for( r_i = 0; r_i < remPerSide; r_i++ )
+ remotes[r_i] = rank * nLocals - remPerSide + r_i;
+ }
+ if( rank < nProcs - 1 ) {
+ for( r_i = 0; r_i < remPerSide; r_i++ ) {
+ unsigned ind = r_i + ((rank > 0) ? remPerSide : 0);
+
+ remotes[ind] = (rank + 1) * nLocals + r_i;
+ }
+ }
+ }
+ else
+ remotes = NULL;
+
+ Decomp_Sync_SetRemotes( sync, nRemotes, remotes );
+
+ if( rank == watch ) {
+ if( sync->netSnks != nRemotes || sync->netSrcs != nRemotes ) {
+ FreeArray( remotes );
+ FreeObject( sync );
+ FreeObject( decomp );
+ return False;
+ }
+ }
+
+ FreeArray( remotes );
+ FreeObject( sync );
+ FreeObject( decomp );
+
+ return True;
+}
+
+typedef struct {
+ int one;
+ int two;
+ int three;
+} theStruct;
+
+Bool testArrays( unsigned rank, unsigned nProcs, unsigned watch ) {
+ Decomp* decomp;
+ Decomp_Sync* sync;
+ unsigned nLocals = 100;
+ unsigned remPerSide = nLocals / 10;
+ unsigned nRemotes = remPerSide * ((rank > 0 && rank < nProcs - 1) ? 2 : 1) * ((nProcs > 1) ? 1 : 0);
+ unsigned* remotes;
+ int* intLocals;
+ int* intRemotes;
+ theStruct* structLocals;
+ theStruct* structRemotes;
+ unsigned r_i;
+
+ decomp = buildDecomp( rank, nProcs, nLocals );
+ sync = Decomp_Sync_New( "" );
+ Decomp_Sync_SetDecomp( sync, decomp );
+
+ if( nRemotes ) {
+ remotes = Memory_Alloc_Array_Unnamed( unsigned, nRemotes );
+ if( rank > 0 ) {
+ for( r_i = 0; r_i < remPerSide; r_i++ )
+ remotes[r_i] = rank * nLocals - remPerSide + r_i;
+ }
+ if( rank < nProcs - 1 ) {
+ for( r_i = 0; r_i < remPerSide; r_i++ ) {
+ unsigned ind = r_i + ((rank > 0) ? remPerSide : 0);
+
+ remotes[ind] = (rank + 1) * nLocals + r_i;
+ }
+ }
+ }
+ else
+ remotes = NULL;
+
+ if( nLocals ) {
+ intLocals = Memory_Alloc_Array_Unnamed( int, nLocals );
+ structLocals = Memory_Alloc_Array_Unnamed( theStruct, nLocals );
+ }
+ else {
+ intLocals = NULL;
+ structLocals = NULL;
+ }
+ if( nRemotes ) {
+ intRemotes = Memory_Alloc_Array_Unnamed( int, nRemotes );
+ structRemotes = Memory_Alloc_Array_Unnamed( theStruct, nRemotes );
+ }
+ else {
+ intRemotes = NULL;
+ structRemotes = NULL;
+ }
+ for( r_i = 0; r_i < nLocals; r_i++ ) {
+ intLocals[r_i] = rank;
+ structLocals[r_i].one = -rank;
+ structLocals[r_i].two = rank;
+ structLocals[r_i].three = -rank;
+ }
+ for( r_i = 0; r_i < nRemotes; r_i++ ) {
+ intRemotes[r_i] = rank;
+ structRemotes[r_i].one = -rank;
+ structRemotes[r_i].two = rank;
+ structRemotes[r_i].three = -rank;
+ }
+
+ Decomp_Sync_SetRemotes( sync, nRemotes, remotes );
+ Decomp_Sync_AddArray( sync, intLocals, intRemotes, sizeof(int), sizeof(int), sizeof(int) );
+ Decomp_Sync_AddArray( sync, &structLocals[0].two, &structRemotes[0].two,
+ sizeof(theStruct), sizeof(theStruct), sizeof(int) );
+ Decomp_Sync_Sync( sync );
+
+ FreeArray( remotes );
+ FreeObject( sync );
+ FreeObject( decomp );
+
+ if( rank == watch ) {
+ for( r_i = 0; r_i < nLocals; r_i++ ) {
+ if( intLocals[r_i] != rank || structLocals[r_i].two != rank ||
+ structLocals[r_i].one != -rank || structLocals[r_i].three != -rank )
+ {
+ break;
+ }
+ }
+ if( r_i < nLocals ) {
+ FreeArray( intLocals );
+ FreeArray( intRemotes );
+ FreeArray( structLocals );
+ FreeArray( structRemotes );
+ return False;
+ }
+
+ if( rank > 0 ) {
+ for( r_i = 0; r_i < remPerSide; r_i++ ) {
+ if( intRemotes[r_i] != rank - 1 || structRemotes[r_i].two != rank - 1 ||
+ structRemotes[r_i].one != -rank || structRemotes[r_i].three != -rank )
+ {
+ break;
+ }
+ }
+ if( r_i < remPerSide ) {
+ FreeArray( intLocals );
+ FreeArray( intRemotes );
+ FreeArray( structLocals );
+ FreeArray( structRemotes );
+ return False;
+ }
+ }
+ if( rank < nProcs - 1 ) {
+ for( r_i = 0; r_i < remPerSide; r_i++ ) {
+ unsigned ind = r_i + ((rank > 0) ? remPerSide : 0);
+
+ if( intRemotes[ind] != rank + 1 || structRemotes[ind].two != rank + 1 ||
+ structRemotes[ind].one != -rank || structRemotes[ind].three != -rank )
+ {
+ break;
+ }
+ }
+ if( r_i < remPerSide ) {
+ FreeArray( intLocals );
+ FreeArray( intRemotes );
+ FreeArray( structLocals );
+ FreeArray( structRemotes );
+ return False;
+ }
+ }
+ }
+
+ FreeArray( intLocals );
+ FreeArray( intRemotes );
+ FreeArray( structLocals );
+ FreeArray( structRemotes );
+
+ return True;
+}
+
+Bool testClaim( unsigned rank, unsigned nProcs, unsigned watch ) {
+ Decomp* decomp;
+ Decomp_Sync* sync;
+ unsigned nRequired;
+ unsigned* required;
+
+ buildRequired( rank, nProcs, &nRequired, &required );
+ decomp = Decomp_New( "" );
+ sync = Decomp_Sync_New( "" );
+ Decomp_Sync_SetDecomp( sync, decomp );
+ Decomp_Sync_Decompose( sync, nRequired, required );
+
+ if( rank == watch ) {
+ }
+
+ FreeArray( required );
+ FreeObject( sync );
+ FreeObject( decomp );
+
+ return True;
+}
+
+
+Decomp* buildDecomp( unsigned rank, unsigned nProcs, unsigned nLocals ) {
+ Decomp* decomp = Decomp_New( "" );
+ unsigned* locals;
+ unsigned l_i;
+
+ locals = Memory_Alloc_Array_Unnamed( unsigned, nLocals );
+ for( l_i = 0; l_i < nLocals; l_i++ )
+ locals[l_i] = rank * nLocals + l_i;
+ Decomp_SetLocals( decomp, nLocals, locals );
+
+ FreeArray( locals );
+
+ return decomp;
+}
+
+void buildRequired( unsigned rank, unsigned nProcs,
+ unsigned* nRequired, unsigned** required )
+{
+ unsigned start;
+ unsigned r_i;
+
+ *nRequired = 100;
+ *required = Memory_Alloc_Array_Unnamed( unsigned, *nRequired );
+ start = rank * (*nRequired - 10);
+
+ for( r_i = 0; r_i < *nRequired; r_i++ )
+ (*required)[r_i] = start + r_i;
+}
+
+
+int main( int argc, char* argv[] ) {
+ /* Initialise MPI, get world info. */
+ MPI_Init( &argc, &argv );
+
+ /* Initialise StGermain. */
+ BaseFoundation_Init( &argc, &argv );
+ BaseIO_Init( &argc, &argv );
+ BaseContainer_Init( &argc, &argv );
+
+ /* Create the test suite. */
+ suite = TestSuite_New();
+ TestSuite_SetProcToWatch( suite, (argc >= 2) ? atoi( argv[1] ) : 0 );
+ TestSuite_SetTests( suite, nTests, tests );
+
+ /* Run the tests. */
+ TestSuite_Run( suite );
+
+ /* Destroy test suites. */
+ FreeObject( suite );
+
+ /* Finalise StGermain. */
+ BaseContainer_Finalise();
+ BaseIO_Finalise();
+ BaseFoundation_Finalise();
+
+ /* Close off MPI */
+ MPI_Finalize();
+
+ return MPI_SUCCESS;
+}
More information about the cig-commits
mailing list