48 #ifndef _ZOLTAN2_ALGND_HPP_ 49 #define _ZOLTAN2_ALGND_HPP_ 86 template <
typename Adapter>
96 typedef typename Adapter::lno_t lno_t;
97 typedef typename Adapter::gno_t gno_t;
100 const RCP<const Environment> mEnv;
101 const RCP<const Comm<int> > mProblemComm;
104 const RCP<GraphModel<typename Adapter::base_adapter_t> > mGraphModel;
106 const RCP<CoordinateModel<typename Adapter::base_adapter_t> > mIds;
110 const RCP<const typename Adapter::base_adapter_t> mBaseInputAdapter;
112 void getBoundLayer(
int levelIndx,
const std::vector<part_t> &partMap,
113 const part_t * parts,
114 const std::set<int> &excVerts,
115 int &bigraphNumS,
int &bigraphNumT,
int &bigraphNumE,
116 std::vector<int> &bigraphCRSRowPtr, std::vector<int> &bigraphCRSCols,
117 std::vector<int> &bigraphVMapU, std::vector<int> &bigraphVMapV);
119 void buildPartTree(
int level,
int leftPart,
int splitPart,
int rightPart, std::vector<int> &partTree);
124 AlgND(
const RCP<const Environment> &env_,
125 const RCP<
const Comm<int> > &problemComm_,
128 const RCP<const typename Adapter::base_adapter_t> baseInputAdapter_
130 :mEnv(env_), mProblemComm(problemComm_), mGraphModel(gModel_),
131 mIds(cModel_), mBaseInputAdapter(baseInputAdapter_)
133 #ifndef INCLUDE_ZOLTAN2_EXPERIMENTAL 137 #ifndef INCLUDE_ZOLTAN2_EXPERIMENTAL_WOLF 141 if(mProblemComm->getSize()!=1)
157 template <
typename Adapter>
161 throw std::logic_error(
"AlgND does not support global ordering.");
169 template <
typename Adapter>
172 typedef typename Adapter::lno_t lno_t;
183 RCP<PartitioningSolution<Adapter> > partSoln;
193 size_t numGlobalParts = partSoln->getTargetGlobalNumberOfParts();
195 const part_t *parts = partSoln->getPartListView();
211 std::vector<int> partTree;
213 buildPartTree( 0, 0, (numGlobalParts-1)/2 + 1, numGlobalParts, partTree);
214 unsigned int numSeparators = partTree.size() / 4;
216 for(
unsigned int i=0;i<partTree.size(); i++)
218 std::cout <<
"partTree: " << partTree[i] << std::endl;
220 std::cout <<
"NumSeparators: " << numSeparators << std::endl;
230 int numLevels = partTree[4*(numSeparators-1)]+1;
232 std::vector<std::vector<int> > partLevelMap(numLevels,std::vector<int>(numGlobalParts));
234 std::vector<int> sepsInLev(numLevels,0);
236 for(
unsigned int i=0;i<numSeparators;i++)
238 int level = partTree[4*i];
239 int leftPart = partTree[4*i+1];
240 int splitPart = partTree[4*i+2];
241 int rightPart = partTree[4*i+3];
243 for(
int part=leftPart; part<splitPart; part++)
245 partLevelMap[level][part] = 2*sepsInLev[level];
248 for(
int part=splitPart; part<rightPart; part++)
250 partLevelMap[level][part] = 2*sepsInLev[level]+1;
256 std::cout <<
"partLevelMap[0][0] = " << partLevelMap[0][0] << std::endl;
257 std::cout <<
"partLevelMap[0][1] = " << partLevelMap[0][1] << std::endl;
259 std::cout <<
"HERE7" << std::endl;
266 std::set<lno_t> sepVerts;
267 std::vector<std::vector< std::set<lno_t> > > sepVertsByLevel(numLevels);
274 std::cout <<
"HERE8" << std::endl;
276 for(
unsigned int level=0;level<numLevels;level++)
278 sepVertsByLevel[level].resize(sepsInLev[level]);
280 for(
unsigned int levIndx=0;levIndx<sepsInLev[level];levIndx++)
285 std::cout <<
"HERE9" << std::endl;
287 int bigraphNumU=0, bigraphNumV=0, bigraphNumE=0;
288 std::vector<int> bigraphVMapU;
289 std::vector<int> bigraphVMapV;
291 std::vector<int> bigraphCRSRowPtr;
292 std::vector<int> bigraphCRSCols;
295 getBoundLayer(levIndx, partLevelMap[level], parts, sepVerts,
296 bigraphNumU,bigraphNumV,bigraphNumE,
297 bigraphCRSRowPtr, bigraphCRSCols,
298 bigraphVMapU,bigraphVMapV);
300 std::cout <<
"Bipartite graph: " << bigraphNumU <<
" " << bigraphNumV <<
" " 301 << bigraphNumE << std::endl;
303 for (
unsigned int i=0;i<bigraphVMapU.size();i++)
305 std::cout <<
"boundVertU: " << bigraphVMapU[i] << std::endl;
308 for (
unsigned int i=0;i<bigraphVMapV.size();i++)
310 std::cout <<
"boundVertV: " << bigraphVMapV[i] << std::endl;
315 for (
int rownum=0;rownum<bigraphNumU;rownum++)
318 for (
int eIdx=bigraphCRSRowPtr[rownum];eIdx<bigraphCRSRowPtr[rownum+1];eIdx++)
320 std::cout <<
"bipartite E: " << bigraphVMapU[rownum] <<
", " << bigraphVMapV[ bigraphCRSCols[eIdx]]
321 <<
" ( " << rownum <<
"," << bigraphCRSCols[eIdx] <<
" )" << std::endl;
325 std::cout <<
"HERE10" << std::endl;
333 assert(bigraphNumV>0);
335 Matcher<lno_t> bpMatch(bigraphCRSRowPtr.data(), bigraphCRSCols.data(), bigraphNumU, bigraphNumV, bigraphNumE);
338 const std::vector<int> &vertUMatches = bpMatch.getVertexUMatches();
339 const std::vector<int> &vertVMatches = bpMatch.getVertexVMatches();
347 bpMatch.getVCfromMatching(bigraphCRSRowPtr,bigraphCRSCols,vertUMatches,vertVMatches,
348 bigraphVMapU,bigraphVMapV,VC);
350 for(
unsigned int i=0;i<VC.size();i++)
352 sepVerts.insert(VC[i]);
354 sepVertsByLevel[level][levIndx].insert(VC[i]);
355 std::cout <<
"VC: " << VC[i] << std::endl;
369 std::cout <<
"Separators: " << std::endl;
370 for(
unsigned int level=0;level<sepVertsByLevel.size();level++)
372 sepVertsByLevel[level].resize(sepsInLev[level]);
374 for(
unsigned int levIndx=0;levIndx<sepVertsByLevel[level].size();levIndx++)
376 std::cout <<
" Separator " << level <<
" " << levIndx <<
": ";
381 typename std::set<lno_t>::const_iterator iterS;
382 for (iterS=sepVertsByLevel[level][levIndx].begin();iterS!=sepVertsByLevel[level][levIndx].end();++iterS)
384 std::cout << *iterS <<
" ";
386 std::cout << std::endl;
396 std::cout <<
"HERE20" << std::endl;
415 template <
typename Adapter>
417 const part_t * parts,
418 const std::set<int> &excVerts,
419 int &bigraphNumS,
int &bigraphNumT,
int &bigraphNumE,
420 std::vector<int> &bigraphCRSRowPtr, std::vector<int> &bigraphCRSCols,
421 std::vector<int> &bigraphVMapS, std::vector<int> &bigraphVMapT)
423 std::cout <<
"HI1" << std::endl;
425 typedef typename Adapter::lno_t lno_t;
426 typedef typename Adapter::scalar_t
scalar_t;
429 int numVerts = mGraphModel->getLocalNumVertices();
432 ArrayView< const lno_t > eIDs;
433 ArrayView< const lno_t > vOffsets;
434 ArrayView< input_t > wgts;
443 std::map<int,std::set<int> > bigraphEs;
449 for(
int v1=0;v1<numVerts;v1++)
452 part_t vpart1 = partMap[parts[v1]];
454 bool correctBL = (vpart1 >= 2*levelIndx && vpart1 < 2*(levelIndx+1) );
464 if(excVerts.find(v1)!=excVerts.end())
471 for(
int j=vOffsets[v1];j<vOffsets[v1+1];j++)
476 part_t vpart2 = partMap[parts[v2]];
478 correctBL = (vpart2 >= 2*levelIndx && vpart2 < 2*(levelIndx+1) );
488 if(excVerts.find(v2)!=excVerts.end())
493 if ( vpart1 != vpart2 )
501 if(bigraphEs.find(v1)==bigraphEs.end())
503 bigraphEs[v1] = std::set<int>();
505 bigraphEs[v1].insert(v2);
522 bigraphNumS = vSetS.size();
523 bigraphNumT = vSetT.size();
529 bigraphVMapS.resize(bigraphNumS);
531 std::map<int,int> glob2LocTMap;
534 for(std::set<int>::const_iterator iter=vSetS.begin(); iter!=vSetS.end(); ++iter)
536 bigraphVMapS[indx] = *iter;
541 bigraphVMapT.resize(bigraphNumT);
543 for(std::set<int>::const_iterator iter=vSetT.begin();iter!=vSetT.end();++iter)
545 bigraphVMapT[indx] = *iter;
546 glob2LocTMap[*iter]=indx;
555 bigraphCRSRowPtr.resize(bigraphNumS+1);
556 bigraphCRSCols.resize(bigraphNumE);
562 bigraphCRSRowPtr[0]=0;
564 unsigned int rownum=0;
565 unsigned int nzIndx=0;
566 std::map<int,std::set<int> >::const_iterator iterM;
567 for (iterM=bigraphEs.begin();iterM!=bigraphEs.end();++iterM)
569 bigraphCRSRowPtr[rownum+1] = bigraphCRSRowPtr[rownum] + (*iterM).second.size();
571 for(std::set<int>::const_iterator iter=(*iterM).second.begin(); iter!=(*iterM).second.end(); ++iter)
573 bigraphCRSCols[nzIndx] = glob2LocTMap[(*iter)];
587 template <
typename Adapter>
589 buildPartTree(
int level,
int leftPart,
int splitPart,
int rightPart, std::vector<int> &partTree)
592 partTree.push_back(level);
593 partTree.push_back(leftPart);
594 partTree.push_back(splitPart);
595 partTree.push_back(rightPart);
598 if(splitPart-leftPart > 1)
600 int newSplit = leftPart+(splitPart-leftPart-1)/2 + 1;
601 buildPartTree(level+1,leftPart,newSplit,splitPart,partTree);
605 if(rightPart-splitPart>1)
607 int newSplit = splitPart+(rightPart-splitPart-1)/2 + 1;
608 buildPartTree(level+1,splitPart,newSplit,rightPart,partTree);
#define Z2_THROW_SERIAL(mystr)
Throw an error when code is run on more than one processor.
#define Z2_THROW_EXPERIMENTAL_WOLF(mystr)
Throw an error when wolf experimental code is requested but not compiled.
LO match()
Computes the maximum cardinality matching.
interface to the Zoltan package
Defines the PartitioningSolution class.
An implementation of the Matcher interface that operates on Epetra matrices and Graphs.
sub-steps, each method's entry and exit
int globalOrder(const RCP< GlobalOrderingSolution< gno_t > > &solution_)
Ordering method.
SparseMatrixAdapter_t::part_t part_t
This class provides geometric coordinates with optional weights to the Zoltan2 algorithm.
void partition(const RCP< PartitioningSolution< Adapter > > &solution)
Partitioning method.
Defines the IdentifierModel interface.
Adapter::scalar_t scalar_t
A PartitioningSolution is a solution to a partitioning problem.
The StridedData class manages lists of weights or coordinates.
Algorithm defines the base class for all algorithms.
#define Z2_THROW_EXPERIMENTAL(mystr)
Throw an error when experimental code is requested but not compiled.
GraphModel defines the interface required for graph models.
AlgND(const RCP< const Environment > &env_, const RCP< const Comm< int > > &problemComm_, const RCP< GraphModel< typename Adapter::base_adapter_t > > &gModel_, const RCP< CoordinateModel< typename Adapter::base_adapter_t > > &cModel_, const RCP< const typename Adapter::base_adapter_t > baseInputAdapter_)
int localOrder(const RCP< LocalOrderingSolution< lno_t > > &solution_)
Ordering method.