36 #define GRAPH_UTIL_H 1
42 #include <boost/shared_ptr.hpp> 43 #include <boost/bimap.hpp> 44 #include <Epetra_MpiComm.h> 45 #include <Epetra_SerialComm.h> 46 #include <Epetra_BlockMap.h> 47 #include <Epetra_CrsGraph.h> 48 #include <Teuchos_ParameterList.hpp> 49 #include <Teuchos_RCP.hpp> 51 #include <lifev/core/LifeV.hpp> 90 template <
typename MeshType>
93 const Teuchos::ParameterList& params,
97 template <
typename MeshType>
100 const Teuchos::ParameterList& params,
104 Int numProc = comm->NumProc();
105 Int myPID = comm->MyPID();
109 UInt numVertices = vertexList->size();
111 for (
UInt i = 0; i < numVertices; ++i)
113 vertexIdMap.insert (biMapValue_Type (i, vertexList->at (i) ) );
119 std::vector<Int> vertexDistribution (numProc + 1);
120 vertexDistribution[0] = 0;
121 UInt k = numVertices;
123 for (
Int i = 0; i < numProc; ++i)
125 UInt l = k / (numProc - i);
126 vertexDistribution[i + 1] = vertexDistribution[i] + l;
138 std::vector<Int> vertexLocations (vertexDistribution[numProc]
139 - vertexDistribution[0], numProc);
140 UInt localStart = vertexDistribution[myPID];
141 UInt localEnd = vertexDistribution[myPID + 1];
146 std::vector<Int> graphEdgeWeights;
147 std::vector<Int> adjacencyGraphKeys (1, 0);
148 std::vector<Int> adjacencyGraphValues (0);
152 UInt elementFacets = MeshType::elementShape_Type::S_numFacets;
154 for (
UInt lid = localStart; lid < localEnd; ++lid)
156 for (
UInt ifacet = 0; ifacet < elementFacets; ++ifacet)
158 UInt gid = vertexIdMap.left.at (lid);
160 UInt facet = mesh.localFacetId (gid, ifacet);
162 UInt elem = mesh.facet (facet).firstAdjacentElementIdentity();
165 elem = mesh.facet (facet).secondAdjacentElementIdentity();
167 biMap_Type::right_const_iterator it = vertexIdMap.right.find (elem);
169 bool inSubGraph = (vertexIdMap.right.end() != it);
170 if ( (elem !=
NotAnId) && (inSubGraph) )
175 adjacencyGraphValues.push_back (it->second);
182 adjacencyGraphKeys.push_back (sum);
188 Int* weightVector = 0;
195 Int options[3] = {1, 3, 1};
199 Int numParts = params.get<Int> (
"num-parts");
200 std::vector<
float> tpwgts (ncon * numParts, 1. / numParts);
202 std::vector<
float> ubvec (ncon, 1.05);
204 std::shared_ptr<Epetra_MpiComm> mpiComm
205 = std::dynamic_pointer_cast <Epetra_MpiComm> (comm);
206 MPI_Comm MPIcomm = mpiComm->Comm();
209 if (graphEdgeWeights.size() > 0)
211 adjwgtPtr =
static_cast<Int*> (&graphEdgeWeights[0]);
213 ParMETIS_V3_PartKway (
static_cast<Int*> (&vertexDistribution[0]),
214 static_cast<Int*> (&adjacencyGraphKeys[0]),
215 static_cast<Int*> (&adjacencyGraphValues[0]),
216 weightVector, adjwgtPtr, &weightFlag, &numflag,
217 &ncon, &numParts, &tpwgts[0], &ubvec[0],
218 &options[0], &cutGraphEdges,
219 &vertexLocations[localStart],
227 for (
Int proc = 0; proc < numProc; proc++)
229 UInt procStart = vertexDistribution[proc];
230 UInt procLength = vertexDistribution[proc + 1]
231 - vertexDistribution[proc];
232 comm->Broadcast (&vertexLocations[procStart], procLength, proc);
238 for (
Int i = 0; i < numParts; ++i)
240 vertexIds->at (i).reset (
new idList_Type (0) );
241 vertexIds->at (i)->reserve (vertexLocations.size() / numParts);
243 for (UInt ii = 0; ii < vertexLocations.size(); ++ii)
246 vertexIds->at (vertexLocations[ii])->push_back (vertexIdMap.left.at (ii) );
249 vertexPartition = vertexIds;
biMap_Type::value_type biMapValue_Type
std::set< Int > idSet_Type
std::shared_ptr< Epetra_Comm > commPtr_Type
std::vector< idListPtr_Type > idTable_Type
int32_type Int
Generic integer data.
void updateInverseJacobian(const UInt &iQuadPt)
std::vector< LifeV::Int > idList_Type
void partitionGraphParMETIS(const idListPtr_Type &vertexList, const MeshType &mesh, const Teuchos::ParameterList ¶ms, idTablePtr_Type &vertexPartition, commPtr_Type &comm)
Function that partitions a graph of a subset of elements in a mesh.
std::vector< idSetPtr_Type > idSetGroup_Type
boost::bimap< LifeV::UInt, LifeV::UInt > biMap_Type
std::shared_ptr< idSetGroup_Type > idSetGroupPtr_Type
std::shared_ptr< idSet_Type > idSetPtr_Type
std::shared_ptr< idTable_Type > idTablePtr_Type
uint32_type UInt
generic unsigned integer (used mainly for addressing)
std::shared_ptr< idList_Type > idListPtr_Type