/[escript]/trunk-mpi-branch/finley/src/Mesh_optimizeDOFDistribution.c
ViewVC logotype

Contents of /trunk-mpi-branch/finley/src/Mesh_optimizeDOFDistribution.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1258 - (show annotations)
Mon Aug 20 03:56:05 2007 UTC (12 years, 9 months ago) by gross
File MIME type: text/plain
File size: 9725 byte(s)
solver starts now but there still seems to be a problem in the MVM
1 /*
2 ************************************************************
3 * Copyright 2007 by ACcESS MNRF *
4 * *
5 * http://www.access.edu.au *
6 * Primary Business: Queensland, Australia *
7 * Licensed under the Open Software License version 3.0 *
8 * http://www.opensource.org/licenses/osl-3.0.php *
9 * *
10 ************************************************************
11 */
12
13 /**************************************************************/
14
15 /* Finley: Mesh: optimizes the distribution of DOFs across processors */
16 /* using ParMETIS. On return a new distribution is given and the globalDOF are relabled */
17 /* accordingly but the mesh has not been redesitributed yet */
18
19 /**************************************************************/
20
21 /* Author: gross@access.edu.au */
22 /* Version: $Id$ */
23
24 /**************************************************************/
25
26 #include "Mesh.h"
27 #include "IndexList.h"
28
29 /**************************************************************/
30
31 void Finley_Mesh_optimizeDOFDistribution(Finley_Mesh* in,dim_t *distribution) {
32
33 dim_t dim, i,j,k, myNumVertices,p, mpiSize, len, globalNumVertices,*partition_count=NULL, *new_distribution=NULL, *loc_partition_count=NULL;
34 bool_t *setNewDOFId=NULL;
35 index_t myFirstVertex, myLastVertex, firstVertex, lastVertex, *newGlobalDOFID=NULL;
36 size_t mpiSize_size;
37 index_t* partition=NULL;
38 Paso_Pattern *pattern=NULL;
39 Paso_MPI_rank myRank,dest,source,current_rank, rank;
40 Finley_IndexList* index_list=NULL;
41 float *xyz=NULL;
42
43 #ifdef PASO_MPI
44 MPI_Status status;
45 #endif
46
47 if (in==NULL) return;
48 if (in->Nodes == NULL) return;
49
50 myRank=in->MPIInfo->rank;
51 mpiSize=in->MPIInfo->size;
52 mpiSize_size=mpiSize*sizeof(dim_t);
53 dim=in->Nodes->numDim;
54 /* first step is to distribute the elements according to a global X of DOF */
55
56 myFirstVertex=distribution[myRank];
57 myLastVertex=distribution[myRank+1];
58 myNumVertices=myLastVertex-myFirstVertex;
59 globalNumVertices=distribution[mpiSize];
60 len=0;
61 for (p=0;p<mpiSize;++p) len=MAX(len,distribution[p+1]-distribution[p]);
62 partition=TMPMEMALLOC(len,index_t); /* len is used for the sending around of partition later on */
63 xyz=TMPMEMALLOC(myNumVertices*dim,float);
64 partition_count=TMPMEMALLOC(mpiSize+1,dim_t);
65 new_distribution=TMPMEMALLOC(mpiSize+1,dim_t);
66 newGlobalDOFID=TMPMEMALLOC(len,index_t);
67 setNewDOFId=TMPMEMALLOC(in->Nodes->numNodes,bool_t);
68 if (!(Finley_checkPtr(partition) || Finley_checkPtr(xyz) || Finley_checkPtr(partition_count) || Finley_checkPtr(partition_count) || Finley_checkPtr(newGlobalDOFID) || Finley_checkPtr(setNewDOFId))) {
69
70 /* set the coordinates: *?
71 /* it is assumed that at least one node on this processor provides a coordinate */
72 #pragma omp parallel for private(i,j,k)
73 for (i=0;i<in->Nodes->numNodes;++i) {
74 k=in->Nodes->globalDegreesOfFreedom[i]-myFirstVertex;
75 if ((k>=0) && (k<myNumVertices)) {
76 for (j=0;j<dim;++j) xyz[k*dim+j]=(float)(in->Nodes->Coordinates[INDEX2(j,i,dim)]);
77 }
78 }
79
80 index_list=TMPMEMALLOC(myNumVertices,Finley_IndexList);
81 /* ksteube CSR of DOF IDs */
82 /* create the adjacency structure xadj and adjncy */
83 if (! Finley_checkPtr(index_list)) {
84 #pragma omp parallel private(i)
85 {
86 #pragma omp for schedule(static)
87 for(i=0;i<myNumVertices;++i) {
88 index_list[i].extension=NULL;
89 index_list[i].n=0;
90 }
91 /* ksteube build CSR format */
92 /* insert contributions from element matrices into colums index index_list: */
93 Finley_IndexList_insertElementsWithRowRange(index_list, myFirstVertex, myLastVertex,
94 in->Elements,in->Nodes->globalDegreesOfFreedom,
95 in->Nodes->globalDegreesOfFreedom);
96 Finley_IndexList_insertElementsWithRowRange(index_list, myFirstVertex, myLastVertex,
97 in->FaceElements,in->Nodes->globalDegreesOfFreedom,
98 in->Nodes->globalDegreesOfFreedom);
99 Finley_IndexList_insertElementsWithRowRange(index_list, myFirstVertex, myLastVertex,
100 in->ContactElements,in->Nodes->globalDegreesOfFreedom,
101 in->Nodes->globalDegreesOfFreedom);
102 Finley_IndexList_insertElementsWithRowRange(index_list, myFirstVertex, myLastVertex,
103 in->Points,in->Nodes->globalDegreesOfFreedom,
104 in->Nodes->globalDegreesOfFreedom);
105 }
106
107 /* create the local matrix pattern */
108 pattern=Finley_IndexList_createPattern(myNumVertices,index_list,0,globalNumVertices,0);
109
110 /* clean up index list */
111 if (index_list!=NULL) {
112 #pragma omp parallel for private(i)
113 for(i=0;i<myNumVertices;++i) Finley_IndexList_free(index_list[i].extension);
114 }
115
116 if (Finley_noError()) {
117
118 /*
119
120 ParMETIS_V3_PartGeomKway(distribution,
121 pattern->ptr,
122 pattern->index,
123 idxtype *vwgt, +
124 idxtype *adjwgt, +
125 int *wgtflag, +
126 int *numflag, +
127 dim,
128 xyz,
129 int *ncon, +
130 mpiSize,
131 float *tpwgts, +
132 float *ubvec, +
133 int *options, +
134 int *edgecut, +
135 partition,
136 in->MPIInfo->comm);
137 */
138 for (i=0;i<myNumVertices;++i) partition[i]=myRank; /* remove */
139 }
140
141 Paso_Pattern_free(pattern);
142
143 /* create a new distributioin and labeling of the DOF */
144 memset(new_distribution,0,mpiSize_size);
145 #pragma omp parallel private(loc_partition_count)
146 {
147 loc_partition_count=THREAD_MEMALLOC(mpiSize,dim_t);
148 memset(loc_partition_count,0,mpiSize_size);
149 #pragma omp for private(i)
150 for (i=0;i<myNumVertices;++i) loc_partition_count[partition[i]]++ ;
151 #pragma omp critical
152 {
153 for (i=0;i<mpiSize;++i) new_distribution[i]+=loc_partition_count[i];
154 }
155 THREAD_MEMFREE(loc_partition_count);
156 }
157 #ifdef PASO_MPI
158 MPI_Allreduce( new_distribution, partition_count, mpiSize, MPI_INT, MPI_SUM, in->MPIInfo->comm );
159 #else
160 for (i=0;i<mpiSize;++i) partition_count[i]=new_distribution[i];
161 #endif
162 new_distribution[0]=0;
163 for (i=0;i<mpiSize;++i) {
164 new_distribution[i+1]=new_distribution[i]+partition_count[i];
165 partition_count[i]=0;
166 }
167 for (i=0;i<myNumVertices;++i) {
168 rank=partition[i];
169 newGlobalDOFID[i]=new_distribution[rank]+partition_count[rank];
170 partition_count[rank]++;
171 }
172 /* now the overlap needs to be created by sending the partition around*/
173
174 dest=Paso_MPIInfo_mod(mpiSize, myRank + 1);
175 source=Paso_MPIInfo_mod(mpiSize, myRank - 1);
176 current_rank=myRank;
177 #pragma omp parallel for private(i)
178 for (i=0;i<in->Nodes->numNodes;++i) setNewDOFId[i]=TRUE;
179
180 for (p=0; p< mpiSize; ++p) {
181
182 firstVertex=distribution[current_rank];
183 lastVertex=distribution[current_rank+1];
184 #pragma omp parallel for private(i,j,k)
185 for (i=0;i<in->Nodes->numNodes;++i) {
186 k=in->Nodes->globalDegreesOfFreedom[i];
187 if (setNewDOFId[i] && (firstVertex<=k) && (k<lastVertex)) {
188 in->Nodes->globalDegreesOfFreedom[i]=newGlobalDOFID[k-firstVertex];
189 setNewDOFId[i]=FALSE;
190 }
191 }
192
193 if (p<mpiSize-1) { /* the final send can be skipped */
194 #ifdef PASO_MPI
195 MPI_Sendrecv_replace(newGlobalDOFID,len, MPI_INT,
196 dest, in->MPIInfo->msg_tag_counter,
197 source, in->MPIInfo->msg_tag_counter,
198 in->MPIInfo->comm,&status);
199 #endif
200 in->MPIInfo->msg_tag_counter++;
201 current_rank=Paso_MPIInfo_mod(mpiSize, current_rank-1);
202 }
203 }
204 for (i=0;i<mpiSize+1;++i) distribution[i]=new_distribution[i];
205
206
207 }
208 TMPMEMFREE(index_list);
209 }
210 TMPMEMFREE(newGlobalDOFID);
211 TMPMEMFREE(setNewDOFId);
212 TMPMEMFREE(new_distribution);
213 TMPMEMFREE(partition_count);
214 TMPMEMFREE(partition);
215 TMPMEMFREE(xyz);
216 return;
217 }

  ViewVC Help
Powered by ViewVC 1.1.26