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

Diff of /trunk/finley/src/Mesh_prepareNodes.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 781 by bcumming, Mon Jun 26 01:46:34 2006 UTC revision 782 by bcumming, Tue Jul 18 00:47:47 2006 UTC
# Line 35  void Finley_Mesh_prepareNodes(Finley_Mes Line 35  void Finley_Mesh_prepareNodes(Finley_Mes
35    dim_t n,len;    dim_t n,len;
36    index_t id,max_id,min_id,*maskReducedDOF=NULL,*maskDOF=NULL,*reducedNodesMask=NULL,*index=NULL;    index_t id,max_id,min_id,*maskReducedDOF=NULL,*maskDOF=NULL,*reducedNodesMask=NULL,*index=NULL;
37  #ifdef PASO_MPI  #ifdef PASO_MPI
38    index_t *indexLocal=NULL, *maskReducedDOFLocation=NULL;    index_t *maskDOFLocation=NULL, *indexLocal=NULL, *maskReducedDOFLocation=NULL, *mask=NULL;
39    index_t thisDom = in->MPIInfo->rank, i;    index_t thisDom = in->MPIInfo->rank, i, iI, iB, iE;
40    dim_t bufferLength=0, numReducedLocal, numReducedInternal, numReducedBoundary, numReducedExternal, numForward, numBackward, totalDOF;    dim_t bufferLength=0, numInternal, numBoundary, numExternal, numLocal, numReducedLocal, numReducedInternal, numReducedBoundary, numReducedExternal, numForward, numBackward, totalDOF;
41        Finley_NodeDistribution *distribution=NULL;
42    
43  #endif  #endif
44    
# Line 114  void Finley_Mesh_prepareNodes(Finley_Mes Line 115  void Finley_Mesh_prepareNodes(Finley_Mes
115     }     }
116    
117  #ifdef PASO_MPI  #ifdef PASO_MPI
   
