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

Last change on this file since 13592 was 13592, checked in by Eric.Larour, 12 years ago

CHG: starting transition from extern int my_rank to my_rank2 where my_rank2 is
recovered with IssmComm:GetRank()

File size: 5.7 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 "../../classes/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 int my_rank2;
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 /*Get my_rank2:*/
50 my_rank2=IssmComm::GetRank();
51
52 /*Fetch parameters: */
53 iomodel->Constant(&dim,MeshDimensionEnum);
54 iomodel->Constant(&numberofelements,MeshNumberofelementsEnum);
55 iomodel->Constant(&numberofvertices,MeshNumberofverticesEnum);
56 iomodel->Constant(&numberofelements2d,MeshNumberofelements2dEnum);
57 iomodel->Constant(&numberofvertices2d,MeshNumberofvertices2dEnum);
58 iomodel->Constant(&numlayers,MeshNumberoflayersEnum);
59 iomodel->Constant(&numrifts,RiftsNumriftsEnum);
60
61 /*First, check that partitioning has not yet been carryed out. Just check whether my_elements pointers is not already assigned a value: */
62 if (*pmy_elements)return;
63
64 /*Number of vertices per elements, needed to correctly retrieve data: */
65 if(dim==2) elements_width=3; //tria elements
66 else elements_width=6; //penta elements
67
68 /*Determine parallel partitioning of elements: we use Metis for now. First load the data, then partition*/
69 if(dim==2){
70 /*load elements: */
71 iomodel->FetchData(&elements,NULL,NULL,MeshElementsEnum);
72 }
73 else{
74 /*load elements2d: */
75 iomodel->FetchData(&elements2d,NULL,NULL,MeshElements2dEnum);
76 }
77
78 MeshPartitionx(&epart, &npart,numberofelements,numberofvertices,elements, numberofelements2d,numberofvertices2d,elements2d,numlayers,elements_width, dim,num_procs);
79
80 /*Free elements and elements2d: */
81 iomodel->DeleteData(elements,MeshElementsEnum);
82 iomodel->DeleteData(elements2d,MeshElements2dEnum);
83
84 /*Deal with rifts, they have to be included into one partition only, not several: */
85 if(numrifts){
86 iomodel->FetchData(&riftinfo,&numrifts,NULL,RiftsRiftstructEnum);
87 for(i=0;i<numrifts;i++){
88 el1=reCast<int>(*(riftinfo+RIFTINFOSIZE*i+2))-1; //matlab indexing to c indexing
89 el2=reCast<int>(*(riftinfo+RIFTINFOSIZE*i+3))-1; //matlab indexing to c indexing
90 epart[el2]=epart[el1]; //ensures that this pair of elements will be in the same partition, as well as the corresponding vertices;
91 }
92 iomodel->DeleteData(riftinfo,RiftsRiftstructEnum);
93 }
94
95 /*Used later on: */
96 my_vertices=xNewZeroInit<int>(numberofvertices);
97 my_elements=xNewZeroInit<bool>(numberofelements);
98
99 /*Start figuring out, out of the partition, which elements belong to this cpu: */
100 iomodel->FetchData(&elements,NULL,NULL,MeshElementsEnum);
101 for (i=0;i<numberofelements;i++){
102
103 /*!All elements have been partitioned above, only deal with elements for this cpu: */
104 if(my_rank2==epart[i]){
105
106 my_elements[i]=true;
107
108 /*Now that we are here, we can also start building the list of vertices belonging to this cpu partition: we use
109 *the element index to do this. For each element n, we know index[n][0:2] holds the indices (matlab indexing)
110 into the vertices coordinates. If we start plugging 1 into my_vertices for each index[n][i] (i=0:2), then my_vertices
111 will hold which vertices belong to this partition*/
112 my_vertices[reCast<int>(*(elements+elements_width*i+0))-1]=1;
113 my_vertices[reCast<int>(*(elements+elements_width*i+1))-1]=1;
114 my_vertices[reCast<int>(*(elements+elements_width*i+2))-1]=1;
115
116 if(elements_width==6){
117 my_vertices[reCast<int>(*(elements+elements_width*i+3))-1]=1;
118 my_vertices[reCast<int>(*(elements+elements_width*i+4))-1]=1;
119 my_vertices[reCast<int>(*(elements+elements_width*i+5))-1]=1;
120 }
121 }
122 }//for (i=0;i<numberofelements;i++)
123 /*Free data : */
124 iomodel->DeleteData(elements,MeshElementsEnum);
125
126 /*We might have vertex_pairing in which case, some vertices have to be cloned:
127 * penpair has 2 nodes that are poointing toward 2 vertices.
128 * The 2 vertices must be in the same cpu as the penpair*/
129 iomodel->FetchData(&vertex_pairing,&numvertex_pairing,NULL,DiagnosticVertexPairingEnum);
130 for(i=0;i<numvertex_pairing;i++){
131 if(my_vertices[reCast<int>(vertex_pairing[2*i+0])-1] && !my_vertices[reCast<int>(vertex_pairing[2*i+1])-1]){
132 my_vertices[reCast<int>(vertex_pairing[2*i+1])-1]=2; //to know that these elements are not on the partition
133 }
134 }
135 iomodel->DeleteData(vertex_pairing,DiagnosticVertexPairingEnum);
136 iomodel->FetchData(&vertex_pairing,&numvertex_pairing,NULL,PrognosticVertexPairingEnum);
137 for(i=0;i<numvertex_pairing;i++){
138 if(my_vertices[reCast<int>(vertex_pairing[2*i+0])-1] && !my_vertices[reCast<int>(vertex_pairing[2*i+1])-1]){
139 my_vertices[reCast<int>(vertex_pairing[2*i+1])-1]=2; //to know that these elements are not on the partition
140 }
141 }
142 iomodel->DeleteData(vertex_pairing,PrognosticVertexPairingEnum);
143
144 /*Free ressources:*/
145 xDelete<int>(npart);
146 xDelete<int>(epart);
147
148 /*Assign output pointers:*/
149 *pmy_elements=my_elements;
150 *pmy_vertices=my_vertices;
151}
Note: See TracBrowser for help on using the repository browser.