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

Last change on this file since 16539 was 16539, checked in by Mathieu Morlighem, 11 years ago

CHG: moving model processor stuff to analyses

File size: 5.2 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/classes.h"
13#include "../../shared/shared.h"
14#include "../MeshPartitionx/MeshPartitionx.h"
15#include "../ModelProcessorx/ModelProcessorx.h"
16
17void ElementsAndVerticesPartitioning(bool** pmy_elements, int** pmy_vertices, IoModel* iomodel){
18
19 int i;
20
21 const int RIFTINFOSIZE = 12;
22 int numberofelements2d;
23 int numberofvertices2d;
24 int numlayers;
25 int numrifts;
26 int numvertex_pairing;
27
28 /*output: */
29 bool *my_elements = NULL;
30 int *my_vertices = NULL;
31
32 /*intermediary: */
33 int *epart = NULL; //element partitioning.
34 int *npart = NULL; //node partitioning.
35 int elements_width; //number of columns in elements (2d->3, 3d->6)
36 int el1,el2;
37 int *elements2d = NULL;
38 int *vertex_pairing = NULL;
39 IssmDouble *riftinfo = NULL;
40
41 /*Get my_rank:*/
42 int my_rank = IssmComm::GetRank();
43 int num_procs = IssmComm::GetSize();
44
45 /*Fetch parameters: */
46 iomodel->Constant(&numrifts,RiftsNumriftsEnum);
47
48 /*First, check that partitioning has not yet been carryed out. Just check whether my_elements pointers is not already assigned a value: */
49 if(*pmy_elements)return;
50
51 /*Number of vertices per elements, needed to correctly retrieve data: */
52 /*Determine parallel partitioning of elements: we use Metis for now. First load the data, then partition*/
53 switch(iomodel->meshtype){
54 case Mesh2DhorizontalEnum:
55 elements_width=3;
56 numberofelements2d = 0;
57 numberofvertices2d = 0;
58 numlayers = 0;
59 break;
60 case Mesh2DverticalEnum:
61 elements_width=3;
62 numberofelements2d = 0;
63 numberofvertices2d = 0;
64 numlayers = 0;
65 break;
66 case Mesh3DEnum:
67 elements_width=6; //penta elements
68 iomodel->FetchData(&elements2d,NULL,NULL,MeshElements2dEnum);
69 iomodel->Constant(&numberofelements2d,MeshNumberofelements2dEnum);
70 iomodel->Constant(&numberofvertices2d,MeshNumberofvertices2dEnum);
71 iomodel->Constant(&numlayers,MeshNumberoflayersEnum);
72 break;
73 default:
74 _error_("mesh not supported yet");
75 }
76
77 MeshPartitionx(&epart,&npart,iomodel->numberofelements,iomodel->numberofvertices,iomodel->elements,numberofelements2d,numberofvertices2d,elements2d,numlayers,elements_width,iomodel->meshtype,num_procs);
78
79 /*Free elements2d: */
80 xDelete<int>(elements2d);
81
82 /*Deal with rifts, they have to be included into one partition only, not several: */
83 if(numrifts){
84 iomodel->FetchData(&riftinfo,&numrifts,NULL,RiftsRiftstructEnum);
85 for(i=0;i<numrifts;i++){
86 el1=reCast<int>(*(riftinfo+RIFTINFOSIZE*i+2))-1; //matlab indexing to c indexing
87 el2=reCast<int>(*(riftinfo+RIFTINFOSIZE*i+3))-1; //matlab indexing to c indexing
88 epart[el2]=epart[el1]; //ensures that this pair of elements will be in the same partition, as well as the corresponding vertices;
89 }
90 iomodel->DeleteData(riftinfo,RiftsRiftstructEnum);
91 }
92
93 /*Used later on: */
94 my_vertices=xNewZeroInit<int>(iomodel->numberofvertices);
95 my_elements=xNewZeroInit<bool>(iomodel->numberofelements);
96
97 /*Start figuring out, out of the partition, which elements belong to this cpu: */
98 for (i=0;i<iomodel->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[iomodel->elements[elements_width*i+0]-1]=1;
110 my_vertices[iomodel->elements[elements_width*i+1]-1]=1;
111 my_vertices[iomodel->elements[elements_width*i+2]-1]=1;
112
113 if(elements_width==6){
114 my_vertices[iomodel->elements[elements_width*i+3]-1]=1;
115 my_vertices[iomodel->elements[elements_width*i+4]-1]=1;
116 my_vertices[iomodel->elements[elements_width*i+5]-1]=1;
117 }
118 }
119 }
120
121 /*We might have vertex_pairing in which case, some vertices have to be cloned:
122 * penpair has 2 nodes that are poointing toward 2 vertices.
123 * The 2 vertices must be in the same cpu as the penpair*/
124 iomodel->FetchData(&vertex_pairing,&numvertex_pairing,NULL,StressbalanceVertexPairingEnum);
125 for(i=0;i<numvertex_pairing;i++){
126 if(my_vertices[vertex_pairing[2*i+0]-1] && !my_vertices[vertex_pairing[2*i+1]-1]){
127 my_vertices[vertex_pairing[2*i+1]-1]=2; //to know that these elements are not on the partition
128 }
129 }
130 xDelete<int>(vertex_pairing);
131 iomodel->FetchData(&vertex_pairing,&numvertex_pairing,NULL,MasstransportVertexPairingEnum);
132 for(i=0;i<numvertex_pairing;i++){
133 if(my_vertices[vertex_pairing[2*i+0]-1] && !my_vertices[vertex_pairing[2*i+1]-1]){
134 my_vertices[vertex_pairing[2*i+1]-1]=2; //to know that these elements are not on the partition
135 }
136 }
137 xDelete<int>(vertex_pairing);
138
139 /*Free ressources:*/
140 xDelete<int>(npart);
141 xDelete<int>(epart);
142
143 /*Assign output pointers:*/
144 *pmy_elements=my_elements;
145 *pmy_vertices=my_vertices;
146}
Note: See TracBrowser for help on using the repository browser.