10 #ifndef _ZOLTAN2_ALGRCM_HPP_
11 #define _ZOLTAN2_ALGRCM_HPP_
27 template <
typename Adapter>
32 const RCP<const typename Adapter::base_adapter_t> adapter;
33 const RCP<Teuchos::ParameterList> pl;
34 const RCP<const Teuchos::Comm<int> > comm;
35 RCP<const Environment> env;
46 const RCP<const typename Adapter::base_adapter_t> &adapter__,
47 const RCP<Teuchos::ParameterList> &pl__,
48 const RCP<
const Teuchos::Comm<int> > &comm__,
49 RCP<const Environment> &env__,
51 ) : adapter(adapter__), pl(pl__), comm(comm__), env(env__), graphFlags(graphFlags__)
57 throw std::logic_error(
"AlgRCM does not yet support global ordering.");
67 ArrayView<const gno_t> edgeIds;
68 ArrayView<const offset_t> offsets;
69 ArrayView<StridedData<lno_t, scalar_t> > wgts;
72 const size_t nVtx = model->getLocalNumVertices();
73 model->getEdgeList(edgeIds, offsets, wgts);
74 const int numWeightsPerEdge = model->getNumWeightsPerEdge();
75 if (numWeightsPerEdge > 1){
76 throw std::runtime_error(
"Multiple weights not supported.");
81 cout <<
"Debug: Local graph from getLocalEdgeList" << endl;
82 cout <<
"rank " << comm->getRank() <<
": nVtx= " << nVtx << endl;
83 cout <<
"rank " << comm->getRank() <<
": edgeIds: " << edgeIds << endl;
84 cout <<
"rank " << comm->getRank() <<
": offsets: " << offsets << endl;
88 const ArrayRCP<lno_t> invPerm = solution->getPermutationRCP(
true);
89 const ArrayRCP<lno_t> tmpPerm(invPerm.size());
93 if (offsets[nVtx] == 0) {
94 for (
size_t i = 0; i < nVtx; ++i) {
97 solution->setHaveInverse(
true);
103 for (
size_t i = 0; i < nVtx; ++i) {
113 Teuchos::Array<std::pair<gno_t, offset_t> > children;
115 while (count < nVtx) {
119 while ((next < nVtx) && (static_cast<Tpetra::global_size_t>(invPerm[next]) != INVALID)) next++;
123 std::string root_method = pl->get(
"root_method",
"pseudoperipheral");
124 if (root_method == std::string(
"first"))
126 else if (root_method == std::string(
"smallest_degree"))
127 root = findSmallestDegree(next, nVtx, edgeIds, offsets);
128 else if (root_method == std::string(
"pseudoperipheral"))
129 root = findPseudoPeripheral(next, nVtx, edgeIds, offsets);
132 throw std::runtime_error(
"invalid root_method");
138 invPerm[
root] = count++;
149 for (
offset_t ptr = offsets[v]; ptr < offsets[v+1]; ++ptr){
150 gno_t child = edgeIds[ptr];
151 if (static_cast<Tpetra::global_size_t>(invPerm[child]) == INVALID){
153 std::pair<gno_t,offset_t> newchild;
154 newchild.first = child;
155 newchild.second = offsets[child+1] - offsets[child];
156 children.push_back(newchild);
164 typename Teuchos::Array<std::pair<gno_t,offset_t> >::iterator it = children.begin ();
165 for ( ; it != children.end(); ++it){
167 gno_t child = it->first;
168 invPerm[child] = count++;
169 tmpPerm[invPerm[child]] = child;
182 for (
size_t i=0; i < nVtx/2; ++i) {
189 invPerm[tmpPerm[nVtx-1-i]] = i;
190 invPerm[temp] = nVtx-1-i;
195 solution->setHaveInverse(
true);
201 gno_t findSmallestDegree(
204 ArrayView<const gno_t> edgeIds,
205 ArrayView<const offset_t> offsets)
208 Teuchos::Array<bool> mark(nVtx);
212 gno_t smallestVertex = 0;
215 for (
int i=0; i<nVtx; i++)
225 offset_t deg = offsets[v+1] - offsets[v];
226 if (deg < smallestDegree){
227 smallestDegree = deg;
231 for (
offset_t ptr = offsets[v]; ptr < offsets[v+1]; ++ptr){
232 gno_t child = edgeIds[ptr];
239 return smallestVertex;
243 gno_t findPseudoPeripheral(
246 ArrayView<const gno_t> edgeIds,
247 ArrayView<const offset_t> offsets)
250 Teuchos::Array<bool> mark(nVtx);
253 const int numBFS = 2;
254 for (
int bfs=0; bfs<numBFS; bfs++){
256 for (
int i=0; i<nVtx; i++)
265 for (
offset_t ptr = offsets[v]; ptr < offsets[v+1]; ++ptr){
266 gno_t child = edgeIds[ptr];
int localOrder(const RCP< LocalOrderingSolution< lno_t > > &solution)
Ordering method.
AlgRCM(const RCP< const typename Adapter::base_adapter_t > &adapter__, const RCP< Teuchos::ParameterList > &pl__, const RCP< const Teuchos::Comm< int > > &comm__, RCP< const Environment > &env__, const modelFlag_t &graphFlags__)
std::bitset< NUM_MODEL_FLAGS > modelFlag_t
map_t::global_ordinal_type gno_t
Defines the OrderingSolution class.
Adapter::offset_t offset_t
Algorithm defines the base class for all algorithms.
map_t::local_ordinal_type lno_t
int globalOrder(const RCP< GlobalOrderingSolution< gno_t > > &)
Ordering method.
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)