35 #include <boost/core/ignore_unused.hpp>
41 namespace SpatialDomains
48 "Partitioning using the Scotch library.");
52 "use-scotch",
"",
"Use Scotch for mesh partitioning.");
58 std::map<int, MeshEntity> element,
81 boost::ignore_unused(nVertConds, edgeWgt);
86 if (vertWgt.size() > 0)
91 if (vertSize.size() > 0)
99 &wgtflag, &numflag, &nparts, &volume,
105 const SCOTCH_Num *
const n,
106 const SCOTCH_Num *
const xadj,
107 const SCOTCH_Num *
const adjncy,
108 const SCOTCH_Num *
const vwgt,
109 const SCOTCH_Num *
const vsize,
110 const SCOTCH_Num *
const wgtflag,
111 const SCOTCH_Num *
const numflag,
112 const SCOTCH_Num *
const nparts,
113 SCOTCH_Num *
const volume,
114 SCOTCH_Num *
const part)
117 const SCOTCH_Num * vwgt2;
118 const SCOTCH_Num * vsize2;
123 const SCOTCH_Num * edgetax;
124 const SCOTCH_Num * parttax;
125 SCOTCH_Num * nghbtab;
128 vsize2 = ((*wgtflag & 1) != 0) ? vsize : NULL;
129 vwgt2 = ((*wgtflag & 2) != 0) ? vwgt : NULL;
132 edgetax = adjncy - baseval;
135 if (vsize2 == NULL) {
136 if (
PartGraph2 (n, xadj, adjncy, vwgt2, NULL, numflag, nparts,
137 part, SCOTCH_STRATQUALITY, 0.01) != 0)
143 const SCOTCH_Num * vsiztax;
145 SCOTCH_Num * edlotax;
148 edgenbr = xadj[vertnbr] - baseval;
150 (SCOTCH_Num*) malloc (edgenbr *
sizeof (SCOTCH_Num))) == NULL)
156 vsiztax = vsize2 - baseval;
159 for (vertnum = 0, edgenum = baseval;
160 vertnum < vertnbr; vertnum ++) {
164 vsizval = vsize2[vertnum];
166 for (edgennd = xadj[vertnum + 1];
172 vertend = edgetax[edgenum];
173 edlotax[edgenum] = vsizval + vsiztax[vertend];
177 o =
PartGraph2 (n, xadj, adjncy, vwgt2, edlotax + baseval, numflag,
178 nparts, part, SCOTCH_STRATQUALITY, 0.01);
180 free (edlotax + baseval);
187 (SCOTCH_Num*) malloc (*nparts *
sizeof (SCOTCH_Num))) == NULL)
192 memset (nghbtab, ~0, *nparts *
sizeof (SCOTCH_Num));
194 parttax = part - baseval;
198 for (vertnum = 0, edgenum = baseval, commvol = 0;
199 vertnum < vertnbr; vertnum ++) {
203 partval = part[vertnum];
204 nghbtab[partval] = vertnum;
207 vsizval = vsize2[vertnum];
210 for (edgennd = xadj[vertnum + 1]; edgenum < edgennd; edgenum ++) {
214 vertend = edgetax[edgenum];
215 partend = parttax[vertend];
218 if (nghbtab[partend] != vertnum) {
219 nghbtab[partend] = vertnum;
230 const SCOTCH_Num *
const n,
231 const SCOTCH_Num *
const xadj,
232 const SCOTCH_Num *
const adjncy,
233 const SCOTCH_Num *
const vwgt,
234 const SCOTCH_Num *
const adjwgt,
235 const SCOTCH_Num *
const numflag,
236 const SCOTCH_Num *
const nparts,
237 SCOTCH_Num *
const part,
242 SCOTCH_Graph * grafdat = SCOTCH_graphAlloc();
243 SCOTCH_Strat stradat;
248 SCOTCH_graphInit (grafdat);
254 if (SCOTCH_graphBuild (grafdat, baseval, vertnbr, xadj, xadj + 1,
255 vwgt, NULL, xadj[vertnbr] - baseval, adjncy,
257 SCOTCH_stratInit (&stradat);
258 SCOTCH_stratGraphMapBuild (&stradat, flagval, *nparts, kbalval);
259 #ifdef SCOTCH_DEBUG_ALL
261 if (SCOTCH_graphCheck (grafdat) == 0)
263 o = SCOTCH_graphPart (grafdat, *nparts, &stradat, part);
264 SCOTCH_stratExit (&stradat);
266 SCOTCH_graphExit (grafdat);
274 for (vertnum = 0; vertnum < vertnbr; vertnum ++)
275 part[vertnum] += baseval;
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.
virtual ~MeshPartitionScotch()
static std::string className
Name of class.
MeshPartitionScotch(const LibUtilities::SessionReaderSharedPtr session, LibUtilities::CommSharedPtr comm, int meshDim, std::map< int, MeshEntity > element, CompositeDescriptor compMap)
virtual void 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)
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()
The above copyright notice and this permission notice shall be included.