Shrirang Abhyankar avatar Shrirang Abhyankar committed a65702f

dmcircuit: Added circuit partitioning and distribution of data.

Comments (0)

Files changed (1)

src/dm/impls/plex/examples/tutorials/dmcircuit/pf.c

 }
 
 #undef __FUNCT__
+#define __FUNCT__ "PetscCircuitDistribute"
+PetscErrorCode PetscCircuitDistribute(PetscCircuit oldCircuit,PetscCircuit *distCircuit)
+{
+  PetscErrorCode ierr;
+  PetscInt       size;
+  const char*    partitioner="chaco";
+  PetscSF        pointsf;
+
+  PetscFunctionBegin;
+  ierr = MPI_Comm_size(PETSC_COMM_WORLD,&size);CHKERRQ(ierr);
+  if (size == 1) {
+    *distCircuit = (PetscCircuit)NULL;
+    PetscFunctionReturn(0);
+  }
+  PetscCircuit Circuitout;
+  ierr = PetscCircuitCreate(&Circuitout);CHKERRQ(ierr);
+  Circuitout->dataheadersize = sizeof(struct _p_PetscCircuitComponentHeader)/sizeof(DataArrayType);
+  /* Distribute dm */
+  ierr = DMPlexDistribute(oldCircuit->dm,partitioner,0,&pointsf,&Circuitout->dm);CHKERRQ(ierr);
+  /* Distribute dof section */
+  ierr = PetscSectionCreate(PETSC_COMM_WORLD,&Circuitout->DofSection);CHKERRQ(ierr);
+  ierr = PetscSFDistributeSection(pointsf,oldCircuit->DofSection,NULL,Circuitout->DofSection);CHKERRQ(ierr);
+  ierr = PetscSectionCreate(PETSC_COMM_WORLD,&Circuitout->DataSection);CHKERRQ(ierr);
+  /* Distribute data */
+  ierr = DMPlexDistributeData(Circuitout->dm,pointsf,oldCircuit->DataSection,MPI_INT,(void*)oldCircuit->dataarray,Circuitout->DataSection,(void**)&Circuitout->dataarray);CHKERRQ(ierr);
+
+  ierr = PetscSectionGetChart(Circuitout->DataSection,&Circuitout->pStart,&Circuitout->pEnd);CHKERRQ(ierr);
+  ierr = DMPlexGetHeightStratum(Circuitout->dm,0, &Circuitout->eStart,&Circuitout->eEnd);CHKERRQ(ierr);
+  ierr = DMPlexGetHeightStratum(Circuitout->dm,1,&Circuitout->vStart,&Circuitout->vEnd);CHKERRQ(ierr);
+  Circuitout->nEdges = Circuitout->eEnd - Circuitout->eStart;
+  Circuitout->nNodes = Circuitout->vEnd - Circuitout->vStart;
+
+  /* Set Dof section as the default section for dm */
+  ierr = DMSetDefaultSection(Circuitout->dm,Circuitout->DofSection);CHKERRQ(ierr);
+  *distCircuit = Circuitout;
+  PetscFunctionReturn(0);
+}
+
+#undef __FUNCT__
 #define __FUNCT__ "GetListofEdges"
 PetscErrorCode GetListofEdges(PetscInt nbranches, EDGEDATA branch,PetscInt *edges)
 {
       for (j = 0; j < pfdata.bus[i].nload; j++) {
 	ierr = PetscMemcpy(&newload[loadj++],&pfdata.load[pfdata.bus[i].lidx[j]],sizeof(struct _p_LOAD));
       }
-      
     }
     ierr = PetscFree(pfdata.gen);CHKERRQ(ierr);
     ierr = PetscFree(pfdata.load);CHKERRQ(ierr);
   ierr = PetscCircuitComponentSetUp(circuit);CHKERRQ(ierr);
   ierr = PetscCircuitVariablesSetUp(circuit);CHKERRQ(ierr);
 
+  PetscCircuit distributedcircuit=NULL;
+  ierr = PetscCircuitDistribute(circuit,&distributedcircuit);CHKERRQ(ierr);
+  if (distributedcircuit) {
+    circuit = distributedcircuit;
+  }
+
+  ierr = PetscCircuitGetEdgeRange(circuit,&eStart,&eEnd);CHKERRQ(ierr);
+  ierr = PetscCircuitGetVertexRange(circuit,&vStart,&vEnd);CHKERRQ(ierr);
+
   PetscInt numComponents;
   EDGEDATA edge;
   for (i = eStart; i < eEnd; i++) {
     ierr = PetscPrintf(PETSC_COMM_SELF,"Rank %d ncomps = %d Bus %d\n",rank,numComponents,bus->internal_i);CHKERRQ(ierr);
   }    
 
-  
   /* Broadcast Sbase to all processors */
   ierr = MPI_Bcast(&pfdata.sbase,1,MPI_DOUBLE,0,PETSC_COMM_WORLD);CHKERRQ(ierr);
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.