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

Last change on this file since 15423 was 15423, checked in by Mathieu Morlighem, 12 years ago

CHG: dim can now be retrieved directly in iomodel

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