118    /***********************************************************    /***********************************************************
119      update the distribution data      update the distribution data
120     ***********************************************************/     ***********************************************************/
121        
122    totalDOF = in->Nodes->degreeOfFreedomDistribution->numLocal + in->Nodes->degreeOfFreedomDistribution->numExternal;      in->Nodes->degreeOfFreedomDistribution->numInternal = 0;
123        in->Nodes->degreeOfFreedomDistribution->numBoundary = 0;
124        in->Nodes->degreeOfFreedomDistribution->numExternal = 0;
125        mask = MEMALLOC(in->Nodes->numDegreesOfFreedom,index_t);
126        for( i=0; i<in->Nodes->numNodes; i++ )
127            mask[in->Nodes->degreeOfFreedom[i]] = in->Nodes->Dom[i];
128        for( i=0; i<in->Nodes->numDegreesOfFreedom; i++ )
129            switch( mask[i] ){
130                case NODE_INTERNAL :
131                    in->Nodes->degreeOfFreedomDistribution->numInternal++;
132                    break;
133                case NODE_BOUNDARY :
134                    in->Nodes->degreeOfFreedomDistribution->numBoundary++;
135                    break;
136                case NODE_EXTERNAL :
137                    in->Nodes->degreeOfFreedomDistribution->numExternal++;
138                    break;
139            }
140            
141        in->Nodes->degreeOfFreedomDistribution->numLocal = in->Nodes->degreeOfFreedomDistribution->numInternal + in->Nodes->degreeOfFreedomDistribution->numBoundary;
142        
143        /* reform the vtxdist */
144        distribution = in->Nodes->degreeOfFreedomDistribution;
145        
146        MPI_Allgather( &distribution->numLocal, 1, MPI_INT, distribution->vtxdist+1, 1, MPI_INT, in->MPIInfo->comm );
147    
148        distribution->vtxdist[0] = 0;
149        for( i=2; i<in->MPIInfo->size+1; i++ )
150            distribution->vtxdist[i] += distribution->vtxdist[i-1];
151            
152        MPI_Allreduce( &distribution->numLocal, &distribution->numGlobal, 1, MPI_INT, MPI_SUM, in->MPIInfo->comm );
153        
154    /* update the forward and backward indices for each neighbour */    /* update the forward and backward indices for each neighbour */
155    for( n=0; n<in->Nodes->degreeOfFreedomDistribution->numNeighbours; n++ ){    for( n=0; n<in->Nodes->degreeOfFreedomDistribution->numNeighbours; n++ ){
156      for( i=0; i<in->Nodes->degreeOfFreedomDistribution->edges[n]->numForward; i++ )      for( i=0, iI=0; i<in->Nodes->degreeOfFreedomDistribution->edges[n]->numForward; i++ ){
157        in->Nodes->degreeOfFreedomDistribution->edges[n]->indexForward[i] = maskDOF[in->Nodes->degreeOfFreedomDistribution->edges[n]->indexForward[i]];              if( maskDOF[in->Nodes->degreeOfFreedomDistribution->edges[n]->indexForward[i]]>=0 )
158      for( i=0; i<in->Nodes->degreeOfFreedomDistribution->edges[n]->numBackward; i++ )          in->Nodes->degreeOfFreedomDistribution->edges[n]->indexForward[iI++] = maskDOF[in->Nodes->degreeOfFreedomDistribution->edges[n]->indexForward[i]];
159        in->Nodes->degreeOfFreedomDistribution->edges[n]->indexBackward[i] = maskDOF[in->Nodes->degreeOfFreedomDistribution->edges[n]->indexBackward[i]];          }
160            in->Nodes->degreeOfFreedomDistribution->edges[n]->numForward = iI;
161        for( i=0, iI=0; i<in->Nodes->degreeOfFreedomDistribution->edges[n]->numBackward; i++ ){
162                if(maskDOF[in->Nodes->degreeOfFreedomDistribution->edges[n]->indexBackward[i]]>=0)  
163                    in->Nodes->degreeOfFreedomDistribution->edges[n]->indexBackward[iI++] = maskDOF[in->Nodes->degreeOfFreedomDistribution->edges[n]->indexBackward[i]];
164            }
165            in->Nodes->degreeOfFreedomDistribution->edges[n]->numBackward = iI;
166      }
167    
168      Finley_NodeDistribution_formCommBuffer( in->Nodes->degreeOfFreedomDistribution, in->Nodes->CommBuffer );
169      if ( !Finley_MPI_noError( in->MPIInfo )) {
170        goto clean;
171    }    }
172    
173    /* update the global indices for the external DOF on this subdomain */    /* update the global indices for the external DOF on this subdomain */
174    Finley_NodeDistribution_calculateIndexExternal( in->Nodes->degreeOfFreedomDistribution, in->Nodes->CommBuffer );    Finley_NodeDistribution_calculateIndexExternal( in->Nodes->degreeOfFreedomDistribution, in->Nodes->CommBuffer );
175      if( !Finley_MPI_noError( in->MPIInfo ) ) {
176        goto clean;
177      }
178    
179    /***********************************************************    /***********************************************************
180      compile distribution data for the reduced degrees of freedom      compile distribution data for the reduced degrees of freedom
# Line 139  void Finley_Mesh_prepareNodes(Finley_Mes Line 183  void Finley_Mesh_prepareNodes(Finley_Mes
183    /* determnine the number of internal, boundary and external DOF in the reduced distribution */    /* determnine the number of internal, boundary and external DOF in the reduced distribution */
184    totalDOF = in->Nodes->degreeOfFreedomDistribution->numLocal + in->Nodes->degreeOfFreedomDistribution->numExternal;    totalDOF = in->Nodes->degreeOfFreedomDistribution->numLocal + in->Nodes->degreeOfFreedomDistribution->numExternal;
185    
   maskReducedDOFLocation = MEMALLOC( in->Nodes->numDegreesOfFreedom, index_t );  
   for( n=0; n<in->Nodes->numDegreesOfFreedom; n++ )  
     maskReducedDOFLocation[n] = -1;  
   Finley_Mesh_markOrderedDegreesOfFreedomLocation( maskReducedDOFLocation, 0, in, TRUE);  
   
186    numReducedInternal = numReducedBoundary = numReducedLocal = numReducedExternal = 0;    numReducedInternal = numReducedBoundary = numReducedLocal = numReducedExternal = 0;
187    for( n=0; n<in->Nodes->degreeOfFreedomDistribution->numLocal + in->Nodes->degreeOfFreedomDistribution->numExternal; n++ ) {      n=0;
188      switch( maskReducedDOFLocation[n] ) {    for( n=0; n<len; n++ )
189        case 1 :          if( maskReducedDOF[n]>=0 )
190          numReducedInternal++;              switch( mask[maskDOF[n]] ){
191          break;                  case NODE_INTERNAL :
192        case 2 :                      numReducedInternal++;
193          numReducedBoundary++;                      break;
194          break;                  case NODE_BOUNDARY :
195        case 3 :                              numReducedBoundary++;
196          numReducedExternal++;                      break;
197          break;                  case NODE_EXTERNAL :
198        }                      numReducedExternal++;
199    }                      break;
200                }
201    
202    numReducedLocal = numReducedInternal + numReducedBoundary;    numReducedLocal = numReducedInternal + numReducedBoundary;
   MEMFREE( maskReducedDOFLocation );  
