Commit 9f02cef5 authored by Chris Cantwell's avatar Chris Cantwell
Browse files

Added manual partitioning in the case that METIS produces an invalid partition.

parent f8f82b35
......@@ -341,7 +341,13 @@ namespace Nektar
try
{
// Attempt partitioning using METIS.
Metis::PartGraphVKway(nGraphVerts, xadj, adjncy, vwgt, vsize, npart, vol, part);
// Check METIS produced a valid partition and fix if not.
CheckPartitions(part);
// Distribute partitioning to all processes.
for (i = 1; i < m_comm->GetSize(); ++i)
{
m_comm->Send(i, part);
......@@ -376,6 +382,44 @@ namespace Nektar
}
}
void MeshPartition::CheckPartitions(Array<OneD, int> &pPart)
{
std::cout << "Checking partitions..." << std::endl;
unsigned int i = 0;
unsigned int cnt = 0;
const unsigned int npart = m_comm->GetSize();
bool valid = true;
// Check that every process has at least one element assigned
for (i = 0; i < npart; ++i)
{
cnt = std::count(pPart.begin(), pPart.end(), i);
if (cnt == 0)
{
valid = false;
}
}
// If METIS produced an invalid partition, repartition naively.
// Elements are assigned to processes in a round-robin fashion.
// It is assumed that METIS failure only occurs when the number of
// elements is approx. the number of processes, so this approach
// should not be too inefficient communication-wise.
if (!valid)
{
std::cout << "Mesh partition not valid. Correcting..." << std::endl;
for (i = 0; i < pPart.num_elements(); ++i)
{
pPart[i] = i % npart;
}
}
std::cout << "Done checking partitions." << std::endl;
}
void MeshPartition::OutputPartition(
LibUtilities::SessionReaderSharedPtr& pSession,
BoostSubGraph& pGraph,
......
......@@ -180,6 +180,7 @@ namespace Nektar
void PartitionGraph(BoostSubGraph& pGraph,
BoostSubGraph& pLocalPartition);
void OutputPartition(SessionReaderSharedPtr& pSession, BoostSubGraph& pGraph, TiXmlElement* pGeometry);
void CheckPartitions(Array<OneD, int> &pPart);
};
typedef boost::shared_ptr<MeshPartition> MeshPartitionSharedPtr;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment