Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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)
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.

Static Public Attributes

static std::string className
 Name of class.
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, 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.

: MeshPartition(pSession)
{
}
Nektar::LibUtilities::MeshPartitionScotch::~MeshPartitionScotch ( )
virtual

Definition at line 61 of file MeshPartitionScotch.cpp.

{
}

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.

{
return MemoryManager<MeshPartitionScotch>
::AllocateSharedPtr(pSession);
}
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 227 of file MeshPartitionScotch.cpp.

Referenced by PartGraphVKway().

{
// Scotch graph object to interface with libScotch
SCOTCH_Graph grafdat;
SCOTCH_Strat stradat;
SCOTCH_Num baseval;
SCOTCH_Num vertnbr;
int o;
SCOTCH_graphInit (&grafdat);
baseval = *numflag;
vertnbr = *n;
o = 1; // Assume something will go wrong
if (SCOTCH_graphBuild (&grafdat, baseval, vertnbr, xadj, xadj + 1,
vwgt, NULL, xadj[vertnbr] - baseval, adjncy,
adjwgt) == 0) {
SCOTCH_stratInit (&stradat);
SCOTCH_stratGraphMapBuild (&stradat, flagval, *nparts, kbalval);
#ifdef SCOTCH_DEBUG_ALL
// TRICK: next instruction called only if graph is consistent
if (SCOTCH_graphCheck (&grafdat) == 0)
#endif /* SCOTCH_DEBUG_ALL */
o = SCOTCH_graphPart (&grafdat, *nparts, &stradat, part);
SCOTCH_stratExit (&stradat);
}
SCOTCH_graphExit (&grafdat);
if (o != 0)
return (1);
if (baseval != 0) { // MeTiS part array is based, Scotch is not
SCOTCH_Num vertnum;
for (vertnum = 0; vertnum < vertnbr; vertnum ++)
part[vertnum] += baseval;
}
return (0);
}
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 101 of file MeshPartitionScotch.cpp.

References PartGraph2().

Referenced by PartitionGraphImpl().

{
SCOTCH_Num baseval;
const SCOTCH_Num * vwgt2;
const SCOTCH_Num * vsize2;
SCOTCH_Num vsizval; /// Communication volume of current vertex
SCOTCH_Num vertnbr;
SCOTCH_Num vertnum;
SCOTCH_Num edgenum;
const SCOTCH_Num * edgetax;
const SCOTCH_Num * parttax;
SCOTCH_Num * nghbtab;
SCOTCH_Num commvol;
vsize2 = ((*wgtflag & 1) != 0) ? vsize : NULL;
vwgt2 = ((*wgtflag & 2) != 0) ? vwgt : NULL;
baseval = *numflag;
vertnbr = *n;
edgetax = adjncy - baseval;
// If no communication load data provided
if (vsize2 == NULL) {
if (PartGraph2 (n, xadj, adjncy, vwgt2, NULL, numflag, nparts,
part, SCOTCH_STRATDEFAULT, 0.01) != 0)
return;
}
// Will have to turn communication volumes into edge loads
else {
const SCOTCH_Num * vsiztax;
SCOTCH_Num edgenbr;
SCOTCH_Num * edlotax;
int o;
edgenbr = xadj[vertnbr] - baseval;
if ((edlotax =
(SCOTCH_Num*) malloc (edgenbr * sizeof (SCOTCH_Num))) == NULL)
{
return;
}
edlotax -= baseval; // Base access to edlotax
vsiztax = vsize2 - baseval;
// Un-based scan of vertex array xadj
for (vertnum = 0, edgenum = baseval;
vertnum < vertnbr; vertnum ++) {
SCOTCH_Num vsizval; // Communication size of current vertex
SCOTCH_Num edgennd;
vsizval = vsize2[vertnum];
// Based traversal of edge array adjncy
for (edgennd = xadj[vertnum + 1];
edgenum < edgennd;
edgenum ++) {
SCOTCH_Num vertend; // Based end vertex number
vertend = edgetax[edgenum];
edlotax[edgenum] = vsizval + vsiztax[vertend];
}
}
o = PartGraph2 (n, xadj, adjncy, vwgt2, edlotax + baseval, numflag,
nparts, part, SCOTCH_STRATDEFAULT, 0.01);
free (edlotax + baseval);
if (o != 0)
return;
}
if ((nghbtab =
(SCOTCH_Num*) malloc (*nparts * sizeof (SCOTCH_Num))) == NULL)
{
return;
}
memset (nghbtab, ~0, *nparts * sizeof (SCOTCH_Num));
parttax = part - baseval;
vsizval = 1; // Assume no vertex communication sizes
// Un-based scan of vertex array xadj
for (vertnum = 0, edgenum = baseval, commvol = 0;
vertnum < vertnbr; vertnum ++) {
SCOTCH_Num partval;
SCOTCH_Num edgennd;
partval = part[vertnum];
nghbtab[partval] = vertnum; // Do not count local neighbors in
// communication volume
if (vsize2 != NULL)
vsizval = vsize2[vertnum];
// Based traversal of edge array adjncy
for (edgennd = xadj[vertnum + 1]; edgenum < edgennd; edgenum ++) {
SCOTCH_Num vertend; // Based end vertex number
SCOTCH_Num partend;
vertend = edgetax[edgenum];
partend = parttax[vertend];
// If first neighbor in this part set part as accounted for
if (nghbtab[partend] != vertnum) {
nghbtab[partend] = vertnum;
commvol += vsizval;
}
}
}
*volume = commvol;
free (nghbtab);
}
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,
int &  nparts,
int &  volume,
Nektar::Array< Nektar::OneD, int > &  part 
)
privatevirtual

Definition at line 66 of file MeshPartitionScotch.cpp.

References PartGraphVKway().

{
int wgtflag = 0;
int *vwgt = 0;
int *vsize = 0;
if (vertWgt.num_elements() > 0)
{
wgtflag += 1;
vwgt = &vertWgt[0];
}
if (vertSize.num_elements() > 0)
{
wgtflag += 2;
vsize = &vertSize[0];
}
int numflag = 0;
// number of balancing conditions (size of vertex multi-weight)
int options[5];
options[0] = 0;
PartGraphVKway(&nVerts, &xadj[0], &adjcy[0], vwgt, vsize,
&wgtflag, &numflag, &nparts, options, &volume,
&part[0]);
}

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.