203    
204      Finley_NodeDistribution_allocTable( in->Nodes->reducedDegreeOfFreedomDistribution, numReducedLocal, numReducedExternal, 0 );
205    if( Finley_MPI_noError( in->MPIInfo ) )      if( Finley_MPI_noError( in->MPIInfo ) )  
206    {    {
     Finley_NodeDistribution_allocTable( in->Nodes->reducedDegreeOfFreedomDistribution, numReducedLocal, numReducedExternal, 0 );  
207      in->Nodes->reducedDegreeOfFreedomDistribution->numInternal = numReducedInternal;        in->Nodes->reducedDegreeOfFreedomDistribution->numInternal = numReducedInternal;  
208      in->Nodes->reducedDegreeOfFreedomDistribution->numBoundary = numReducedBoundary;      in->Nodes->reducedDegreeOfFreedomDistribution->numBoundary = numReducedBoundary;
209    
# Line 177  void Finley_Mesh_prepareNodes(Finley_Mes Line 217  void Finley_Mesh_prepareNodes(Finley_Mes
217      }      }
218      indexLocal = TMPMEMALLOC( bufferLength, index_t );      indexLocal = TMPMEMALLOC( bufferLength, index_t );
219    
220            /* find the new mapping from full to reduced DOF */
221            for( i=0; i<in->Nodes->numNodes; i++ )
222                maskReducedDOF[in->Nodes->degreeOfFreedom[i]] = in->Nodes->reducedDegreeOfFreedom[i];
223    
224            /* use the mapping to map the full distribution to the reduced distribution */  
225      for( n=0; n<in->Nodes->degreeOfFreedomDistribution->numNeighbours; n++ ){      for( n=0; n<in->Nodes->degreeOfFreedomDistribution->numNeighbours; n++ ){
226        numForward = numBackward = 0;        numForward = numBackward = 0;
227        for( i=0; i<in->Nodes->degreeOfFreedomDistribution->edges[n]->numForward; i++  )        for( i=0; i<in->Nodes->degreeOfFreedomDistribution->edges[n]->numForward; i++  )
# Line 190  void Finley_Mesh_prepareNodes(Finley_Mes Line 235  void Finley_Mesh_prepareNodes(Finley_Mes
235      }      }
236    
237      /* update the global indices for the reduced external DOF on this subdomain */      /* update the global indices for the reduced external DOF on this subdomain */
   
238      Finley_NodeDistribution_calculateIndexExternal( in->Nodes->degreeOfFreedomDistribution, in->Nodes->CommBuffer );      Finley_NodeDistribution_calculateIndexExternal( in->Nodes->degreeOfFreedomDistribution, in->Nodes->CommBuffer );
239        if( !Finley_MPI_noError( in->MPIInfo ) ) {
240                TMPMEMFREE( indexLocal );
241                goto clean;
242            }
243      Finley_NodeDistribution_formCommBuffer( in->Nodes->reducedDegreeOfFreedomDistribution, in->Nodes->reducedCommBuffer );      Finley_NodeDistribution_formCommBuffer( in->Nodes->reducedDegreeOfFreedomDistribution, in->Nodes->reducedCommBuffer );
244        if( !Finley_MPI_noError( in->MPIInfo ) ) {
245            TMPMEMFREE( indexLocal );
246                goto clean;
247            }
248      Finley_NodeDistribution_calculateIndexExternal( in->Nodes->reducedDegreeOfFreedomDistribution, in->Nodes->reducedCommBuffer );      Finley_NodeDistribution_calculateIndexExternal( in->Nodes->reducedDegreeOfFreedomDistribution, in->Nodes->reducedCommBuffer );
249            TMPMEMFREE( indexLocal );
250    }    }
251        MEMFREE( mask );
252    TMPMEMFREE( indexLocal );      Finley_MPI_noError( in->MPIInfo );
253  #endif  #endif
254    clean:
255    TMPMEMFREE(reducedNodesMask);    TMPMEMFREE(reducedNodesMask);
256    TMPMEMFREE(maskDOF);    TMPMEMFREE(maskDOF);
257    TMPMEMFREE(maskReducedDOF);    TMPMEMFREE(maskReducedDOF);

Legend:
Removed from v.781  
changed lines
  Added in v.782

  ViewVC Help
Powered by ViewVC 1.1.26