45 #ifndef _ZOLTAN2_ALGRCM_HPP_ 46 #define _ZOLTAN2_ALGRCM_HPP_ 62 template <
typename Adapter>
67 const RCP<GraphModel<Adapter> > model;
68 const RCP<Teuchos::ParameterList> pl;
69 const RCP<const Teuchos::Comm<int> > comm;
73 typedef typename Adapter::lno_t
lno_t;
74 typedef typename Adapter::gno_t
gno_t;
79 const RCP<Teuchos::ParameterList> &pl__,
80 const RCP<
const Teuchos::Comm<int> > &comm__
81 ) : model(model__), pl(pl__), comm(comm__)
87 throw std::logic_error(
"AlgRCM does not yet support global ordering.");
97 ArrayView<const gno_t> edgeIds;
98 ArrayView<const lno_t> offsets;
99 ArrayView<StridedData<lno_t, scalar_t> > wgts;
101 const size_t nVtx = model->getLocalNumVertices();
102 model->getEdgeList(edgeIds, offsets, wgts);
103 const int numWeightsPerEdge = model->getNumWeightsPerEdge();
104 if (numWeightsPerEdge > 1){
105 throw std::runtime_error(
"Multiple weights not supported.");
110 cout <<
"Debug: Local graph from getLocalEdgeList" << endl;
111 cout <<
"rank " << comm->getRank() <<
": nVtx= " << nVtx << endl;
112 cout <<
"rank " << comm->getRank() <<
": edgeIds: " << edgeIds << endl;
113 cout <<
"rank " << comm->getRank() <<
": offsets: " << offsets << endl;
117 const ArrayRCP<lno_t> invPerm = solution->getPermutationRCP(
true);
121 if (offsets[nVtx] == 0) {
122 for (
size_t i = 0; i < nVtx; ++i) {
125 solution->setHaveInverse(
true);
131 for (
size_t i = 0; i < nVtx; ++i) {
141 Teuchos::Array<std::pair<gno_t, size_t> > children;
143 while (count < nVtx) {
147 while ((next < nVtx) && (static_cast<Tpetra::global_size_t>(invPerm[next]) != INVALID)) next++;
151 std::string root_method = pl->get(
"root_method",
"pseudoperipheral");
152 if (root_method == std::string(
"first"))
154 else if (root_method == std::string(
"smallest_degree"))
155 root = findSmallestDegree(next, nVtx, edgeIds, offsets);
156 else if (root_method == std::string(
"pseudoperipheral"))
157 root = findPseudoPeripheral(next, nVtx, edgeIds, offsets);
160 throw std::runtime_error(
"invalid root_method");
166 invPerm[
root] = count++;
176 for (lno_t ptr = offsets[v]; ptr < offsets[v+1]; ++ptr){
177 gno_t child = edgeIds[ptr];
178 if (static_cast<Tpetra::global_size_t>(invPerm[child]) == INVALID){
180 std::pair<gno_t,size_t> newchild;
181 newchild.first = child;
182 newchild.second = offsets[child+1] - offsets[child];
183 children.push_back(newchild);
191 typename Teuchos::Array<std::pair<gno_t,size_t> >::iterator it = children.begin ();
192 for ( ; it != children.end(); ++it){
194 gno_t child = it->first;
195 invPerm[child] = count++;
206 for (
size_t i=0; i < nVtx/2; ++i) {
209 invPerm[i] = invPerm[nVtx-1-i];
210 invPerm[nVtx-1-i] = temp;
214 solution->setHaveInverse(
true);
220 gno_t findSmallestDegree(
223 ArrayView<const gno_t> edgeIds,
224 ArrayView<const lno_t> offsets)
227 Teuchos::Array<bool> mark(nVtx);
230 lno_t smallestDegree = nVtx;
231 gno_t smallestVertex = 0;
234 for (
int i=0; i<nVtx; i++)
244 lno_t deg = offsets[v+1] - offsets[v];
245 if (deg < smallestDegree){
246 smallestDegree = deg;
250 for (lno_t ptr = offsets[v]; ptr < offsets[v+1]; ++ptr){
251 gno_t child = edgeIds[ptr];
258 return smallestVertex;
262 gno_t findPseudoPeripheral(
265 ArrayView<const gno_t> edgeIds,
266 ArrayView<const lno_t> offsets)
269 Teuchos::Array<bool> mark(nVtx);
272 const int numBFS = 2;
273 for (
int bfs=0; bfs<numBFS; bfs++){
275 for (
int i=0; i<nVtx; i++)
284 for (lno_t ptr = offsets[v]; ptr < offsets[v+1]; ++ptr){
285 gno_t child = edgeIds[ptr];
int localOrder(const RCP< LocalOrderingSolution< lno_t > > &solution)
Ordering method.
Defines the OrderingSolution class.
AlgRCM(const RCP< GraphModel< Adapter > > &model__, const RCP< Teuchos::ParameterList > &pl__, const RCP< const Teuchos::Comm< int > > &comm__)
int globalOrder(const RCP< GlobalOrderingSolution< gno_t > > &solution)
Ordering method.
Algorithm defines the base class for all algorithms.
Sort vector of pairs (key, value) by value.
Adapter::scalar_t scalar_t
GraphModel defines the interface required for graph models.
Tpetra::global_size_t global_size_t
Defines the GraphModel interface.
void sort(Teuchos::Array< std::pair< key_t, value_t > > &listofPairs, bool inc=true)