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

Annotation of /trunk/finley/src/NodeDistribution_add.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 782 - (hide annotations)
Tue Jul 18 00:47:47 2006 UTC (13 years, 1 month ago) by bcumming
File MIME type: text/plain
File size: 4079 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 bcumming 731 /* created by Ben Cumming on 2/5/2006 */
2    
3     #include "Distribution.h"
4    
5     #ifdef PASO_MPI
6    
7     /* returns position of first occurence of val in list of lenght len
8     returns -1 if val is not in list */
9     static index_t findInList( index_t val, index_t* list, dim_t len )
10     {
11     index_t i;
12    
13     for( i=0; i<len; i++ )
14     if( list[i]==val )
15     return i;
16     return -1;
17     }
18    
19     void Finley_NodeDistribution_addForward( Finley_NodeDistribution *in, index_t domain, dim_t numForward, index_t* indexLocal )
20     {
21     index_t posDomain=0;
22    
23     if( !numForward )
24     return;
25    
26     if( Finley_checkPtr(in) || Finley_checkPtr( indexLocal ) )
27     return;
28    
29     /* determine if we already share DOF with this domain */
30     posDomain = findInList( domain, in->neighbours, in->numNeighbours );
31    
32     /* we do */
33     if( posDomain>=0 )
34     {
35     MEMREALLOC( in->edges[posDomain]->indexForward, in->edges[posDomain]->numForward + numForward, index_t );
36     if( Finley_checkPtr(in->edges[posDomain]->indexForward) )
37     {
38     Finley_setError( PASO_MPI_ERROR, "Finley_NodeDistribution_addForward() : unable to realloc() memory for aditional degrees of freedom" );
39     return;
40     }
41     memcpy( in->edges[posDomain]->indexForward + in->edges[posDomain]->numForward, indexLocal, sizeof(index_t)*numForward );
42     in->edges[posDomain]->numForward += numForward;
43     }
44     /* we don't */
45     else
46     {
47     posDomain = findInList( -1, in->neighbours, in->numNeighbours );
48     if( posDomain==-1 )
49     {
50     posDomain = in->numNeighbours++;
51 bcumming 782 MEMREALLOC( in->edges, in->numNeighbours, Finley_NodeGhostEdge* );
52     MEMREALLOC( in->neighbours, in->numNeighbours, index_t );
53 bcumming 731 if( Finley_checkPtr( in->edges ) || Finley_checkPtr( in->neighbours ) )
54     return;
55     in->edges[posDomain] = NULL;
56     }
57     in->neighbours[posDomain] = domain;
58     in->edges[posDomain] = Finley_NodeGhostEdge_alloc();
59     if( Finley_checkPtr(in->edges[posDomain]) )
60     {
61     Finley_setError( MEMORY_ERROR, "Finley_NodeDistribution_addForward() : invalid pointer to ghost edge" );
62     return;
63     }
64     Finley_NodeGhostEdge_allocTable( in->edges[posDomain], numForward, 0 );
65     memcpy( in->edges[posDomain]->indexForward, indexLocal, sizeof(index_t)*numForward );
66     }
67     }
68    
69     void Finley_NodeDistribution_addBackward( Finley_NodeDistribution *in, index_t domain, dim_t numBackward, index_t* indexLocal )
70     {
71     index_t posDomain=0;
72    
73     if( !numBackward )
74     return;
75    
76     if( Finley_checkPtr(in) || Finley_checkPtr( indexLocal ) )
77     return;
78    
79     /* determine if we already share DOF with this domain */
80     posDomain = findInList( domain, in->neighbours, in->numNeighbours );
81    
82     /* we do */
83     if( posDomain>=0 )
84     {
85     MEMREALLOC( in->edges[posDomain]->indexBackward, in->edges[posDomain]->numBackward + numBackward, index_t );
86     if( Finley_checkPtr(in->edges[posDomain]->indexBackward) )
87     return;
88     memcpy( in->edges[posDomain]->indexBackward + in->edges[posDomain]->numBackward, indexLocal, sizeof(index_t)*numBackward );
89     in->edges[posDomain]->numBackward += numBackward;
90     }
91     /* we don't */
92     else
93     {
94 bcumming 782 posDomain = findInList( -1, in->neighbours, in->numNeighbours );
95 bcumming 731 if( posDomain==-1 )
96     {
97     posDomain = in->numNeighbours++;
98 bcumming 782 MEMREALLOC( in->edges, in->numNeighbours, Finley_NodeGhostEdge* );
99     MEMREALLOC( in->neighbours, in->numNeighbours, index_t );
100 bcumming 731 if( Finley_checkPtr( in->edges ) || Finley_checkPtr( in->neighbours ) )
101     return;
102     in->edges[posDomain] = NULL;
103     }
104     in->neighbours[posDomain] = domain;
105     in->edges[posDomain] = Finley_NodeGhostEdge_alloc();
106     if( Finley_checkPtr(in->edges[posDomain]))
107     {
108     Finley_setError( MEMORY_ERROR, "Finley_NodeDistribution_addForward() : invalid pointer to ghost edge" );
109     return;
110     }
111     Finley_NodeGhostEdge_allocTable( in->edges[posDomain], 0, numBackward );
112     memcpy( in->edges[posDomain]->indexBackward, indexLocal, sizeof(index_t)*numBackward );
113     }
114     }
115    
116     #endif

  ViewVC Help
Powered by ViewVC 1.1.26