36 #ifndef GRAPH_PARTITION_TOOL_ZOLTAN_H 37 #define GRAPH_PARTITION_TOOL_ZOLTAN_H 1
39 #pragma GCC diagnostic ignored "-Wunused-variable" 40 #pragma GCC diagnostic ignored "-Wunused-parameter" 44 #include <boost/shared_ptr.hpp> 45 #include <boost/lexical_cast.hpp> 46 #include <Epetra_Comm.h> 47 #include <Teuchos_ParameterList.hpp> 50 #pragma GCC diagnostic warning "-Wunused-variable" 51 #pragma GCC diagnostic warning "-Wunused-parameter" 53 #include <lifev/core/LifeV.hpp> 54 #include <lifev/core/mesh/GraphCutterBase.hpp> 55 #include <lifev/core/mesh/GraphUtil.hpp> 90 template<
typename MeshType>
135 return M_partitionTable.find (i)->second;
139 return M_partitionTable.find (i)->second;
148 graph->at (i) = getPart (i);
156 return M_partitionTable.size();
162 return static_cast<UInt> (M_elementList.size() );
168 return M_indexBounds[i];
174 return M_indexBounds[i + 1] - 1;
186 return M_elementList;
192 return M_elementList;
198 return M_elementParts;
204 return M_elementParts;
224 ZOLTAN_ID_PTR globalID, ZOLTAN_ID_PTR localID,
225 int wgt_dim,
float* obj_wgts,
int* ierr);
228 ZOLTAN_ID_PTR globalID,
229 ZOLTAN_ID_PTR localID,
230 int* numEdges,
int* ierr);
232 int num_obj, ZOLTAN_ID_PTR globalID,
233 ZOLTAN_ID_PTR localID,
int* num_edges,
234 ZOLTAN_ID_PTR nborGID,
int* nborProc,
235 int wgt_dim,
float* ewgts,
int* ierr);
237 int num_lid_entries,
int num_ids,
238 ZOLTAN_ID_PTR global_ids,
239 ZOLTAN_ID_PTR local_ids,
240 int* sizes,
int* ierr);
241 static void packObjects (
void* data,
int num_gid_entries,
242 int num_lid_entries,
int num_ids,
243 ZOLTAN_ID_PTR global_ids,
244 ZOLTAN_ID_PTR local_ids,
245 int* dest,
int* sizes,
int* idx,
246 char* buf,
int* ierr);
248 int num_ids, ZOLTAN_ID_PTR global_ids,
249 int* sizes,
int* idx,
char* buf,
int* ierr);
272 ZOLTAN_ID_PTR exportLocalGids,
273 int* exportProcs,
int* exportToPart);
312 template<
typename MeshType>
330 template<
typename MeshType>
335 M_parameters.set (
"num-parts",
static_cast<Int> (M_comm->NumProc() ),
336 "The desired number of parts");
337 M_parameters.set (
"topology",
"1",
338 "The topology of the mesh partition process.");
339 M_parameters.set (
"debug_level", 0,
"Verbosity of Zoltan");
340 M_parameters.set (
"hier_debug_level", 0,
"Verbosity (hier. partition)");
341 M_parameters.set (
"lb_method",
"GRAPH",
342 "Graph partition method: GRAPH or HIER");
343 M_parameters.set (
"lb_approach",
"PARTITION",
344 "Partition approach: PARTITION or REPARTITION");
346 M_parameters.setParameters (parameters);
348 M_numParts = M_parameters.get<Int> (
"num-parts");
352 template<
typename MeshType>
366 template<
typename MeshType>
372 return object->numStoredElements();
375 template<
typename MeshType>
379 ZOLTAN_ID_PTR globalID,
380 ZOLTAN_ID_PTR localID,
388 for (
UInt i = 0; i < object->numStoredElements(); ++i)
390 globalID[i] = object->elementList() [i];
398 template<
typename MeshType>
403 ZOLTAN_ID_PTR globalID,
410 for (
int element = 0; element < num_obj; ++element)
413 = object->graph().find (globalID[element])->second->size();
419 template<
typename MeshType>
424 ZOLTAN_ID_PTR globalID,
427 ZOLTAN_ID_PTR nborGID,
435 std::vector<Int>::const_iterator iter;
437 for (
int element = 0; element < num_obj; ++element)
439 iter = object->graph().find (globalID[element])->second->begin();
440 for (
int k = 0; k < num_edges[element]; ++k)
442 nborGID[pos] = *iter;
444 for (
int i = 0; i < object->numProcessors(); ++i)
447 if (ie >= object->firstIndex (i)
449 ie <= object->lastIndex (i) )
464 template<
typename MeshType>
467 int num_ids, ZOLTAN_ID_PTR , ZOLTAN_ID_PTR ,
468 int* sizes,
int* ierr)
471 for (
int i = 0; i < num_ids; ++i)
473 sizes[i] = sizeOfBuffer;
479 template<
typename MeshType>
484 ZOLTAN_ID_PTR global_ids,
485 ZOLTAN_ID_PTR local_ids,
495 for (
int i = 0; i < num_ids; ++i)
498 buffer->gid = global_ids[i];
503 object->elementList() [local_ids[i]] = -1;
504 object->elementParts() [local_ids[i]] = -1;
510 template<
typename MeshType>
523 for (
int i = 0; i < num_ids; ++i)
526 object->elementList().push_back (buffer
->gid);
527 object->elementParts().push_back (buffer
->part);
537 template<
typename MeshType>
553 template<
typename MeshType>
560 Int k = M_mesh->numElements();
562 M_indexBounds.resize (M_numProcessors + 1);
563 M_indexBounds[0] = 0;
568 M_indexBounds[i + 1] = M_indexBounds[i] + l;
572 M_elementList.resize (M_indexBounds[M_myPID + 1] - M_indexBounds[M_myPID]);
576 M_elementList[i] = startIndex + i;
579 M_elementParts.resize (numStoredElements() );
582 std::vector<Int> partitionBounds (M_numPartsPerProcessor + 1);
583 partitionBounds[0] = 0;
587 partitionBounds[i + 1] = partitionBounds[i] + l;
592 for (Int lid = partitionBounds[i];
593 lid < partitionBounds[i + 1]; ++lid)
595 M_elementParts[lid] = M_myFirstPart + i;
600 Int numDimensions = MeshType::elementShape_Type::S_nDimensions;
602 switch (numDimensions)
615 UInt numElementFacets = MeshType::elementShape_Type::S_numFacets;
619 UInt ie = M_elementList[i];
620 M_graph.insert (std::pair<Int, idListPtr_Type >
621 (ie, idListPtr_Type() )
624 M_graph[ie]->reserve (numNeighbours);
625 for (
UInt ifacet = 0; ifacet < numElementFacets; ++ifacet)
627 UInt facet = M_mesh->localFacetId (ie, ifacet);
628 UInt elem = M_mesh->facet (facet).firstAdjacentElementIdentity();
631 elem = M_mesh->facet (facet).secondAdjacentElementIdentity();
641 template<
typename MeshType>
643 ZOLTAN_ID_PTR exportLocalGids,
647 for (
int i = 0; i < numExport; ++i)
652 if (M_elementParts[exportLocalGids[i]] != exportToPart[i])
654 M_elementParts[exportLocalGids[i]] = exportToPart[i];
660 template<
typename MeshType>
663 for (table_Type::iterator it = M_partitionTable.begin();
664 it != M_partitionTable.end(); ++it)
667 it->second->reserve (numStoredElements() / M_numPartsPerProcessor);
673 if (
static_cast<Int> (M_elementList[i]) != -1)
675 M_partitionTable[M_elementParts[i]]->push_back (M_elementList[i]);
678 for (table_Type::iterator it = M_partitionTable.begin();
679 it != M_partitionTable.end(); ++it)
681 std::sort (it->second->begin(), it->second->end() );
695 M_comm->Broadcast (¤tSize, 1, i);
700 M_comm->Broadcast (& (M_partitionTable[i]->at (0) ), currentSize, i);
705 template<
typename MeshType>
711 std::shared_ptr<Epetra_MpiComm> mpiComm
712 = std::dynamic_pointer_cast<Epetra_MpiComm> (M_comm);
714 Zoltan_Initialize (argc, &argv, &ver);
715 M_zoltanStruct = Zoltan_Create (mpiComm->Comm() );
717 int debug_level = M_parameters.get<
int> (
"debug_level");
718 int hier_debug_level = M_parameters.get<
int> (
"hier_debug_level");
719 Zoltan_Set_Param (M_zoltanStruct,
721 std::to_string (debug_level).c_str() );
723 Zoltan_Set_Param (M_zoltanStruct,
725 std::to_string (hier_debug_level).c_str() );
727 Zoltan_Set_Param (M_zoltanStruct,
"LB_METHOD",
728 M_parameters.get<std::string> (
"lb_method").c_str() );
730 Zoltan_Set_Param (M_zoltanStruct,
"LB_APPROACH",
731 M_parameters.get<std::string> (
"lb_approach").c_str() );
743 Zoltan_Set_Param (
M_zoltanStruct,
"MIGRATE_ONLY_PROC_CHANGES",
"1");
744 Zoltan_Set_Param (M_zoltanStruct,
"TOPOLOGY",
745 M_parameters.get<std::string> (
"topology").c_str() );
746 Zoltan_Set_Param (M_zoltanStruct,
"NUM_GLOBAL_PARTS",
748 (M_numParts) ).c_str() );
749 Zoltan_Set_Param (M_zoltanStruct,
"NUM_LOCAL_PARTS",
751 (M_numPartsPerProcessor) ).c_str() );
756 Zoltan_Set_Obj_List_Fn (M_zoltanStruct,
757 GraphCutterZoltan::getElementList,
759 Zoltan_Set_Num_Edges_Multi_Fn (M_zoltanStruct,
760 GraphCutterZoltan::getNumNeighboursList,
762 Zoltan_Set_Edge_List_Multi_Fn (M_zoltanStruct,
763 GraphCutterZoltan::getNeighbourList,
765 Zoltan_Set_Obj_Size_Multi_Fn (M_zoltanStruct,
766 GraphCutterZoltan::getTransferObjectSizes,
768 Zoltan_Set_Pack_Obj_Multi_Fn (M_zoltanStruct,
769 GraphCutterZoltan::packObjects,
771 Zoltan_Set_Unpack_Obj_Multi_Fn (M_zoltanStruct,
772 GraphCutterZoltan::unpackObjects,
775 int changes, numGidEntries, numLidEntries, numImport, numExport;
776 ZOLTAN_ID_PTR importGlobalGids, importLocalGids;
777 ZOLTAN_ID_PTR exportGlobalGids, exportLocalGids;
778 int* importProcs, *importToPart, *exportProcs, *exportToPart;
781 Zoltan_LB_Partition (M_zoltanStruct,
798 localMigrate (numExport, exportLocalGids, exportProcs, exportToPart);
808 Zoltan_Migrate (M_zoltanStruct,
821 Zoltan_LB_Free_Part (&importGlobalGids, &importLocalGids,
822 &importProcs, &importToPart);
823 Zoltan_LB_Free_Part (&exportGlobalGids, &exportLocalGids,
824 &exportProcs, &exportToPart);
GraphCutterZoltan & operator=(const GraphCutterZoltan &)
This structure is used to pack objects in the Zoltan migration phase.
Int myPID() const
The PID of the process.
std::vector< Int > & elementParts()
The vector of stored element partitions (non-const)
std::map< Int, idListPtr_Type > table_Type
std::vector< Int > M_elementList
virtual const idTablePtr_Type getGraph() const
Get the entire partitioned graph, wrapped in a smart pointer.
Graph cutter base class (abstract)
int32_type Int
Generic integer data.
static void getElementList(void *data, int sizeGID, int sizeLID, ZOLTAN_ID_PTR globalID, ZOLTAN_ID_PTR localID, int wgt_dim, float *obj_wgts, int *ierr)
void distributePartitions()
Distribute the partitions among available processors.
virtual const idListPtr_Type & getPart(const UInt i) const
Get a pointer to one of the parts.
static void unpackObjects(void *data, int num_gid_entries, int num_ids, ZOLTAN_ID_PTR global_ids, int *sizes, int *idx, char *buf, int *ierr)
void updateInverseJacobian(const UInt &iQuadPt)
GraphCutterZoltan(const GraphCutterZoltan &)
Int M_numPartsPerProcessor
void buildPartitionTable()
Build the partition table that can be exported to the mesh builder.
Teuchos::ParameterList pList_Type
std::vector< Int > M_elementParts
std::vector< LifeV::Int > idList_Type
virtual const UInt numParts() const
Return the number of parts.
Int numProcessors() const
The number of processes in the comm.
Int firstIndex(const Int i) const
First global index that is initially assigned to process i.
const std::vector< Int > & elementParts() const
The vector of stored element partitions.
table_Type M_partitionTable
void localMigrate(int numExport, ZOLTAN_ID_PTR exportLocalGids, int *exportProcs, int *exportToPart)
Migrate elements between locally stored partitions.
GraphCutterZoltan(meshPtr_Type &mesh, commPtr_Type &comm, pList_Type ¶meters)
std::vector< Int > M_indexBounds
UInt numStoredElements() const
Get number of stored graph elements.
std::vector< Int > & elementList()
The vector of stored element GIDs (non-const)
void buildGraph()
Build the dual graph of the unpartitioned mesh.
static void getNumNeighboursList(void *data, int sizeGID, int sizeLID, int num_obj, ZOLTAN_ID_PTR globalID, ZOLTAN_ID_PTR localID, int *numEdges, int *ierr)
virtual Int run()
Performs the graph partitioning.
Class that partitions the graph associated with a mesh.
virtual void setParameters(pList_Type ¶meters)
Set values for all the parameters, with default values where needed.
static void getNeighbourList(void *data, int sizeGID, int sizeLID, int num_obj, ZOLTAN_ID_PTR globalID, ZOLTAN_ID_PTR localID, int *num_edges, ZOLTAN_ID_PTR nborGID, int *nborProc, int wgt_dim, float *ewgts, int *ierr)
std::shared_ptr< idTable_Type > idTablePtr_Type
Int lastIndex(const Int i) const
Last global index that is initially assigned to process i.
static int getNumElements(void *data, int *ierr)
static void packObjects(void *data, int num_gid_entries, int num_lid_entries, int num_ids, ZOLTAN_ID_PTR global_ids, ZOLTAN_ID_PTR local_ids, int *dest, int *sizes, int *idx, char *buf, int *ierr)
void partitionGraph()
Partition the graph.
struct Zoltan_Struct * M_zoltanStruct
virtual idListPtr_Type & getPart(const UInt i)
std::shared_ptr< Epetra_Comm > commPtr_Type
const std::vector< Int > & elementList() const
The vector of stored element GIDs.
uint32_type UInt
generic unsigned integer (used mainly for addressing)
const table_Type & graph() const
The internally stored dual graph of the mesh.
virtual ~GraphCutterZoltan()
Destructor.
std::shared_ptr< idList_Type > idListPtr_Type
static void getTransferObjectSizes(void *data, int num_gid_entries, int num_lid_entries, int num_ids, ZOLTAN_ID_PTR global_ids, ZOLTAN_ID_PTR local_ids, int *sizes, int *ierr)
std::shared_ptr< mesh_Type > meshPtr_Type