Nektar++
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Private Member Functions | List of all members
Nektar::SpatialDomains::MeshPartitionScotch Class Reference

#include <MeshPartitionScotch.h>

Inheritance diagram for Nektar::SpatialDomains::MeshPartitionScotch:
[legend]

Public Member Functions

 MeshPartitionScotch (const LibUtilities::SessionReaderSharedPtr session, LibUtilities::CommSharedPtr comm, int meshDim, std::map< int, MeshEntity > element, CompositeDescriptor compMap)
 
 ~MeshPartitionScotch () override
 
- Public Member Functions inherited from Nektar::SpatialDomains::MeshPartition
 MeshPartition (const LibUtilities::SessionReaderSharedPtr session, LibUtilities::CommSharedPtr comm, int meshDim, std::map< int, MeshEntity > element, CompositeDescriptor compMap)
 
virtual ~MeshPartition ()
 
void PartitionMesh (int nParts, bool shared=false, bool overlapping=false, int nLocal=0)
 
void PrintPartInfo (std::ostream &out)
 
void GetElementIDs (const int procid, std::vector< unsigned int > &tmp)
 

Static Public Member Functions

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. More...
 

Static Public Attributes

static std::string className
 Name of class. More...
 
static std::string cmdSwitch
 

Protected Member Functions

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
 
- Protected Member Functions inherited from Nektar::SpatialDomains::MeshPartition
void ReadExpansions ()
 
void ReadConditions ()
 
void WeightElements ()
 
void CreateGraph ()
 
void PartitionGraph (int nParts, bool overlapping=false)
 Partition the graph. More...
 
void CheckPartitions (int nParts, Array< OneD, int > &pPart)
 
int CalculateElementWeight (LibUtilities::ShapeType elmtType, bool bndWeight, int na, int nb, int nc)
 
int CalculateEdgeWeight (LibUtilities::ShapeType elmtType, int na, int nb, int nc)
 
virtual 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)=0
 

Private Member Functions

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)
 
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)
 

Additional Inherited Members

- Protected Types inherited from Nektar::SpatialDomains::MeshPartition
typedef std::vector< unsigned int > MultiWeight
 
typedef boost::adjacency_list< boost::setS, boost::vecS, boost::undirectedS, GraphVertexProperties, boost::property< boost::edge_index_t, unsigned int, GraphEdgeProperties > > BoostGraph
 
typedef boost::graph_traits< BoostGraph >::vertex_descriptor BoostVertex
 
typedef boost::graph_traits< BoostGraph >::edge_descriptor BoostEdge
 
typedef boost::graph_traits< BoostGraph >::edge_iterator BoostEdgeIterator
 
typedef boost::graph_traits< BoostGraph >::vertex_iterator BoostVertexIterator
 
typedef boost::graph_traits< BoostGraph >::adjacency_iterator BoostAdjacencyIterator
 
typedef std::vector< unsigned int > NumModes
 
typedef std::map< std::string, NumModesNummodesPerField
 
- Protected Attributes inherited from Nektar::SpatialDomains::MeshPartition
LibUtilities::SessionReaderSharedPtr m_session
 
LibUtilities::CommSharedPtr m_comm
 
int m_dim
 
int m_numFields
 
std::map< int, MeshEntitym_elements
 
std::map< int, MeshEntitym_ghostElmts
 
CompositeDescriptor m_compMap
 
std::map< int, NummodesPerFieldm_expansions
 
std::map< int, LibUtilities::ShapeTypem_shape
 
std::map< std::string, int > m_fieldNameToId
 
std::map< int, MultiWeightm_vertWeights
 
std::map< int, MultiWeightm_vertBndWeights
 
std::map< int, MultiWeightm_edgeWeights
 
BoostGraph m_graph
 
std::map< int, std::vector< unsigned int > > m_localPartition
 
bool m_weightingRequired
 
bool m_weightBnd
 
bool m_weightDofs
 
bool m_shared
 
bool m_parallel
 

Detailed Description

Definition at line 49 of file MeshPartitionScotch.h.

Constructor & Destructor Documentation

◆ MeshPartitionScotch()

Nektar::SpatialDomains::MeshPartitionScotch::MeshPartitionScotch ( const LibUtilities::SessionReaderSharedPtr  session,
LibUtilities::CommSharedPtr  comm,
int  meshDim,
std::map< int, MeshEntity element,
CompositeDescriptor  compMap 
)

Definition at line 49 of file MeshPartitionScotch.cpp.

