/[escript]/trunk/finley/src/NodeDistribution_alloctable.c
ViewVC logotype

Contents of /trunk/finley/src/NodeDistribution_alloctable.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 782 - (show annotations)
Tue Jul 18 00:47:47 2006 UTC (13 years, 2 months ago) by bcumming
File MIME type: text/plain
File size: 3514 byte(s)
Large number of changes to Finley for meshing in MPI.

- optimisation and neatening up of rectcanglular mesh generation code
- first and second order 1D, 2D and 3D rectangular meshes are now
  available in finley and escript using MPI.
- reduced meshes now generated in MPI, and interpolation to and from 
  reduced data types now supported.  

1 #include "Distribution.h"
2
3 #ifdef PASO_MPI
4
5 /*
6 * allocates memory arrays for a node distribution.
7 * assumes that numLocal and numExternal are greater than zero.
8 * numNeigbhours may be zero.
9 */
10 void Finley_NodeDistribution_allocTable( Finley_NodeDistribution *in, dim_t numLocal, dim_t numExternal, dim_t numNeighbours )
11 {
12 index_t i;
13 index_t *neighbours=NULL, *vtxdist=NULL, *indexExternal=NULL;
14 Finley_NodeGhostEdge **edges=NULL;
15
16 if( Finley_checkPtr(in) )
17 return;
18
19 neighbours = numNeighbours ? MEMALLOC( numNeighbours, index_t ) : NULL;
20 edges = numNeighbours ? MEMALLOC( numNeighbours, Finley_NodeGhostEdge* ) : NULL;
21 vtxdist = MEMALLOC( in->MPIInfo->size+1, index_t );
22 indexExternal = numExternal ? MEMALLOC( numExternal, index_t ) : NULL;
23
24 if( (numNeighbours && ( Finley_checkPtr(neighbours) || Finley_checkPtr(edges) )) || Finley_checkPtr(vtxdist) || (numExternal && Finley_checkPtr(indexExternal)) )
25 {
26 MEMFREE( neighbours );
27 MEMFREE( edges );
28 MEMFREE( vtxdist );
29 MEMFREE( indexExternal );
30 }
31 else
32 {
33 Finley_NodeDistribution_deallocTable( in );
34 in->neighbours = neighbours;
35 in->edges = edges;
36 in->vtxdist = vtxdist;
37 in->indexExternal = indexExternal;
38
39 /* initialise dummy values */
40 for( i=0; i<numNeighbours; i++ )
41 {
42 neighbours[i] = -1;
43 edges[i] = NULL;
44 }
45 for( i=0; i<numExternal; i++ )
46 indexExternal[i] = -1;
47
48 /* MPI Communication to determine global info from local info */
49 MPI_Allreduce( &numLocal, &in->numGlobal, 1, MPI_INT, MPI_SUM, in->MPIInfo->comm );
50 vtxdist[0] = 0;
51 MPI_Allgather( &numLocal, 1, MPI_INT, vtxdist+1, 1, MPI_INT, in->MPIInfo->comm );
52 for( i=1; i<in->MPIInfo->size+1; i++ )
53 vtxdist[i] += vtxdist[i-1];
54
55 /* table dimensions */
56 in->numLocal = numLocal;
57 in->numInternal = 0;
58 in->numExternal = numExternal;
59 in->numBoundary = 0;
60 in->numNeighbours = numNeighbours;
61 }
62
63 return;
64 }
65
66 void Finley_NodeDistribution_deallocTable( Finley_NodeDistribution *in )
67 {
68 index_t i;
69
70 if( in!=NULL )
71 {
72 MEMFREE( in->neighbours );
73 MEMFREE( in->vtxdist );
74 MEMFREE( in->indexExternal );
75 for( i=0; i<in->numNeighbours; i++ )
76 Finley_NodeGhostEdge_dealloc( in->edges[i] );
77 MEMFREE( in->edges );
78
79 in->numBoundary = 0;
80 in->numInternal = 0;
81 in->numLocal = 0;
82 in->numNeighbours = 0;
83 in->numExternal = 0;
84 in->numGlobal = 0;
85 }
86 }
87
88 /* TODO */
89 /* maybe these should be replaced by a routine to compile the edge list automatically */
90 void Finley_NodeGhostEdge_allocTable( Finley_NodeGhostEdge *in, dim_t numForward, dim_t numBackward )
91 {
92 index_t *indexForward=NULL, *indexBackward=NULL;
93
94 if( Finley_checkPtr(in) )
95 return;
96
97 if( numForward )
98 {
99 indexForward = MEMALLOC( numForward, index_t );
100 }
101 if( numBackward )
102 {
103 indexBackward = MEMALLOC( numBackward, index_t );
104 }
105
106 if( (numForward && Finley_checkPtr(indexForward)) || (numBackward && Finley_checkPtr(indexBackward)) )
107 {
108 MEMFREE( indexForward );
109 MEMFREE( indexBackward );
110 }
111 else
112 {
113 Finley_NodeGhostEdge_deallocTable( in );
114 in->indexForward = indexForward;
115 in->indexBackward = indexBackward;
116 in->numForward = numForward;
117 in->numBackward = numBackward;
118 }
119 return;
120 }
121
122 void Finley_NodeGhostEdge_deallocTable( Finley_NodeGhostEdge *in )
123 {
124 if( in!=NULL )
125 {
126 in->numForward = in->numBackward = 0;
127 MEMFREE( in->indexForward);
128 MEMFREE( in->indexBackward );
129 }
130 }
131
132
133 #endif

  ViewVC Help
Powered by ViewVC 1.1.26