Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | List of all members
Nektar::LibUtilities::MeshPartitionScotch Class Reference

#include <MeshPartitionScotch.h>

Inheritance diagram for Nektar::LibUtilities::MeshPartitionScotch:
Inheritance graph
[legend]
Collaboration diagram for Nektar::LibUtilities::MeshPartitionScotch:
Collaboration graph
[legend]

Public Member Functions

 MeshPartitionScotch (const SessionReaderSharedPtr &pSession)
 
virtual ~MeshPartitionScotch ()
 
- Public Member Functions inherited from Nektar::LibUtilities::MeshPartition
 MeshPartition (const SessionReaderSharedPtr &pSession)
 
virtual ~MeshPartition ()
 
void PartitionMesh (int nParts, bool shared=false, bool overlapping=false)
 
void WriteLocalPartition (SessionReaderSharedPtr &pSession)
 
void WriteAllPartitions (SessionReaderSharedPtr &pSession)
 
void PrintPartInfo (std::ostream &out)
 
void GetCompositeOrdering (CompositeOrdering &composites)
 
void GetBndRegionOrdering (BndRegionOrdering &composites)
 
void GetElementIDs (const int procid, std::vector< unsigned int > &tmp)
 

Static Public Member Functions

static MeshPartitionSharedPtr create (const SessionReaderSharedPtr &pSession)
 Creates an instance of this class. More...
 

Static Public Attributes

static std::string className
 Name of class. More...
 
static std::string cmdSwitch = SessionReader::RegisterCmdLineFlag("use-scotch","","Use Scotch for mesh partitioning.")
 

Private Member Functions

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)
 
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, const SCOTCH_Num *const options, 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)
 

Detailed Description

Definition at line 49 of file MeshPartitionScotch.h.

Constructor & Destructor Documentation

Nektar::LibUtilities::MeshPartitionScotch::MeshPartitionScotch ( const SessionReaderSharedPtr pSession)

Definition at line 55 of file MeshPartitionScotch.cpp.

56  : MeshPartition(pSession)
57  {
58 
59  }
MeshPartition(const SessionReaderSharedPtr &pSession)
Nektar::LibUtilities::MeshPartitionScotch::~MeshPartitionScotch ( )
virtual

Definition at line 61 of file MeshPartitionScotch.cpp.

62  {
63 
64  }

Member Function Documentation

static MeshPartitionSharedPtr Nektar::LibUtilities::MeshPartitionScotch::create ( const SessionReaderSharedPtr pSession)
inlinestatic

Creates an instance of this class.

Definition at line 53 of file MeshPartitionScotch.h.

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

55  {
57  ::AllocateSharedPtr(pSession);
58  }
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
int Nektar::LibUtilities::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 228 of file MeshPartitionScotch.cpp.

Referenced by PartGraphVKway().

239  {
240  // Scotch graph object to interface with libScotch
241  SCOTCH_Graph grafdat;
242  SCOTCH_Strat stradat;
243  SCOTCH_Num baseval;
244  SCOTCH_Num vertnbr;
245  int o;
246 
247  SCOTCH_graphInit (&grafdat);
248 
249  baseval = *numflag;
250  vertnbr = *n;
251 
252  o = 1; // Assume something will go wrong
253  if (SCOTCH_graphBuild (&grafdat, baseval, vertnbr, xadj, xadj + 1,
254  vwgt, NULL, xadj[vertnbr] - baseval, adjncy,
255  adjwgt) == 0) {
256  SCOTCH_stratInit (&stradat);
257  SCOTCH_stratGraphMapBuild (&stradat, flagval, *nparts, kbalval);
258 #ifdef SCOTCH_DEBUG_ALL
259  // TRICK: next instruction called only if graph is consistent
260  if (SCOTCH_graphCheck (&grafdat) == 0)
261 #endif /* SCOTCH_DEBUG_ALL */
262  o = SCOTCH_graphPart (&grafdat, *nparts, &stradat, part);
263  SCOTCH_stratExit (&stradat);
264  }
265  SCOTCH_graphExit (&grafdat);
266 
267  if (o != 0)
268  return (1);
269 
270  if (baseval != 0) { // MeTiS part array is based, Scotch is not
271  SCOTCH_Num vertnum;
272 
273  for (vertnum = 0; vertnum < vertnbr; vertnum ++)
274  part[vertnum] += baseval;
275  }
276 
277  return (0);
278  }
void Nektar::LibUtilities::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,
const SCOTCH_Num *const  options,
SCOTCH_Num *const  volume,
SCOTCH_Num *const  part 
)
private

Communication volume of current vertex

Definition at line 102 of file MeshPartitionScotch.cpp.

References PartGraph2().

Referenced by PartitionGraphImpl().

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

Implements Nektar::LibUtilities::MeshPartition.

Definition at line 66 of file MeshPartitionScotch.cpp.

References PartGraphVKway().

77  {
78  int wgtflag = 0;
79  int *vwgt = 0;
80  int *vsize = 0;
81  if (vertWgt.num_elements() > 0)
82  {
83  wgtflag += 1;
84  vwgt = &vertWgt[0];
85  }
86  if (vertSize.num_elements() > 0)
87  {
88  wgtflag += 2;
89  vsize = &vertSize[0];
90  }
91  int numflag = 0;
92  // number of balancing conditions (size of vertex multi-weight)
93  int options[5];
94  options[0] = 0;
95 
96  PartGraphVKway(&nVerts, &xadj[0], &adjcy[0], vwgt, vsize,
97  &wgtflag, &numflag, &nparts, options, &volume,
98  &part[0]);
99  }
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, const SCOTCH_Num *const options, SCOTCH_Num *const volume, SCOTCH_Num *const part)

Member Data Documentation

std::string Nektar::LibUtilities::MeshPartitionScotch::className
static
Initial value:
"Scotch",
"Partitioning using the Scotch library.")

Name of class.

Definition at line 61 of file MeshPartitionScotch.h.

std::string Nektar::LibUtilities::MeshPartitionScotch::cmdSwitch = SessionReader::RegisterCmdLineFlag("use-scotch","","Use Scotch for mesh partitioning.")
static

Definition at line 62 of file MeshPartitionScotch.h.