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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 731 - (show annotations)
Mon May 15 04:09:52 2006 UTC (13 years, 4 months ago) by bcumming
File MIME type: text/plain
File size: 4064 byte(s)


1 /* 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 MEMREALLOC( in->edges, in->numNeighbours, Finley_NodeGhostEdge* );
52 MEMREALLOC( in->neighbours, in->numNeighbours, index_t );
53 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 posDomain = in->numNeighbours++;
95
96 if( posDomain==-1 )
97 {
98 posDomain = in->numNeighbours++;
99 MEMREALLOC( in->edges, in->numNeighbours, Finley_NodeGhostEdge* );
100 MEMREALLOC( in->neighbours, in->numNeighbours, index_t );
101 if( Finley_checkPtr( in->edges ) || Finley_checkPtr( in->neighbours ) )
102 return;
103 in->edges[posDomain] = NULL;
104 }
105 in->neighbours[posDomain] = domain;
106 in->edges[posDomain] = Finley_NodeGhostEdge_alloc();
107 if( Finley_checkPtr(in->edges[posDomain]))
108 {
109 Finley_setError( MEMORY_ERROR, "Finley_NodeDistribution_addForward() : invalid pointer to ghost edge" );
110 return;
111 }
112 Finley_NodeGhostEdge_allocTable( in->edges[posDomain], 0, numBackward );
113 memcpy( in->edges[posDomain]->indexBackward, indexLocal, sizeof(index_t)*numBackward );
114 }
115 }
116
117 #endif

  ViewVC Help
Powered by ViewVC 1.1.26