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;
80 const RCP<Teuchos::ParameterList> &pl__,
81 const RCP<
const Teuchos::Comm<int> > &comm__
82 ) : model(model__), pl(pl__), comm(comm__)
88 throw std::logic_error(
"AlgRCM does not yet support global ordering.");
98 ArrayView<const gno_t> edgeIds;
99 ArrayView<const offset_t> offsets;
100 ArrayView<StridedData<lno_t, scalar_t> > wgts;
102 const size_t nVtx = model->getLocalNumVertices();
103 model->getEdgeList(edgeIds, offsets, wgts);
104 const int numWeightsPerEdge = model->getNumWeightsPerEdge();
105 if (numWeightsPerEdge > 1){
106 throw std::runtime_error(
"Multiple weights not supported.");
111 cout <<
"Debug: Local graph from getLocalEdgeList" << endl;
112 cout <<
"rank " << comm->getRank() <<
": nVtx= " << nVtx << endl;
113 cout <<
"rank " << comm->getRank() <<
": edgeIds: " << edgeIds << endl;
114 cout <<
"rank " << comm->getRank() <<
": offsets: " << offsets << endl;
118 const ArrayRCP<lno_t> invPerm = solution->getPermutationRCP(
true);
119 const ArrayRCP<lno_t> tmpPerm(invPerm.size());
123 if (offsets[nVtx] == 0) {
124 for (
size_t i = 0; i < nVtx; ++i) {
127 solution->setHaveInverse(
true);
133 for (
size_t i = 0; i < nVtx; ++i) {
143 Teuchos::Array<std::pair<gno_t, offset_t> > children;
145 while (count < nVtx) {
153 std::string root_method = pl->get(
"root_method",
"pseudoperipheral");
154 if (root_method == std::string(
"first"))
156 else if (root_method == std::string(
"smallest_degree"))
157 root = findSmallestDegree(next, nVtx, edgeIds, offsets);
158 else if (root_method == std::string(
"pseudoperipheral"))
159 root = findPseudoPeripheral(next, nVtx, edgeIds, offsets);
162 throw std::runtime_error(
"invalid root_method");
168 invPerm[
root] = count++;
179 for (
offset_t ptr = offsets[v]; ptr < offsets[v+1]; ++ptr){
180 gno_t child = edgeIds[ptr];
183 std::pair<gno_t,offset_t> newchild;
184 newchild.first = child;
185 newchild.second = offsets[child+1] - offsets[child];
186 children.push_back(newchild);
194 typename Teuchos::Array<std::pair<gno_t,offset_t> >::iterator it = children.begin ();
195 for ( ; it != children.end(); ++it){
197 gno_t child = it->first;
198 invPerm[child] = count++;
199 tmpPerm[invPerm[child]] = child;
212 for (
size_t i=0; i < nVtx/2; ++i) {
219 invPerm[tmpPerm[nVtx-1-i]] = i;
220 invPerm[temp] = nVtx-1-i;
225 solution->setHaveInverse(
true);
231 gno_t findSmallestDegree(
234 ArrayView<const gno_t> edgeIds,
235 ArrayView<const offset_t> offsets)
238 Teuchos::Array<bool> mark(nVtx);
242 gno_t smallestVertex = 0;
245 for (
int i=0; i<nVtx; i++)
255 offset_t deg = offsets[v+1] - offsets[v];
256 if (deg < smallestDegree){
257 smallestDegree = deg;
261 for (
offset_t ptr = offsets[v]; ptr < offsets[v+1]; ++ptr){
262 gno_t child = edgeIds[ptr];
269 return smallestVertex;
273 gno_t findPseudoPeripheral(
276 ArrayView<const gno_t> edgeIds,
277 ArrayView<const offset_t> offsets)
280 Teuchos::Array<bool> mark(nVtx);
283 const int numBFS = 2;
284 for (
int bfs=0; bfs<numBFS; bfs++){
286 for (
int i=0; i<nVtx; i++)
295 for (
offset_t ptr = offsets[v]; ptr < offsets[v+1]; ++ptr){
296 gno_t child = edgeIds[ptr];
Defines the GraphModel interface.
Defines the OrderingSolution class.
Sort vector of pairs (key, value) by value.
AlgRCM(const RCP< GraphModel< Adapter > > &model__, const RCP< Teuchos::ParameterList > &pl__, const RCP< const Teuchos::Comm< int > > &comm__)
Adapter::offset_t offset_t
int localOrder(const RCP< LocalOrderingSolution< lno_t > > &solution)
Ordering method.
int globalOrder(const RCP< GlobalOrderingSolution< gno_t > > &)
Ordering method.
Adapter::scalar_t scalar_t
Algorithm defines the base class for all algorithms.
GraphModel defines the interface required for graph models.
void sort(Teuchos::Array< std::pair< key_t, value_t > > &listofPairs, bool inc=true)
map_t::local_ordinal_type lno_t
map_t::global_ordinal_type gno_t
Created by mbenlioglu on Aug 31, 2020.
Tpetra::global_size_t global_size_t