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 |
|
---|
17 | void ElementsAndVerticesPartitioning(IoModel* iomodel){
|
---|
18 |
|
---|
19 | int numberofelements2d;
|
---|
20 | int numberofvertices2d;
|
---|
21 | int numlayers;
|
---|
22 |
|
---|
23 | /*intermediary: */
|
---|
24 | int *epart = NULL; //element partitioning.
|
---|
25 | int *npart = NULL; //node partitioning.
|
---|
26 | int elements_width; //number of columns in elements (2d->3, 3d->6)
|
---|
27 | int *elements2d = NULL;
|
---|
28 |
|
---|
29 | /*Get my_rank:*/
|
---|
30 | int my_rank = IssmComm::GetRank();
|
---|
31 | int num_procs = IssmComm::GetSize();
|
---|
32 |
|
---|
33 | /*First, check that partitioning has not yet been carryed out. Just check whether my_elements pointers is not already assigned a value: */
|
---|
34 | if(iomodel->my_elements) return;
|
---|
35 |
|
---|
36 | /*Number of vertices per elements, needed to correctly retrieve data: */
|
---|
37 | /*Determine parallel partitioning of elements: we use Metis for now. First load the data, then partition*/
|
---|
38 | switch(iomodel->meshelementtype){
|
---|
39 | case TriaEnum:
|
---|
40 | elements_width=3;
|
---|
41 | numberofelements2d = 0;
|
---|
42 | numberofvertices2d = 0;
|
---|
43 | numlayers = 0;
|
---|
44 | break;
|
---|
45 | case TetraEnum:
|
---|
46 | elements_width=4;
|
---|
47 | numberofelements2d = 0;
|
---|
48 | numberofvertices2d = 0;
|
---|
49 | numlayers = 0;
|
---|
50 | break;
|
---|
51 | case PentaEnum:
|
---|
52 | elements_width=6;
|
---|
53 | iomodel->FetchData(&elements2d,NULL,NULL,"md.mesh.elements2d");
|
---|
54 | iomodel->FindConstant(&numberofelements2d,"md.mesh.numberofelements2d");
|
---|
55 | iomodel->FindConstant(&numberofvertices2d,"md.mesh.numberofvertices2d");
|
---|
56 | iomodel->FindConstant(&numlayers,"md.mesh.numberoflayers");
|
---|
57 | break;
|
---|
58 | default:
|
---|
59 | _error_("mesh elements "<< EnumToStringx(iomodel->meshelementtype) <<" not supported yet");
|
---|
60 | }
|
---|
61 |
|
---|
62 | /*Use ice levelset for weights*/
|
---|
63 | int fordan = 0;
|
---|
64 | int* weights = NULL;
|
---|
65 | if(fordan){
|
---|
66 | IssmDouble* icelevelset = NULL;
|
---|
67 | iomodel->FetchData(&icelevelset,NULL,NULL,"md.mask.ice_levelset");
|
---|
68 |
|
---|
69 | weights = xNew<int>(iomodel->numberofvertices);
|
---|
70 | for(int i=0;i<iomodel->numberofvertices;i++){
|
---|
71 | if(icelevelset[i]>=0) weights[i] = 1;
|
---|
72 | if(icelevelset[i]<0) weights[i] = 100;
|
---|
73 | }
|
---|
74 | xDelete<IssmDouble>(icelevelset);
|
---|
75 | }
|
---|
76 |
|
---|
77 | /*Partition and free resouces*/
|
---|
78 | MeshPartitionx(&epart,&npart,iomodel->numberofelements,iomodel->numberofvertices,iomodel->elements,numberofelements2d,numberofvertices2d,elements2d,weights,numlayers,elements_width,iomodel->meshelementtype,num_procs);
|
---|
79 | xDelete<int>(elements2d);
|
---|
80 | xDelete<int>(npart);
|
---|
81 | xDelete<int>(weights);
|
---|
82 |
|
---|
83 | if(fordan){
|
---|
84 | for(int i=0;i<IssmComm::GetSize();i++){
|
---|
85 | if(i==IssmComm::GetRank()){
|
---|
86 | int temp =0;
|
---|
87 | for(int j=0;j<iomodel->numberofelements;j++) if(epart[j]==i) temp++;
|
---|
88 | _printf_("Partition #"<<i<<" number of elements: "<<temp<<"\n");
|
---|
89 | }
|
---|
90 | ISSM_MPI_Barrier(IssmComm::GetComm());
|
---|
91 | }
|
---|
92 | }
|
---|
93 |
|
---|
94 | /*Deal with rifts, they have to be included into one partition only, not several: */
|
---|
95 | int numrifts;
|
---|
96 | iomodel->FindConstant(&numrifts,"md.rifts.numrifts");
|
---|
97 | if(numrifts){
|
---|
98 | IssmDouble *riftinfo = NULL;
|
---|
99 | iomodel->FetchData(&riftinfo,&numrifts,NULL,"md.rifts.riftstruct");
|
---|
100 | for(int i=0;i<numrifts;i++){
|
---|
101 | const int RIFTINFOSIZE = 12;
|
---|
102 | int el1=reCast<int>(*(riftinfo+RIFTINFOSIZE*i+2))-1; //matlab indexing to c indexing
|
---|
103 | int el2=reCast<int>(*(riftinfo+RIFTINFOSIZE*i+3))-1; //matlab indexing to c indexing
|
---|
104 | epart[el2]=epart[el1]; //ensures that this pair of elements will be in the same partition, as well as the corresponding vertices;
|
---|
105 | }
|
---|
106 | iomodel->DeleteData(riftinfo,"md.rifts.riftstruct");
|
---|
107 | }
|
---|
108 |
|
---|
109 | /*Create my_elements, used by each partition */
|
---|
110 | bool *my_elements = xNewZeroInit<bool>(iomodel->numberofelements);
|
---|
111 |
|
---|
112 | /*Start figuring out, out of the partition, which elements belong to this cpu: */
|
---|
113 | bool check = false;
|
---|
114 | for(int i=0;i<iomodel->numberofelements;i++){
|
---|
115 |
|
---|
116 | /*!All elements have been partitioned above, only deal with elements for this cpu: */
|
---|
117 | if(my_rank==epart[i]){
|
---|
118 | my_elements[i]=true;
|
---|
119 | check = true;
|
---|
120 | }
|
---|
121 | }
|
---|
122 | if(!check) _error_("partition "<<my_rank<<" does not have any element! Try reducing md.cluster.np");
|
---|
123 |
|
---|
124 | /*Assign pointers to iomodel*/
|
---|
125 | iomodel->epart =epart;
|
---|
126 | iomodel->my_elements=my_elements;
|
---|
127 | }
|
---|