14 #ifndef ZOLTAN2_EVALUATEORDERING_HPP
15 #define ZOLTAN2_EVALUATEORDERING_HPP
25 template <
typename Adapter>
31 typedef typename Adapter::offset_t offset_t;
33 typedef typename Adapter::scalar_t scalar_t;
45 void sharedConstructor(
const Adapter *ia,
47 const RCP<
const Comm<int> > &problemComm,
66 Teuchos::RCP<const Comm<int> > problemComm = Tpetra::getDefaultComm();
67 sharedConstructor(ia, p, problemComm, localSoln, globalSoln);
82 const RCP<
const Comm<int> > &problemComm,
86 sharedConstructor(ia, p, problemComm, localSoln, globalSoln);
89 #ifdef HAVE_ZOLTAN2_MPI
106 RCP<Teuchos::OpaqueWrapper<MPI_Comm> > wrapper =
107 Teuchos::opaqueWrapper(comm);
108 RCP<const Comm<int> > problemComm =
109 rcp<const Comm<int> >(
new Teuchos::MpiComm<int>(wrapper));
110 sharedConstructor(ia, p, problemComm, localSoln, globalSoln);
124 os <<
"Ordering Metrics" << std::endl;
125 os << std::setw(20) <<
" " << std::setw(11) <<
"ordered" << std::endl;
126 os << std::setw(20) <<
"envelope" << std::setw(11) << std::setprecision(4)
127 << envelope << std::endl;
128 os << std::setw(20) <<
"bandwidth" << std::setw(11) << std::setprecision(4)
129 << bandwidth << std::endl;
133 const RCP<const Environment> &env,
134 const RCP<
const Comm<int> > &comm,
143 std::bitset<NUM_MODEL_FLAGS> modelFlags;
144 RCP<GraphModel<base_adapter_t> > graph;
145 const RCP<const base_adapter_t> bia =
146 rcp(dynamic_cast<const base_adapter_t *>(ia),
false);
148 ArrayView<const gno_t> Ids;
149 ArrayView<input_t> vwgts;
150 ArrayView<const gno_t> edgeIds;
151 ArrayView<const offset_t> offsets;
152 ArrayView<input_t> wgts;
153 ArrayView<input_t> vtx;
154 graph->getEdgeList(edgeIds, offsets, wgts);
155 lno_t numVertex = graph->getVertexList(Ids, vwgts);
162 for(
int checkRank = 0; checkRank < comm->getSize(); ++checkRank ) {
164 if( checkRank == comm->getRank() ) {
165 std::cout <<
"-----------------------------------------" << std::endl;
166 std::cout <<
"Inspect rank: " << checkRank << std::endl;
167 std::cout << std::endl;
169 Array<lno_t> oldMatrix(numVertex*numVertex);
170 Array<lno_t> newMatrix(numVertex*numVertex);
173 std::cout << std::endl <<
"perm: ";
174 for(lno_t n = 0; n < numVertex; ++n) {
175 std::cout <<
" " << perm[n] <<
" ";
179 std::cout << std::endl <<
"iperm: ";
180 for(lno_t n = 0; n < numVertex; ++n) {
181 std::cout <<
" " << iperm[n] <<
" ";
183 std::cout << std::endl;
185 for (lno_t y = 0; y < numVertex; y++) {
186 for (offset_t n = offsets[y]; n < offsets[y+1]; ++n) {
187 lno_t x =
static_cast<lno_t
>(edgeIds[n]);
188 if (x < numVertex && y < numVertex) {
189 oldMatrix[x + y*numVertex] = 1;
190 newMatrix[perm[x] + perm[y]*numVertex] = 1;
196 std::cout << std::endl <<
"original graph in matrix form:" << std::endl;
197 for(lno_t y = 0; y < numVertex; ++y) {
198 for(lno_t x = 0; x < numVertex; ++x) {
199 std::cout <<
" " << oldMatrix[x + y*numVertex];
201 std::cout << std::endl;
205 std::cout << std::endl <<
"reordered graph in matrix form:" << std::endl;
206 for(lno_t y = 0; y < numVertex; ++y) {
207 for(lno_t x = 0; x < numVertex; ++x) {
208 std::cout <<
" " << newMatrix[x + y*numVertex];
210 std::cout << std::endl;
212 std::cout << std::endl;
218 #endif // Ends temporary logging which can be deleted later
225 for (lno_t j = 0; j < numVertex; j++) {
227 for (offset_t n = offsets[j]; n < offsets[j+1]; ++n) {
228 lno_t x =
static_cast<lno_t
>(edgeIds[n]);
234 lno_t delta_right = y2 - x2;
235 if (delta_right > bw_right) {
236 bw_right = delta_right;
238 lno_t delta_left = y2 - x2;
239 if (delta_left > bw_left) {
240 bw_left = delta_left;
244 if(delta_right > 0) {
245 envelope += delta_right;
248 envelope += delta_left;
255 bandwidth = (bw_left + bw_right + 1);
265 template <
typename Adapter>
266 void EvaluateOrdering<Adapter>::sharedConstructor(
269 const RCP<
const Comm<int> > &comm,
270 const LocalOrderingSolution<lno_t> *localSoln,
271 const GlobalOrderingSolution<gno_t> *globalSoln)
273 RCP<const Comm<int> > problemComm = (comm == Teuchos::null) ?
274 Tpetra::getDefaultComm() : comm;
276 RCP<Environment> env;
278 env = rcp(
new Environment(*p, problemComm));
283 env->timerStart(
MACRO_TIMERS,
"Computing ordering metrics");
290 localOrderingMetrics(env, problemComm, ia, localSoln);
294 throw std::logic_error(
"EvaluateOrdering not set up for global ordering.");
298 env->timerStop(
MACRO_TIMERS,
"Computing ordering metrics");
303 template <
typename Adapter>
333 const RCP<
const Comm<int> > &problemComm,
337 #ifdef HAVE_ZOLTAN2_MPI
356 template <
typename Adapter>
386 const RCP<
const Comm<int> > &problemComm,
390 #ifdef HAVE_ZOLTAN2_MPI
Zoltan2::BaseAdapter< userTypes_t > base_adapter_t
Time an algorithm (or other entity) as a whole.
EvaluateGlobalOrdering(const Adapter *ia, ParameterList *p, const RCP< const Comm< int > > &problemComm, const GlobalOrderingSolution< gno_t > *globalSoln)
Constructor where Teuchos communicator is specified.
#define Z2_FORWARD_EXCEPTIONS
Forward an exception back through call stack.
EvaluateOrdering(const Adapter *ia, ParameterList *p, const LocalOrderingSolution< lno_t > *localSoln, const GlobalOrderingSolution< gno_t > *globalSoln)
Constructor where communicator is Teuchos default.
EvaluateOrdering(const Adapter *ia, ParameterList *p, const RCP< const Comm< int > > &problemComm, const LocalOrderingSolution< lno_t > *localSoln, const GlobalOrderingSolution< gno_t > *globalSoln)
Constructor where Teuchos communicator is specified.
map_t::global_ordinal_type gno_t
Defines the OrderingSolution class.
A class that computes and returns quality metrics. base class for the local and global ordering vers...
sub-steps, each method's entry and exit
EvaluateLocalOrdering(const Adapter *ia, ParameterList *p, const LocalOrderingSolution< lno_t > *localSoln)
Constructor where communicator is Teuchos default.
SparseMatrixAdapter_t::part_t part_t
lno_t getSeparatorSize() const
lno_t getEnvelope() const
virtual void printMetrics(std::ostream &os) const
Print all metrics of type metricType based on the metric object type Note that parent class currently...
lno_t * getPermutationView(bool inverse=false) const
Get pointer to permutation. If inverse = true, return inverse permutation. By default, perm[i] is where new index i can be found in the old ordering. When inverse==true, perm[i] is where old index i can be found in the new ordering.
The StridedData class manages lists of weights or coordinates.
void localOrderingMetrics(const RCP< const Environment > &env, const RCP< const Comm< int > > &comm, const Adapter *ia, const LocalOrderingSolution< typename Adapter::lno_t > *localSoln)
map_t::local_ordinal_type lno_t
Base class for the EvaluatePartition and EvaluateOrdering classes.
GraphModel defines the interface required for graph models.
lno_t getBandwidth() const
EvaluateGlobalOrdering(const Adapter *ia, ParameterList *p, const GlobalOrderingSolution< gno_t > *globalSoln)
Constructor where communicator is Teuchos default.
EvaluateLocalOrdering(const Adapter *ia, ParameterList *p, const RCP< const Comm< int > > &problemComm, const LocalOrderingSolution< lno_t > *localSoln)
Constructor where Teuchos communicator is specified.