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