53 : MeshPartition(session, comm, meshDim, element, compMap)
54{
55}
MeshPartition(const LibUtilities::SessionReaderSharedPtr session, LibUtilities::CommSharedPtr comm, int meshDim, std::map< int, MeshEntity > element, CompositeDescriptor compMap)

◆ ~MeshPartitionScotch()

Nektar::SpatialDomains::MeshPartitionScotch::~MeshPartitionScotch ( )
override

Definition at line 57 of file MeshPartitionScotch.cpp.

58{
59}

Member Function Documentation

◆ create()

static MeshPartitionSharedPtr Nektar::SpatialDomains::MeshPartitionScotch::create ( const LibUtilities::SessionReaderSharedPtr  session,
LibUtilities::CommSharedPtr  comm,
int  meshDim,
std::map< int, MeshEntity element,
CompositeDescriptor  compMap 
)
inlinestatic

Creates an instance of this class.

Definition at line 53 of file MeshPartitionScotch.h.

57 {
59 session, comm, meshDim, element, compMap);
60 }
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.

References Nektar::MemoryManager< DataType >::AllocateSharedPtr().

◆ PartGraph2()

int Nektar::SpatialDomains::MeshPartitionScotch::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 
)
private

Definition at line 219 of file MeshPartitionScotch.cpp.

225{
226 // Scotch graph object to interface with libScotch
227 SCOTCH_Graph *grafdat = SCOTCH_graphAlloc();
228 ASSERTL0(grafdat != nullptr,
229 "Failed to allocate Scotch graph for partitioning.");
230
231 SCOTCH_Strat stradat;
232 SCOTCH_Num baseval;
233 SCOTCH_Num vertnbr;
234 int o;
235
236 ASSERTL0(SCOTCH_graphInit(grafdat) == 0,
237 "Failed to initialise Scotch graph for partitioning.");
238
239 baseval = *numflag;
240 vertnbr = *n;
241
242 o = 1; // Assume something will go wrong
243 if (SCOTCH_graphBuild(grafdat, baseval, vertnbr, xadj, xadj + 1, vwgt,
244 nullptr, xadj[vertnbr] - baseval, adjncy,
245 adjwgt) == 0)
246 {
247 SCOTCH_stratInit(&stradat);
248 SCOTCH_stratGraphMapBuild(&stradat, flagval, *nparts, kbalval);
249#ifdef SCOTCH_DEBUG_ALL
250 // TRICK: next instruction called only if graph is consistent
251 if (SCOTCH_graphCheck(grafdat) == 0)
252#endif /* SCOTCH_DEBUG_ALL */
253 o = SCOTCH_graphPart(grafdat, *nparts, &stradat, part);
254 SCOTCH_stratExit(&stradat);
255 }
256 SCOTCH_graphExit(grafdat);
257
258 if (o != 0)
259 {
260 return (1);
261 }
262
263 if (baseval != 0)
264 { // MeTiS part array is based, Scotch is not
265 SCOTCH_Num vertnum;
266
267 for (vertnum = 0; vertnum < vertnbr; vertnum++)
268 {
269 part[vertnum] += baseval;
270 }
271 }
272
273 return (0);
274}
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208

References ASSERTL0.

Referenced by PartGraphVKway().

◆ PartGraphVKway()

void Nektar::SpatialDomains::MeshPartitionScotch::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 
)
private

Communication volume of current vertex

Definition at line 89 of file MeshPartitionScotch.cpp.

