/[escript]/branches/domexper/dudley/src/Mesh_optimizeDOFLabeling.c
ViewVC logotype

Contents of /branches/domexper/dudley/src/Mesh_optimizeDOFLabeling.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3126 - (show annotations)
Wed Sep 1 00:37:53 2010 UTC (8 years, 8 months ago) by jfenwick
File MIME type: text/plain
File size: 5459 byte(s)
Updated referenceElements and enums
1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2010 by University of Queensland
5 * Earth Systems Science Computational Center (ESSCC)
6 * http://www.uq.edu.au/esscc
7 *
8 * Primary Business: Queensland, Australia
9 * Licensed under the Open Software License version 3.0
10 * http://www.opensource.org/licenses/osl-3.0.php
11 *
12 *******************************************************/
13
14
15 /************************************************************************/
16
17 /* Dudley: Mesh: optimizes the labeling of the DOFs on each processor */
18
19 /************************************************************************/
20
21 #include "Mesh.h"
22 #include "IndexList.h"
23
24 /**************************************************************/
25
26 void Dudley_Mesh_optimizeDOFLabeling(Dudley_Mesh* in,dim_t *distribution) {
27
28 index_t myFirstVertex,myLastVertex, *newGlobalDOFID=NULL, firstVertex, lastVertex;
29 register index_t k;
30 dim_t mpiSize, myNumVertices,len, p, i;
31 Paso_Pattern *pattern=NULL;
32 Paso_MPI_rank myRank,dest,source,current_rank;
33 Dudley_IndexList* index_list=NULL;
34 #ifdef PASO_MPI
35 MPI_Status status;
36 #endif
37
38 if (in==NULL) return;
39 if (in->Nodes == NULL) return;
40
41 myRank=in->MPIInfo->rank;
42 mpiSize=in->MPIInfo->size;
43 myFirstVertex=distribution[myRank];
44 myLastVertex=distribution[myRank+1];
45 myNumVertices=myLastVertex-myFirstVertex;
46 len=0;
47 for (p=0;p<mpiSize;++p) len=MAX(len,distribution[p+1]-distribution[p]);
48
49 index_list=TMPMEMALLOC(myNumVertices,Dudley_IndexList);
50 newGlobalDOFID=TMPMEMALLOC(len,index_t);
51 /* create the adjacency structure xadj and adjncy */
52 if (! ( Dudley_checkPtr(index_list) || Dudley_checkPtr(newGlobalDOFID) ) ) {
53 #pragma omp parallel private(i)
54 {
55 #pragma omp for schedule(static)
56 for(i=0;i<myNumVertices;++i) {
57 index_list[i].extension=NULL;
58 index_list[i].n=0;
59 }
60 /* insert contributions from element matrices into colums index index_list: */
61 Dudley_IndexList_insertElementsWithRowRangeNoMainDiagonal(index_list, myFirstVertex, myLastVertex,
62 in->Elements,in->Nodes->globalDegreesOfFreedom,
63 in->Nodes->globalDegreesOfFreedom);
64 Dudley_IndexList_insertElementsWithRowRangeNoMainDiagonal(index_list, myFirstVertex, myLastVertex,
65 in->FaceElements,in->Nodes->globalDegreesOfFreedom,
66 in->Nodes->globalDegreesOfFreedom);
67 Dudley_IndexList_insertElementsWithRowRangeNoMainDiagonal(index_list, myFirstVertex, myLastVertex,
68 in->Points,in->Nodes->globalDegreesOfFreedom,
69 in->Nodes->globalDegreesOfFreedom);
70 }
71 /* create the local matrix pattern */
72 pattern=Dudley_IndexList_createPattern(0,myNumVertices,index_list,myFirstVertex, myLastVertex,-myFirstVertex);
73
74 /* clean up index list */
75 if (index_list!=NULL) {
76 #pragma omp parallel for private(i)
77 for(i=0;i<myNumVertices;++i) Dudley_IndexList_free(index_list[i].extension);
78 }
79
80 if (Dudley_noError()) Paso_Pattern_reduceBandwidth(pattern,newGlobalDOFID);
81
82 Paso_Pattern_free(pattern);
83 }
84 Paso_MPIInfo_noError(in->MPIInfo);
85 if (Dudley_noError()) {
86 /* shift new labeling to create a global id */
87 #pragma omp parallel for private(i)
88 for (i=0;i<myNumVertices;++i) newGlobalDOFID[i]+=myFirstVertex;
89
90
91 /* distribute new labeling to other processors */
92 dest=Paso_MPIInfo_mod(mpiSize, myRank + 1);
93 source=Paso_MPIInfo_mod(mpiSize, myRank - 1);
94 current_rank=myRank;
95 for (p=0; p< mpiSize; ++p) {
96 firstVertex=distribution[current_rank];
97 lastVertex=distribution[current_rank+1];
98 #pragma omp parallel for private(i,k)
99 for (i=0;i<in->Nodes->numNodes;++i) {
100 k=in->Nodes->globalDegreesOfFreedom[i];
101 if ( (firstVertex<=k) && (k<lastVertex)) {
102 in->Nodes->globalDegreesOfFreedom[i]=newGlobalDOFID[k-firstVertex];
103 }
104 }
105
106 if (p<mpiSize-1) { /* the final send can be skipped */
107 #ifdef PASO_MPI
108 MPI_Sendrecv_replace(newGlobalDOFID,len, MPI_INT,
109 dest, in->MPIInfo->msg_tag_counter,
110 source, in->MPIInfo->msg_tag_counter,
111 in->MPIInfo->comm,&status);
112 #endif
113 in->MPIInfo->msg_tag_counter++;
114 current_rank=Paso_MPIInfo_mod(mpiSize, current_rank-1);
115 }
116 }
117 }
118 TMPMEMFREE(index_list);
119 TMPMEMFREE(newGlobalDOFID);
120 #if 0
121 for (i=0;i<in->Nodes->numNodes;++i) printf("%d ",in->Nodes->globalDegreesOfFreedom[i]);
122 printf("\n");
123 #endif
124 return;
125 }

  ViewVC Help
Powered by ViewVC 1.1.26