source: issm/oecreview/Archive/23390-24306/ISSM-23503-23504.diff@ 24307

Last change on this file since 24307 was 24307, checked in by Mathieu Morlighem, 5 years ago

NEW: adding Archive/23390-24306

File size: 5.1 KB
  • ../trunk-jpl/src/c/modules/ModelProcessorx/ElementsAndVerticesPartitioning.cpp

     
    1616
    1717void  ElementsAndVerticesPartitioning(bool** pmy_elements, int** pmy_vertices, IoModel* iomodel){
    1818
    19         int i,j;
    20 
    21         const int RIFTINFOSIZE = 12;
    2219        int numberofelements2d;
    2320        int numberofvertices2d;
    2421        int numlayers;
    25         int numrifts;
    2622        int numvertex_pairing;
    2723
    28         /*output: */
    29         bool *my_elements = NULL;
    30         int  *my_vertices = NULL;
    31 
    3224        /*intermediary: */
    3325        int        *epart          = NULL; //element partitioning.
    3426        int        *npart          = NULL; //node partitioning.
     
    3527        int         elements_width;        //number of columns in elements (2d->3, 3d->6)
    3628        int         el1,el2;
    3729        int        *elements2d     = NULL;
    38         int        *vertex_pairing = NULL;
    39         IssmDouble *riftinfo       = NULL;
    4030
    4131        /*Get my_rank:*/
    4232        int my_rank   = IssmComm::GetRank();
    4333        int num_procs = IssmComm::GetSize();
    4434
    45         /*Fetch parameters: */
    46         iomodel->FindConstant(&numrifts,"md.rifts.numrifts");
    47 
    4835        /*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;
     36        if(*pmy_elements) return;
    5037
    5138        /*Number of vertices per elements, needed to correctly retrieve data: */
    5239        /*Determine parallel partitioning of elements: we use Metis for now. First load the data, then partition*/
     
    7461                        _error_("mesh elements "<< EnumToStringx(iomodel->meshelementtype) <<" not supported yet");
    7562        }
    7663
     64        /*Partition and free resouces*/
    7765        MeshPartitionx(&epart,&npart,iomodel->numberofelements,iomodel->numberofvertices,iomodel->elements,numberofelements2d,numberofvertices2d,elements2d,numlayers,elements_width,iomodel->meshelementtype,num_procs);
    78 
    79         /*Free elements2d: */
    8066        xDelete<int>(elements2d);
     67        xDelete<int>(npart);
    8168
    8269        /*Deal with rifts, they have to be included into one partition only, not several: */
     70        int numrifts;
     71        iomodel->FindConstant(&numrifts,"md.rifts.numrifts");
    8372        if(numrifts){
     73                IssmDouble *riftinfo = NULL;
    8474                iomodel->FetchData(&riftinfo,&numrifts,NULL,"md.rifts.riftstruct");
    85                 for(i=0;i<numrifts;i++){
     75                for(int i=0;i<numrifts;i++){
     76                        const int RIFTINFOSIZE = 12;
    8677                        el1=reCast<int>(*(riftinfo+RIFTINFOSIZE*i+2))-1; //matlab indexing to c indexing
    8778                        el2=reCast<int>(*(riftinfo+RIFTINFOSIZE*i+3))-1; //matlab indexing to c indexing
    8879                        epart[el2]=epart[el1]; //ensures that this pair of elements will be in the same partition, as well as the corresponding vertices;
     
    9081                iomodel->DeleteData(riftinfo,"md.rifts.riftstruct");
    9182        }
    9283
    93         /*Used later on: */
    94         my_vertices=xNewZeroInit<int>(iomodel->numberofvertices);
    95         my_elements=xNewZeroInit<bool>(iomodel->numberofelements);
     84        /*Create my_vertices and my_elements, used by each partition */
     85        bool *my_elements = xNewZeroInit<bool>(iomodel->numberofelements);
     86        int  *my_vertices = xNewZeroInit<int>(iomodel->numberofvertices);
    9687
    9788        /*Start figuring out, out of the partition, which elements belong to this cpu: */
    98         for(i=0;i<iomodel->numberofelements;i++){
     89        for(int i=0;i<iomodel->numberofelements;i++){
    9990
    10091                /*!All elements have been partitioned above, only deal with elements for this cpu: */
    10192                if(my_rank==epart[i]){
     
    10495                         *the  element index to do this. For each element n, we know index[n][0:2] holds the indices (matlab indexing)
    10596                         into the vertices coordinates. If we start plugging 1 into my_vertices for each index[n][i] (i=0:2), then my_vertices
    10697                         will hold which vertices belong to this partition*/
    107                         for(j=0;j<elements_width;j++){
     98                        for(int j=0;j<elements_width;j++){
    10899                                my_vertices[iomodel->elements[elements_width*i+j]-1]=1;
    109100                        }
    110101                }
     
    113104        /*We might have vertex_pairing in which case, some vertices have to be cloned:
    114105         * penpair has 2 nodes that are poointing toward 2 vertices.
    115106         * The 2 vertices must be in the same cpu as the penpair*/
     107        int *vertex_pairing = NULL;
    116108        iomodel->FetchData(&vertex_pairing,&numvertex_pairing,NULL,"md.stressbalance.vertex_pairing");
    117         for(i=0;i<numvertex_pairing;i++){
     109        for(int i=0;i<numvertex_pairing;i++){
    118110                if(my_vertices[vertex_pairing[2*i+0]-1] && !my_vertices[vertex_pairing[2*i+1]-1]){
    119111                        my_vertices[vertex_pairing[2*i+1]-1]=2; //to know that these elements are not on the partition
    120112                }
     
    121113        }
    122114        xDelete<int>(vertex_pairing);
    123115        iomodel->FetchData(&vertex_pairing,&numvertex_pairing,NULL,"md.masstransport.vertex_pairing");
    124         for(i=0;i<numvertex_pairing;i++){
     116        for(int i=0;i<numvertex_pairing;i++){
    125117                if(my_vertices[vertex_pairing[2*i+0]-1] && !my_vertices[vertex_pairing[2*i+1]-1]){
    126118                        my_vertices[vertex_pairing[2*i+1]-1]=2; //to know that these elements are not on the partition
    127119                }
     
    128120        }
    129121        xDelete<int>(vertex_pairing);
    130122
    131         /*Free ressources:*/
    132         xDelete<int>(npart);
     123        /*cleanup and assign output pointer*/
    133124        xDelete<int>(epart);
    134 
    135         /*Assign output pointers:*/
    136125        *pmy_elements=my_elements;
    137126        *pmy_vertices=my_vertices;
    138127}
Note: See TracBrowser for help on using the repository browser.