44 "Partitioning using the Scotch library.");
48 "use-scotch",
"",
"Use Scotch for mesh partitioning.");
59 int &nVerts, [[maybe_unused]]
int &nVertConds,
71 std::set<unsigned> isolated;
72 for (
int i = 0; i < nVerts; ++i)
74 if (xadj[i] == xadj[i + 1])
83 for (
auto i : isolated)
86 Vmath::Vcopy(nVerts - i, xadj + i + 1, 1, tmp = xadj + i, 1);
94 if (vertWgt.size() > 0)
99 if (vertSize.size() > 0)
102 vsize = &vertSize[0];
106 PartGraphVKway(&nVerts, &xadj[0], &adjcy[0], vwgt, vsize, &wgtflag,
107 &numflag, &nparts, &volume, &part[0]);
114 for (
auto i : isolated)
119 Vmath::Vcopy(nVerts - i, part + i, 1, tmp = part + i + 1, 1);
121 part[i] = topart % nparts;
129 const SCOTCH_Num *
const n,
const SCOTCH_Num *
const xadj,
130 const SCOTCH_Num *
const adjncy,
const SCOTCH_Num *
const vwgt,
131 const SCOTCH_Num *
const vsize,
const SCOTCH_Num *
const wgtflag,
132 const SCOTCH_Num *
const numflag,
const SCOTCH_Num *
const nparts,
133 SCOTCH_Num *
const volume, SCOTCH_Num *
const part)
136 const SCOTCH_Num *vwgt2;
137 const SCOTCH_Num *vsize2;
142 const SCOTCH_Num *edgetax;
143 const SCOTCH_Num *parttax;
147 vsize2 = ((*wgtflag & 1) != 0) ? vsize :
nullptr;
148 vwgt2 = ((*wgtflag & 2) != 0) ? vwgt :
nullptr;
151 edgetax = adjncy - baseval;
154 if (vsize2 ==
nullptr)
156 if (
PartGraph2(n, xadj, adjncy, vwgt2,
nullptr, numflag, nparts, part,
157 SCOTCH_STRATQUALITY, 0.01) != 0)
166 const SCOTCH_Num *vsiztax;
171 edgenbr = xadj[vertnbr] - baseval;
172 if ((edlotax = (SCOTCH_Num *)malloc(edgenbr *
sizeof(SCOTCH_Num))) ==
179 vsiztax = vsize2 - baseval;
182 for (vertnum = 0, edgenum = baseval; vertnum < vertnbr; vertnum++)
187 vsizval = vsize2[vertnum];
189 for (edgennd = xadj[vertnum + 1]; edgenum < edgennd; edgenum++)
194 vertend = edgetax[edgenum];
195 edlotax[edgenum] = vsizval + vsiztax[vertend];
199 o =
PartGraph2(n, xadj, adjncy, vwgt2, edlotax + baseval, numflag,
200 nparts, part, SCOTCH_STRATQUALITY, 0.01);
202 free(edlotax + baseval);
210 if ((nghbtab = (SCOTCH_Num *)malloc(*nparts *
sizeof(SCOTCH_Num))) ==
216 memset(nghbtab, ~0, *nparts *
sizeof(SCOTCH_Num));
218 parttax = part - baseval;
222 for (vertnum = 0, edgenum = baseval, commvol = 0; vertnum < vertnbr;
228 partval = part[vertnum];
229 nghbtab[partval] = vertnum;
231 if (vsize2 !=
nullptr)
233 vsizval = vsize2[vertnum];
237 for (edgennd = xadj[vertnum + 1]; edgenum < edgennd; edgenum++)
242 vertend = edgetax[edgenum];
243 partend = parttax[vertend];
246 if (nghbtab[partend] != vertnum)
248 nghbtab[partend] = vertnum;
259 const SCOTCH_Num *
const n,
const SCOTCH_Num *
const xadj,
260 const SCOTCH_Num *
const adjncy,
const SCOTCH_Num *
const vwgt,
261 const SCOTCH_Num *
const adjwgt,
const SCOTCH_Num *
const numflag,
262 const SCOTCH_Num *
const nparts, SCOTCH_Num *
const part, SCOTCH_Num flagval,
266 SCOTCH_Graph *grafdat = SCOTCH_graphAlloc();
268 "Failed to allocate Scotch graph for partitioning.");
270 SCOTCH_Strat stradat;
275 ASSERTL0(SCOTCH_graphInit(grafdat) == 0,
276 "Failed to initialise Scotch graph for partitioning.");
282 if (SCOTCH_graphBuild(grafdat, baseval, vertnbr, xadj, xadj + 1, vwgt,
283 nullptr, xadj[vertnbr] - baseval, adjncy,
286 SCOTCH_stratInit(&stradat);
287 SCOTCH_stratGraphMapBuild(&stradat, flagval, *nparts, kbalval);
288#ifdef SCOTCH_DEBUG_ALL
290 if (SCOTCH_graphCheck(grafdat) == 0)
292 o = SCOTCH_graphPart(grafdat, *nparts, &stradat, part);
293 SCOTCH_stratExit(&stradat);
295 SCOTCH_graphExit(grafdat);
306 for (vertnum = 0; vertnum < vertnbr; vertnum++)
308 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
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()
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)