50 #ifndef ZOLTAN2_EVALUATEORDERING_HPP
51 #define ZOLTAN2_EVALUATEORDERING_HPP
61 template <
typename Adapter>
65 typedef typename Adapter::lno_t lno_t;
66 typedef typename Adapter::gno_t gno_t;
67 typedef typename Adapter::offset_t offset_t;
69 typedef typename Adapter::scalar_t scalar_t;
81 void sharedConstructor(
const Adapter *ia,
83 const RCP<
const Comm<int> > &problemComm,
102 Teuchos::RCP<const Comm<int> > problemComm = Tpetra::getDefaultComm();
103 sharedConstructor(ia, p, problemComm, localSoln, globalSoln);
118 const RCP<
const Comm<int> > &problemComm,
122 sharedConstructor(ia, p, problemComm, localSoln, globalSoln);
125 #ifdef HAVE_ZOLTAN2_MPI
142 RCP<Teuchos::OpaqueWrapper<MPI_Comm> > wrapper =
143 Teuchos::opaqueWrapper(comm);
144 RCP<const Comm<int> > problemComm =
145 rcp<const Comm<int> >(
new Teuchos::MpiComm<int>(wrapper));
146 sharedConstructor(ia, p, problemComm, localSoln, globalSoln);
160 os <<
"Ordering Metrics" << std::endl;
161 os << std::setw(20) <<
" " << std::setw(11) <<
"ordered" << std::endl;
162 os << std::setw(20) <<
"envelope" << std::setw(11) << std::setprecision(4)
163 << envelope << std::endl;
164 os << std::setw(20) <<
"bandwidth" << std::setw(11) << std::setprecision(4)
165 << bandwidth << std::endl;
169 const RCP<const Environment> &env,
170 const RCP<
const Comm<int> > &comm,
179 std::bitset<NUM_MODEL_FLAGS> modelFlags;
180 RCP<GraphModel<base_adapter_t> > graph;
181 const RCP<const base_adapter_t> bia =
182 rcp(dynamic_cast<const base_adapter_t *>(ia),
false);
184 ArrayView<const gno_t> Ids;
185 ArrayView<input_t> vwgts;
186 ArrayView<const gno_t> edgeIds;
187 ArrayView<const offset_t> offsets;
188 ArrayView<input_t> wgts;
189 ArrayView<input_t> vtx;
190 graph->getEdgeList(edgeIds, offsets, wgts);
191 lno_t numVertex = graph->getVertexList(Ids, vwgts);
198 for(
int checkRank = 0; checkRank < comm->getSize(); ++checkRank ) {
200 if( checkRank == comm->getRank() ) {
201 std::cout <<
"-----------------------------------------" << std::endl;
202 std::cout <<
"Inspect rank: " << checkRank << std::endl;
203 std::cout << std::endl;
205 Array<lno_t> oldMatrix(numVertex*numVertex);
206 Array<lno_t> newMatrix(numVertex*numVertex);
209 std::cout << std::endl <<
"perm: ";
210 for(lno_t n = 0; n < numVertex; ++n) {
211 std::cout <<
" " << perm[n] <<
" ";
215 std::cout << std::endl <<
"iperm: ";
216 for(lno_t n = 0; n < numVertex; ++n) {
217 std::cout <<
" " << iperm[n] <<
" ";
219 std::cout << std::endl;
221 for (lno_t y = 0; y < numVertex; y++) {
222 for (offset_t n = offsets[y]; n < offsets[y+1]; ++n) {
223 lno_t x =
static_cast<lno_t
>(edgeIds[n]);
224 if (x < numVertex && y < numVertex) {
225 oldMatrix[x + y*numVertex] = 1;
226 newMatrix[perm[x] + perm[y]*numVertex] = 1;
232 std::cout << std::endl <<
"original graph in matrix form:" << std::endl;
233 for(lno_t y = 0; y < numVertex; ++y) {
234 for(lno_t x = 0; x < numVertex; ++x) {
235 std::cout <<
" " << oldMatrix[x + y*numVertex];
237 std::cout << std::endl;
241 std::cout << std::endl <<
"reordered graph in matrix form:" << std::endl;
242 for(lno_t y = 0; y < numVertex; ++y) {
243 for(lno_t x = 0; x < numVertex; ++x) {
244 std::cout <<
" " << newMatrix[x + y*numVertex];
246 std::cout << std::endl;
248 std::cout << std::endl;
254 #endif // Ends temporary logging which can be deleted later
261 for (lno_t j = 0; j < numVertex; j++) {
263 for (offset_t n = offsets[j]; n < offsets[j+1]; ++n) {
264 lno_t x =
static_cast<lno_t
>(edgeIds[n]);
270 lno_t delta_right = y2 - x2;
271 if (delta_right > bw_right) {
272 bw_right = delta_right;
274 lno_t delta_left = y2 - x2;
275 if (delta_left > bw_left) {
276 bw_left = delta_left;
280 if(delta_right > 0) {
281 envelope += delta_right;
284 envelope += delta_left;
291 bandwidth = (bw_left + bw_right + 1);
301 template <
typename Adapter>
302 void EvaluateOrdering<Adapter>::sharedConstructor(
305 const RCP<
const Comm<int> > &comm,
306 const LocalOrderingSolution<lno_t> *localSoln,
307 const GlobalOrderingSolution<gno_t> *globalSoln)
309 RCP<const Comm<int> > problemComm = (comm == Teuchos::null) ?
310 Tpetra::getDefaultComm() : comm;
312 RCP<Environment> env;
314 env = rcp(
new Environment(*p, problemComm));
319 env->timerStart(
MACRO_TIMERS,
"Computing ordering metrics");
326 localOrderingMetrics(env, problemComm, ia, localSoln);
330 throw std::logic_error(
"EvaluateOrdering not set up for global ordering.");
334 env->timerStop(
MACRO_TIMERS,
"Computing ordering metrics");
339 template <
typename Adapter>
342 typedef typename Adapter::lno_t lno_t;
369 const RCP<
const Comm<int> > &problemComm,
373 #ifdef HAVE_ZOLTAN2_MPI
392 template <
typename Adapter>
395 typedef typename Adapter::gno_t gno_t;
422 const RCP<
const Comm<int> > &problemComm,
426 #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.
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)
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.