Index: ../trunk-jpl/src/c/modules/ModelProcessorx/ElementsAndVerticesPartitioning.cpp =================================================================== --- ../trunk-jpl/src/c/modules/ModelProcessorx/ElementsAndVerticesPartitioning.cpp (revision 23503) +++ ../trunk-jpl/src/c/modules/ModelProcessorx/ElementsAndVerticesPartitioning.cpp (revision 23504) @@ -16,19 +16,11 @@ void ElementsAndVerticesPartitioning(bool** pmy_elements, int** pmy_vertices, IoModel* iomodel){ - int i,j; - - const int RIFTINFOSIZE = 12; int numberofelements2d; int numberofvertices2d; int numlayers; - int numrifts; int numvertex_pairing; - /*output: */ - bool *my_elements = NULL; - int *my_vertices = NULL; - /*intermediary: */ int *epart = NULL; //element partitioning. int *npart = NULL; //node partitioning. @@ -35,18 +27,13 @@ int elements_width; //number of columns in elements (2d->3, 3d->6) int el1,el2; int *elements2d = NULL; - int *vertex_pairing = NULL; - IssmDouble *riftinfo = NULL; /*Get my_rank:*/ int my_rank = IssmComm::GetRank(); int num_procs = IssmComm::GetSize(); - /*Fetch parameters: */ - iomodel->FindConstant(&numrifts,"md.rifts.numrifts"); - /*First, check that partitioning has not yet been carryed out. Just check whether my_elements pointers is not already assigned a value: */ - if(*pmy_elements)return; + if(*pmy_elements) return; /*Number of vertices per elements, needed to correctly retrieve data: */ /*Determine parallel partitioning of elements: we use Metis for now. First load the data, then partition*/ @@ -74,15 +61,19 @@ _error_("mesh elements "<< EnumToStringx(iomodel->meshelementtype) <<" not supported yet"); } + /*Partition and free resouces*/ MeshPartitionx(&epart,&npart,iomodel->numberofelements,iomodel->numberofvertices,iomodel->elements,numberofelements2d,numberofvertices2d,elements2d,numlayers,elements_width,iomodel->meshelementtype,num_procs); - - /*Free elements2d: */ xDelete(elements2d); + xDelete(npart); /*Deal with rifts, they have to be included into one partition only, not several: */ + int numrifts; + iomodel->FindConstant(&numrifts,"md.rifts.numrifts"); if(numrifts){ + IssmDouble *riftinfo = NULL; iomodel->FetchData(&riftinfo,&numrifts,NULL,"md.rifts.riftstruct"); - for(i=0;i(*(riftinfo+RIFTINFOSIZE*i+2))-1; //matlab indexing to c indexing el2=reCast(*(riftinfo+RIFTINFOSIZE*i+3))-1; //matlab indexing to c indexing epart[el2]=epart[el1]; //ensures that this pair of elements will be in the same partition, as well as the corresponding vertices; @@ -90,12 +81,12 @@ iomodel->DeleteData(riftinfo,"md.rifts.riftstruct"); } - /*Used later on: */ - my_vertices=xNewZeroInit(iomodel->numberofvertices); - my_elements=xNewZeroInit(iomodel->numberofelements); + /*Create my_vertices and my_elements, used by each partition */ + bool *my_elements = xNewZeroInit(iomodel->numberofelements); + int *my_vertices = xNewZeroInit(iomodel->numberofvertices); /*Start figuring out, out of the partition, which elements belong to this cpu: */ - for(i=0;inumberofelements;i++){ + for(int i=0;inumberofelements;i++){ /*!All elements have been partitioned above, only deal with elements for this cpu: */ if(my_rank==epart[i]){ @@ -104,7 +95,7 @@ *the element index to do this. For each element n, we know index[n][0:2] holds the indices (matlab indexing) into the vertices coordinates. If we start plugging 1 into my_vertices for each index[n][i] (i=0:2), then my_vertices will hold which vertices belong to this partition*/ - for(j=0;jelements[elements_width*i+j]-1]=1; } } @@ -113,8 +104,9 @@ /*We might have vertex_pairing in which case, some vertices have to be cloned: * penpair has 2 nodes that are poointing toward 2 vertices. * The 2 vertices must be in the same cpu as the penpair*/ + int *vertex_pairing = NULL; iomodel->FetchData(&vertex_pairing,&numvertex_pairing,NULL,"md.stressbalance.vertex_pairing"); - for(i=0;i(vertex_pairing); iomodel->FetchData(&vertex_pairing,&numvertex_pairing,NULL,"md.masstransport.vertex_pairing"); - for(i=0;i(vertex_pairing); - /*Free ressources:*/ - xDelete(npart); + /*cleanup and assign output pointer*/ xDelete(epart); - - /*Assign output pointers:*/ *pmy_elements=my_elements; *pmy_vertices=my_vertices; }