95{
96 SCOTCH_Num baseval;
97 const SCOTCH_Num *vwgt2;
98 const SCOTCH_Num *vsize2;
99 SCOTCH_Num vsizval; /// Communication volume of current vertex
100 SCOTCH_Num vertnbr;
101 SCOTCH_Num vertnum;
102 SCOTCH_Num edgenum;
103 const SCOTCH_Num *edgetax;
104 const SCOTCH_Num *parttax;
105 SCOTCH_Num *nghbtab;
106 SCOTCH_Num commvol;
107
108 vsize2 = ((*wgtflag & 1) != 0) ? vsize : nullptr;
109 vwgt2 = ((*wgtflag & 2) != 0) ? vwgt : nullptr;
110 baseval = *numflag;
111 vertnbr = *n;
112 edgetax = adjncy - baseval;
113
114 // If no communication load data provided
115 if (vsize2 == nullptr)
116 {
117 if (PartGraph2(n, xadj, adjncy, vwgt2, nullptr, numflag, nparts, part,
118 SCOTCH_STRATQUALITY, 0.01) != 0)
119 {
120 return;
121 }
122 }
123
124 // Will have to turn communication volumes into edge loads
125 else
126 {
127 const SCOTCH_Num *vsiztax;
128 SCOTCH_Num edgenbr;
129 SCOTCH_Num *edlotax;
130 int o;
131
132 edgenbr = xadj[vertnbr] - baseval;
133 if ((edlotax = (SCOTCH_Num *)malloc(edgenbr * sizeof(SCOTCH_Num))) ==
134 nullptr)
135 {
136 return;
137 }
138
139 edlotax -= baseval; // Base access to edlotax
140 vsiztax = vsize2 - baseval;
141
142 // Un-based scan of vertex array xadj
143 for (vertnum = 0, edgenum = baseval; vertnum < vertnbr; vertnum++)
144 {
145 SCOTCH_Num vsizval; // Communication size of current vertex
146 SCOTCH_Num edgennd;
147
148 vsizval = vsize2[vertnum];
149 // Based traversal of edge array adjncy
150 for (edgennd = xadj[vertnum + 1]; edgenum < edgennd; edgenum++)
151 {
152
153 SCOTCH_Num vertend; // Based end vertex number
154
155 vertend = edgetax[edgenum];
156 edlotax[edgenum] = vsizval + vsiztax[vertend];
157 }
158 }
159
160 o = PartGraph2(n, xadj, adjncy, vwgt2, edlotax + baseval, numflag,
161 nparts, part, SCOTCH_STRATQUALITY, 0.01);
162
163 free(edlotax + baseval);
164
165 if (o != 0)
166 {
167 return;
168 }
169 }
170
171 if ((nghbtab = (SCOTCH_Num *)malloc(*nparts * sizeof(SCOTCH_Num))) ==
172 nullptr)
173 {
174 return;
175 }
176
177 memset(nghbtab, ~0, *nparts * sizeof(SCOTCH_Num));
178
179 parttax = part - baseval;
180 vsizval = 1; // Assume no vertex communication sizes
181
182 // Un-based scan of vertex array xadj
183 for (vertnum = 0, edgenum = baseval, commvol = 0; vertnum < vertnbr;
184 vertnum++)
185 {
186 SCOTCH_Num partval;
187 SCOTCH_Num edgennd;
188
189 partval = part[vertnum];
190 nghbtab[partval] = vertnum; // Do not count local neighbors in
191 // communication volume
192 if (vsize2 != nullptr)
193 {
194 vsizval = vsize2[vertnum];
195 }
196
197 // Based traversal of edge array adjncy
198 for (edgennd = xadj[vertnum + 1]; edgenum < edgennd; edgenum++)
199 {
200 SCOTCH_Num vertend; // Based end vertex number
201 SCOTCH_Num partend;
202
203 vertend = edgetax[edgenum];
204 partend = parttax[vertend];
205
206 // If first neighbor in this part set part as accounted for
207 if (nghbtab[partend] != vertnum)
208 {
209 nghbtab[partend] = vertnum;
210 commvol += vsizval;
211 }
212 }
213 }
214 *volume = commvol;
215
216 free(nghbtab);
217}
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)

References PartGraph2().

Referenced by v_PartitionGraphImpl().

◆ v_PartitionGraphImpl()

void Nektar::SpatialDomains::MeshPartitionScotch::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 
)
finalprotectedvirtual

Implements Nektar::SpatialDomains::MeshPartition.

Definition at line 61 of file MeshPartitionScotch.cpp.

69{
70 int wgtflag = 0;
71 int *vwgt = nullptr;
72 int *vsize = nullptr;
73 if (vertWgt.size() > 0)
74 {
75 wgtflag += 1;
76 vwgt = &vertWgt[0];
77 }
78 if (vertSize.size() > 0)
79 {
80 wgtflag += 2;
81 vsize = &vertSize[0];
82 }
83 int numflag = 0;
84
85 PartGraphVKway(&nVerts, &xadj[0], &adjcy[0], vwgt, vsize, &wgtflag,
86 &numflag, &nparts, &volume, &part[0]);
87}
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)

References PartGraphVKway().

Member Data Documentation

◆ className

std::string Nektar::SpatialDomains::MeshPartitionScotch::className
static
Initial value:
=
"Partitioning using the Scotch library.")
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
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.
MeshPartitionFactory & GetMeshPartitionFactory()

Name of class.

Definition at line 63 of file MeshPartitionScotch.h.

◆ cmdSwitch

std::string Nektar::SpatialDomains::MeshPartitionScotch::cmdSwitch
static
Initial value:
=
"use-scotch", "", "Use Scotch for mesh partitioning.")
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.

Definition at line 64 of file MeshPartitionScotch.h.