source: issm/trunk-jpl/src/c/modules/ModelProcessorx/ElementsAndVerticesPartitioning.cpp@ 12565

Last change on this file since 12565 was 12565, checked in by utke, 13 years ago

reCast

File size: 5.5 KB
Line 
1/*!\file: ElementsAndVerticesPartitioning.cpp
2 * \brief: partition elements and nodes and vertices
3 */
4
5#ifdef HAVE_CONFIG_H
6 #include <config.h>
7#else
8#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
9#endif
10
11#include <string.h>
12#include "../../objects/objects.h"
13#include "../../shared/shared.h"
14#include "../../EnumDefinitions/EnumDefinitions.h"
15#include "../../io/io.h"
16#include "../../include/include.h"
17#include "../MeshPartitionx/MeshPartitionx.h"
18#include "../ModelProcessorx/ModelProcessorx.h"
19
20void ElementsAndVerticesPartitioning(bool** pmy_elements, int** pmy_vertices, IoModel* iomodel){
21
22 int i;
23
24 extern int my_rank;
25 extern int num_procs;
26 int numberofelements;
27 int numberofvertices;
28 int numberofelements2d;
29 int numberofvertices2d;
30 int numlayers;
31 int numrifts;
32 int numvertex_pairing;
33
34 /*output: */
35 bool* my_elements=NULL;
36 int* my_vertices=NULL;
37
38 /*intermediary: */
39 int* epart=NULL; //element partitioning.
40 int* npart=NULL; //node partitioning.
41 int elements_width; //number of columns in elements (2d->3, 3d->6)
42 int el1,el2;
43 int dim;
44 IssmDouble* elements=NULL;
45 IssmDouble* elements2d=NULL;
46 IssmDouble* riftinfo=NULL;
47 IssmDouble* vertex_pairing=NULL;
48
49 /*Fetch parameters: */
50 iomodel->Constant(&dim,MeshDimensionEnum);
51 iomodel->Constant(&numberofelements,MeshNumberofelementsEnum);
52 iomodel->Constant(&numberofvertices,MeshNumberofverticesEnum);
53 iomodel->Constant(&numberofelements2d,MeshNumberofelements2dEnum);
54 iomodel->Constant(&numberofvertices2d,MeshNumberofvertices2dEnum);
55 iomodel->Constant(&numlayers,MeshNumberoflayersEnum);
56 iomodel->Constant(&numrifts,RiftsNumriftsEnum);
57
58 /*First, check that partitioning has not yet been carryed out. Just check whether my_elements pointers is not already assigned a value: */
59 if (*pmy_elements)return;
60
61 /*Number of vertices per elements, needed to correctly retrieve data: */
62 if(dim==2) elements_width=3; //tria elements
63 else elements_width=6; //penta elements
64
65 /*Determine parallel partitioning of elements: we use Metis for now. First load the data, then partition*/
66 if(dim==2){
67 /*load elements: */
68 iomodel->FetchData(&elements,NULL,NULL,MeshElementsEnum);
69 }
70 else{
71 /*load elements2d: */
72 iomodel->FetchData(&elements2d,NULL,NULL,MeshElements2dEnum);
73 }
74
75 MeshPartitionx(&epart, &npart,numberofelements,numberofvertices,elements, numberofelements2d,numberofvertices2d,elements2d,numlayers,elements_width, dim,num_procs);
76
77 /*Free elements and elements2d: */
78 xDelete<IssmDouble>(elements);
79 xDelete<IssmDouble>(elements2d);
80
81 /*Deal with rifts, they have to be included into one partition only, not several: */
82 if(numrifts){
83 iomodel->FetchData(&riftinfo,&numrifts,NULL,RiftsRiftstructEnum);
84 for(i=0;i<numrifts;i++){
85 el1=reCast<int>(*(riftinfo+RIFTINFOSIZE*i+2))-1; //matlab indexing to c indexing
86 el2=reCast<int>(*(riftinfo+RIFTINFOSIZE*i+3))-1; //matlab indexing to c indexing
87 epart[el2]=epart[el1]; //ensures that this pair of elements will be in the same partition, as well as the corresponding vertices;
88 }
89 xDelete<IssmDouble>(riftinfo);
90 }
91
92 /*Used later on: */
93 my_vertices=xNewZeroInit<int>(numberofvertices);
94 my_elements=xNewZeroInit<bool>(numberofelements);
95
96 /*Start figuring out, out of the partition, which elements belong to this cpu: */
97 iomodel->FetchData(&elements,NULL,NULL,MeshElementsEnum);
98 for (i=0;i<numberofelements;i++){
99
100 /*!All elements have been partitioned above, only deal with elements for this cpu: */
101 if(my_rank==epart[i]){
102
103 my_elements[i]=true;
104
105 /*Now that we are here, we can also start building the list of vertices belonging to this cpu partition: we use
106 *the element index to do this. For each element n, we know index[n][0:2] holds the indices (matlab indexing)
107 into the vertices coordinates. If we start plugging 1 into my_vertices for each index[n][i] (i=0:2), then my_vertices
108 will hold which vertices belong to this partition*/
109 my_vertices[reCast<int>(*(elements+elements_width*i+0))-1]=1;
110 my_vertices[reCast<int>(*(elements+elements_width*i+1))-1]=1;
111 my_vertices[reCast<int>(*(elements+elements_width*i+2))-1]=1;
112
113 if(elements_width==6){
114 my_vertices[reCast<int>(*(elements+elements_width*i+3))-1]=1;
115 my_vertices[reCast<int>(*(elements+elements_width*i+4))-1]=1;
116 my_vertices[reCast<int>(*(elements+elements_width*i+5))-1]=1;
117 }
118 }
119 }//for (i=0;i<numberofelements;i++)
120 /*Free data : */
121 xDelete<IssmDouble>(elements);
122
123 /*We might have vertex_pairing in which case, some vertices have to be cloned:
124 * penpair has 2 nodes that are poointing toward 2 vertices.
125 * The 2 vertices must be in the same cpu as the penpair*/
126 iomodel->FetchData(&vertex_pairing,&numvertex_pairing,NULL,DiagnosticVertexPairingEnum);
127 for(i=0;i<numvertex_pairing;i++){
128 if(my_vertices[reCast<int>(vertex_pairing[2*i+0])-1] && !my_vertices[reCast<int>(vertex_pairing[2*i+1])-1]){
129 my_vertices[reCast<int>(vertex_pairing[2*i+1])-1]=2; //to know that these elements are not on the partition
130 }
131 }
132 xDelete<IssmDouble>(vertex_pairing);
133 iomodel->FetchData(&vertex_pairing,&numvertex_pairing,NULL,PrognosticVertexPairingEnum);
134 for(i=0;i<numvertex_pairing;i++){
135 if(my_vertices[reCast<int>(vertex_pairing[2*i+0])-1] && !my_vertices[reCast<int>(vertex_pairing[2*i+1])-1]){
136 my_vertices[reCast<int>(vertex_pairing[2*i+1])-1]=2; //to know that these elements are not on the partition
137 }
138 }
139 xDelete<IssmDouble>(vertex_pairing);
140
141 /*Free ressources:*/
142 xDelete<int>(npart);
143 xDelete<int>(epart);
144
145 /*Assign output pointers:*/
146 *pmy_elements=my_elements;
147 *pmy_vertices=my_vertices;
148}
Note: See TracBrowser for help on using the repository browser.