43 "Partitioning using the Scotch library.");
47 "use-scotch",
"",
"Use Scotch for mesh partitioning.");
62 int &nVerts, [[maybe_unused]]
int &nVertConds,
73 if (vertWgt.size() > 0)
78 if (vertSize.size() > 0)
85 PartGraphVKway(&nVerts, &xadj[0], &adjcy[0], vwgt, vsize, &wgtflag,
86 &numflag, &nparts, &volume, &part[0]);
90 const SCOTCH_Num *
const n,
const SCOTCH_Num *
const xadj,
91 const SCOTCH_Num *
const adjncy,
const SCOTCH_Num *
const vwgt,
92 const SCOTCH_Num *
const vsize,
const SCOTCH_Num *
const wgtflag,
93 const SCOTCH_Num *
const numflag,
const SCOTCH_Num *
const nparts,
94 SCOTCH_Num *
const volume, SCOTCH_Num *
const part)
97 const SCOTCH_Num *vwgt2;
98 const SCOTCH_Num *vsize2;
103 const SCOTCH_Num *edgetax;
104 const SCOTCH_Num *parttax;
108 vsize2 = ((*wgtflag & 1) != 0) ? vsize :
nullptr;
109 vwgt2 = ((*wgtflag & 2) != 0) ? vwgt :
nullptr;
112 edgetax = adjncy - baseval;
115 if (vsize2 ==
nullptr)
117 if (
PartGraph2(n, xadj, adjncy, vwgt2,
nullptr, numflag, nparts, part,
118 SCOTCH_STRATQUALITY, 0.01) != 0)
127 const SCOTCH_Num *vsiztax;
132 edgenbr = xadj[vertnbr] - baseval;
133 if ((edlotax = (SCOTCH_Num *)malloc(edgenbr *
sizeof(SCOTCH_Num))) ==
140 vsiztax = vsize2 - baseval;
143 for (vertnum = 0, edgenum = baseval; vertnum < vertnbr; vertnum++)
148 vsizval = vsize2[vertnum];
150 for (edgennd = xadj[vertnum + 1]; edgenum < edgennd; edgenum++)
155 vertend = edgetax[edgenum];
156 edlotax[edgenum] = vsizval + vsiztax[vertend];
160 o =
PartGraph2(n, xadj, adjncy, vwgt2, edlotax + baseval, numflag,
161 nparts, part, SCOTCH_STRATQUALITY, 0.01);
163 free(edlotax + baseval);
171 if ((nghbtab = (SCOTCH_Num *)malloc(*nparts *
sizeof(SCOTCH_Num))) ==
177 memset(nghbtab, ~0, *nparts *
sizeof(SCOTCH_Num));
179 parttax = part - baseval;
183 for (vertnum = 0, edgenum = baseval, commvol = 0; vertnum < vertnbr;
189 partval = part[vertnum];
190 nghbtab[partval] = vertnum;
192 if (vsize2 !=
nullptr)
194 vsizval = vsize2[vertnum];
198 for (edgennd = xadj[vertnum + 1]; edgenum < edgennd; edgenum++)
203 vertend = edgetax[edgenum];
204 partend = parttax[vertend];
207 if (nghbtab[partend] != vertnum)
209 nghbtab[partend] = vertnum;
220 const SCOTCH_Num *
const n,
const SCOTCH_Num *
const xadj,
221 const SCOTCH_Num *
const adjncy,
const SCOTCH_Num *
const vwgt,
222 const SCOTCH_Num *
const adjwgt,
const SCOTCH_Num *
const numflag,
223 const SCOTCH_Num *
const nparts, SCOTCH_Num *
const part, SCOTCH_Num flagval,
227 SCOTCH_Graph *grafdat = SCOTCH_graphAlloc();
229 "Failed to allocate Scotch graph for partitioning.");
231 SCOTCH_Strat stradat;
236 ASSERTL0(SCOTCH_graphInit(grafdat) == 0,
237 "Failed to initialise Scotch graph for partitioning.");
243 if (SCOTCH_graphBuild(grafdat, baseval, vertnbr, xadj, xadj + 1, vwgt,
244 nullptr, xadj[vertnbr] - baseval, adjncy,
247 SCOTCH_stratInit(&stradat);
248 SCOTCH_stratGraphMapBuild(&stradat, flagval, *nparts, kbalval);
249#ifdef SCOTCH_DEBUG_ALL
251 if (SCOTCH_graphCheck(grafdat) == 0)
253 o = SCOTCH_graphPart(grafdat, *nparts, &stradat, part);
254 SCOTCH_stratExit(&stradat);
256 SCOTCH_graphExit(grafdat);
267 for (vertnum = 0; vertnum < vertnbr; vertnum++)
269 part[vertnum] += baseval;
#define ASSERTL0(condition, msg)
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
static std::string RegisterCmdLineFlag(const std::string &pName, const std::string &pShortName, const std::string &pDescription)
Registers a command-line flag with the session reader.
static MeshPartitionSharedPtr create(const LibUtilities::SessionReaderSharedPtr session, LibUtilities::CommSharedPtr comm, int meshDim, std::map< int, MeshEntity > element, CompositeDescriptor compMap)
Creates an instance of this class.
void v_PartitionGraphImpl(int &nVerts, int &nVertConds, Nektar::Array< Nektar::OneD, int > &xadj, Nektar::Array< Nektar::OneD, int > &adjcy, Nektar::Array< Nektar::OneD, int > &vertWgt, Nektar::Array< Nektar::OneD, int > &vertSize, Nektar::Array< Nektar::OneD, int > &edgeWgt, int &nparts, int &volume, Nektar::Array< Nektar::OneD, int > &part) final
static std::string className
Name of class.
MeshPartitionScotch(const LibUtilities::SessionReaderSharedPtr session, LibUtilities::CommSharedPtr comm, int meshDim, std::map< int, MeshEntity > element, CompositeDescriptor compMap)
int PartGraph2(const SCOTCH_Num *const n, const SCOTCH_Num *const xadj, const SCOTCH_Num *const adjncy, const SCOTCH_Num *const vwgt, const SCOTCH_Num *const adjwgt, const SCOTCH_Num *const numflag, const SCOTCH_Num *const nparts, SCOTCH_Num *const part, SCOTCH_Num flagval, double kbalval)
static std::string cmdSwitch
~MeshPartitionScotch() override
void PartGraphVKway(const SCOTCH_Num *const n, const SCOTCH_Num *const xadj, const SCOTCH_Num *const adjncy, const SCOTCH_Num *const vwgt, const SCOTCH_Num *const vsize, const SCOTCH_Num *const wgtflag, const SCOTCH_Num *const numflag, const SCOTCH_Num *const nparts, SCOTCH_Num *const volume, SCOTCH_Num *const part)
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
std::map< int, std::pair< LibUtilities::ShapeType, std::vector< int > > > CompositeDescriptor
MeshPartitionFactory & GetMeshPartitionFactory()