[24307] | 1 | Index: ../trunk-jpl/src/c/modules/ModelProcessorx/ElementsAndVerticesPartitioning.cpp
|
---|
| 2 | ===================================================================
|
---|
| 3 | --- ../trunk-jpl/src/c/modules/ModelProcessorx/ElementsAndVerticesPartitioning.cpp (revision 23503)
|
---|
| 4 | +++ ../trunk-jpl/src/c/modules/ModelProcessorx/ElementsAndVerticesPartitioning.cpp (revision 23504)
|
---|
| 5 | @@ -16,19 +16,11 @@
|
---|
| 6 |
|
---|
| 7 | void ElementsAndVerticesPartitioning(bool** pmy_elements, int** pmy_vertices, IoModel* iomodel){
|
---|
| 8 |
|
---|
| 9 | - int i,j;
|
---|
| 10 | -
|
---|
| 11 | - const int RIFTINFOSIZE = 12;
|
---|
| 12 | int numberofelements2d;
|
---|
| 13 | int numberofvertices2d;
|
---|
| 14 | int numlayers;
|
---|
| 15 | - int numrifts;
|
---|
| 16 | int numvertex_pairing;
|
---|
| 17 |
|
---|
| 18 | - /*output: */
|
---|
| 19 | - bool *my_elements = NULL;
|
---|
| 20 | - int *my_vertices = NULL;
|
---|
| 21 | -
|
---|
| 22 | /*intermediary: */
|
---|
| 23 | int *epart = NULL; //element partitioning.
|
---|
| 24 | int *npart = NULL; //node partitioning.
|
---|
| 25 | @@ -35,18 +27,13 @@
|
---|
| 26 | int elements_width; //number of columns in elements (2d->3, 3d->6)
|
---|
| 27 | int el1,el2;
|
---|
| 28 | int *elements2d = NULL;
|
---|
| 29 | - int *vertex_pairing = NULL;
|
---|
| 30 | - IssmDouble *riftinfo = NULL;
|
---|
| 31 |
|
---|
| 32 | /*Get my_rank:*/
|
---|
| 33 | int my_rank = IssmComm::GetRank();
|
---|
| 34 | int num_procs = IssmComm::GetSize();
|
---|
| 35 |
|
---|
| 36 | - /*Fetch parameters: */
|
---|
| 37 | - iomodel->FindConstant(&numrifts,"md.rifts.numrifts");
|
---|
| 38 | -
|
---|
| 39 | /*First, check that partitioning has not yet been carryed out. Just check whether my_elements pointers is not already assigned a value: */
|
---|
| 40 | - if(*pmy_elements)return;
|
---|
| 41 | + if(*pmy_elements) return;
|
---|
| 42 |
|
---|
| 43 | /*Number of vertices per elements, needed to correctly retrieve data: */
|
---|
| 44 | /*Determine parallel partitioning of elements: we use Metis for now. First load the data, then partition*/
|
---|
| 45 | @@ -74,15 +61,19 @@
|
---|
| 46 | _error_("mesh elements "<< EnumToStringx(iomodel->meshelementtype) <<" not supported yet");
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | + /*Partition and free resouces*/
|
---|
| 50 | MeshPartitionx(&epart,&npart,iomodel->numberofelements,iomodel->numberofvertices,iomodel->elements,numberofelements2d,numberofvertices2d,elements2d,numlayers,elements_width,iomodel->meshelementtype,num_procs);
|
---|
| 51 | -
|
---|
| 52 | - /*Free elements2d: */
|
---|
| 53 | xDelete<int>(elements2d);
|
---|
| 54 | + xDelete<int>(npart);
|
---|
| 55 |
|
---|
| 56 | /*Deal with rifts, they have to be included into one partition only, not several: */
|
---|
| 57 | + int numrifts;
|
---|
| 58 | + iomodel->FindConstant(&numrifts,"md.rifts.numrifts");
|
---|
| 59 | if(numrifts){
|
---|
| 60 | + IssmDouble *riftinfo = NULL;
|
---|
| 61 | iomodel->FetchData(&riftinfo,&numrifts,NULL,"md.rifts.riftstruct");
|
---|
| 62 | - for(i=0;i<numrifts;i++){
|
---|
| 63 | + for(int i=0;i<numrifts;i++){
|
---|
| 64 | + const int RIFTINFOSIZE = 12;
|
---|
| 65 | el1=reCast<int>(*(riftinfo+RIFTINFOSIZE*i+2))-1; //matlab indexing to c indexing
|
---|
| 66 | el2=reCast<int>(*(riftinfo+RIFTINFOSIZE*i+3))-1; //matlab indexing to c indexing
|
---|
| 67 | epart[el2]=epart[el1]; //ensures that this pair of elements will be in the same partition, as well as the corresponding vertices;
|
---|
| 68 | @@ -90,12 +81,12 @@
|
---|
| 69 | iomodel->DeleteData(riftinfo,"md.rifts.riftstruct");
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | - /*Used later on: */
|
---|
| 73 | - my_vertices=xNewZeroInit<int>(iomodel->numberofvertices);
|
---|
| 74 | - my_elements=xNewZeroInit<bool>(iomodel->numberofelements);
|
---|
| 75 | + /*Create my_vertices and my_elements, used by each partition */
|
---|
| 76 | + bool *my_elements = xNewZeroInit<bool>(iomodel->numberofelements);
|
---|
| 77 | + int *my_vertices = xNewZeroInit<int>(iomodel->numberofvertices);
|
---|
| 78 |
|
---|
| 79 | /*Start figuring out, out of the partition, which elements belong to this cpu: */
|
---|
| 80 | - for(i=0;i<iomodel->numberofelements;i++){
|
---|
| 81 | + for(int i=0;i<iomodel->numberofelements;i++){
|
---|
| 82 |
|
---|
| 83 | /*!All elements have been partitioned above, only deal with elements for this cpu: */
|
---|
| 84 | if(my_rank==epart[i]){
|
---|
| 85 | @@ -104,7 +95,7 @@
|
---|
| 86 | *the element index to do this. For each element n, we know index[n][0:2] holds the indices (matlab indexing)
|
---|
| 87 | into the vertices coordinates. If we start plugging 1 into my_vertices for each index[n][i] (i=0:2), then my_vertices
|
---|
| 88 | will hold which vertices belong to this partition*/
|
---|
| 89 | - for(j=0;j<elements_width;j++){
|
---|
| 90 | + for(int j=0;j<elements_width;j++){
|
---|
| 91 | my_vertices[iomodel->elements[elements_width*i+j]-1]=1;
|
---|
| 92 | }
|
---|
| 93 | }
|
---|
| 94 | @@ -113,8 +104,9 @@
|
---|
| 95 | /*We might have vertex_pairing in which case, some vertices have to be cloned:
|
---|
| 96 | * penpair has 2 nodes that are poointing toward 2 vertices.
|
---|
| 97 | * The 2 vertices must be in the same cpu as the penpair*/
|
---|
| 98 | + int *vertex_pairing = NULL;
|
---|
| 99 | iomodel->FetchData(&vertex_pairing,&numvertex_pairing,NULL,"md.stressbalance.vertex_pairing");
|
---|
| 100 | - for(i=0;i<numvertex_pairing;i++){
|
---|
| 101 | + for(int i=0;i<numvertex_pairing;i++){
|
---|
| 102 | if(my_vertices[vertex_pairing[2*i+0]-1] && !my_vertices[vertex_pairing[2*i+1]-1]){
|
---|
| 103 | my_vertices[vertex_pairing[2*i+1]-1]=2; //to know that these elements are not on the partition
|
---|
| 104 | }
|
---|
| 105 | @@ -121,7 +113,7 @@
|
---|
| 106 | }
|
---|
| 107 | xDelete<int>(vertex_pairing);
|
---|
| 108 | iomodel->FetchData(&vertex_pairing,&numvertex_pairing,NULL,"md.masstransport.vertex_pairing");
|
---|
| 109 | - for(i=0;i<numvertex_pairing;i++){
|
---|
| 110 | + for(int i=0;i<numvertex_pairing;i++){
|
---|
| 111 | if(my_vertices[vertex_pairing[2*i+0]-1] && !my_vertices[vertex_pairing[2*i+1]-1]){
|
---|
| 112 | my_vertices[vertex_pairing[2*i+1]-1]=2; //to know that these elements are not on the partition
|
---|
| 113 | }
|
---|
| 114 | @@ -128,11 +120,8 @@
|
---|
| 115 | }
|
---|
| 116 | xDelete<int>(vertex_pairing);
|
---|
| 117 |
|
---|
| 118 | - /*Free ressources:*/
|
---|
| 119 | - xDelete<int>(npart);
|
---|
| 120 | + /*cleanup and assign output pointer*/
|
---|
| 121 | xDelete<int>(epart);
|
---|
| 122 | -
|
---|
| 123 | - /*Assign output pointers:*/
|
---|
| 124 | *pmy_elements=my_elements;
|
---|
| 125 | *pmy_vertices=my_vertices;
|
---|
| 126 | }
|
---|