17 #include <Teuchos_ParameterList.hpp>
18 #include <Teuchos_RCP.hpp>
19 #include <Teuchos_CommandLineProcessor.hpp>
20 #include <Tpetra_CrsMatrix.hpp>
21 #include <Tpetra_Vector.hpp>
22 #include <MatrixMarket_Tpetra.hpp>
44 typedef Tpetra::CrsMatrix<z2TestScalar, z2TestLO, z2TestGO>
SparseMatrix;
45 typedef Tpetra::Vector<z2TestScalar, z2TestLO, z2TestGO>
Vector;
46 typedef Vector::node_type
Node;
54 typename SparseMatrix::local_inds_host_view_type indices;
55 typename SparseMatrix::values_host_view_type values;
63 for (ii=0; ii<n; ii++) {
64 A->getLocalRowView (ii, indices, values);
65 for (k=0; k< static_cast<z2TestLO>(indices.size()); k++){
82 return (bw_left + bw_right + 1);
96 lno_t numRows = origMatrix->getLocalNumRows();
98 std::cout <<
"origMatrix->getLocalNumRows(): " << numRows << std::endl;
101 std::cout <<
"Skipping analysis - matrix is empty" << std::endl;
105 Array<lno_t> oldMatrix(numRows*numRows);
106 Array<lno_t> newMatrix(numRows*numRows);
109 lno_t showSize = numRows;
114 std::cout << std::endl <<
"perm: ";
115 for(lno_t n = 0; n < showSize; ++n) {
116 std::cout <<
" " << perm[n] <<
" ";
118 if(showSize < numRows) {
121 std::cout << std::endl <<
"iperm: ";
122 for(lno_t n = 0; n < showSize; ++n) {
123 std::cout <<
" " << iperm[n] <<
" ";
125 if(showSize < numRows) {
129 std::cout << std::endl;
132 for (lno_t j = 0; j < numRows; ++j) {
133 typename SparseMatrix::local_inds_host_view_type indices;
134 typename SparseMatrix::values_host_view_type wgts;
135 origMatrix->getLocalRowView( j, indices, wgts );
136 for (lno_t n = 0; n < static_cast<lno_t>(indices.size()); ++n) {
137 lno_t i = indices[n];
139 oldMatrix[i + j*numRows] = 1;
140 newMatrix[perm[i] + perm[j]*numRows] = 1;
146 std::cout << std::endl <<
"original graph in matrix form:" << std::endl;
147 for(lno_t y = 0; y < showSize; ++y) {
148 for(lno_t x = 0; x < showSize; ++x) {
149 std::cout <<
" " << oldMatrix[x + y*numRows];
151 if(showSize < numRows) {
154 std::cout << std::endl;
156 if(showSize < numRows) {
157 for(lno_t i = 0; i < showSize; ++i) {
162 std::cout << std::endl;
165 std::cout << std::endl <<
"reordered graph in matrix form:" << std::endl;
166 for(lno_t y = 0; y < showSize; ++y) {
167 for(lno_t x = 0; x < showSize; ++x) {
168 std::cout <<
" " << newMatrix[x + y*numRows];
170 if(showSize < numRows) {
173 std::cout << std::endl;
175 if(showSize < numRows) {
176 for(lno_t i = 0; i < showSize; ++i) {
181 std::cout << std::endl;
186 int mainExecute(
int narg,
char** arg, RCP<
const Teuchos::Comm<int> > comm)
188 std::string inputFile =
"";
189 std::string outputFile =
"";
190 bool verbose =
false;
193 int rank = comm->getRank();
196 Teuchos::CommandLineProcessor cmdp (
false,
false);
197 cmdp.setOption(
"inputFile", &inputFile,
198 "Name of a Matrix Market file in the data directory; "
199 "if not specified, a matrix will be generated by Galeri.");
200 cmdp.setOption(
"outputFile", &outputFile,
201 "Name of file to write the permutation");
202 cmdp.setOption(
"verbose",
"quiet", &verbose,
203 "Print messages and results.");
206 std::cout <<
"Starting everything" << std::endl;
218 std::string matrixType(
"Laplace3D");
220 cmdp.setOption(
"x", &xdim,
221 "number of gridpoints in X dimension for "
222 "mesh used to generate matrix.");
223 cmdp.setOption(
"y", &ydim,
224 "number of gridpoints in Y dimension for "
225 "mesh used to generate matrix.");
226 cmdp.setOption(
"z", &zdim,
227 "number of gridpoints in Z dimension for "
228 "mesh used to generate matrix.");
229 cmdp.setOption(
"matrix", &matrixType,
230 "Matrix type: Laplace1D, Laplace2D, or Laplace3D");
235 std::string orderMethod(
"scotch");
236 cmdp.setOption(
"order_method", &orderMethod,
237 "order_method: natural, random, rcm, scotch");
239 std::string orderMethodType(
"local");
240 cmdp.setOption(
"order_method_type", &orderMethodType,
241 "local or global or both" );
244 cmdp.parse(narg, arg);
247 RCP<UserInputForTests> uinput;
253 if (inputFile !=
""){
261 RCP<SparseMatrix> origMatrix = uinput->getUITpetraCrsMatrix();
264 std::cout <<
"NumRows = " << origMatrix->getGlobalNumRows() << std::endl
265 <<
"NumNonzeros = " << origMatrix->getGlobalNumEntries() << std::endl
266 <<
"NumProcs = " << comm->getSize() << std::endl;
281 Teuchos::ParameterList params;
282 params.set(
"order_method", orderMethod);
283 params.set(
"order_method_type", orderMethodType);
295 std::cout <<
"Going to solve" << std::endl;
306 std::cout <<
"Going to get results" << std::endl;
309 #ifdef MDM // Temp debugging code all of which can be removed for final
310 for(
int checkRank = 0; checkRank < comm->getSize(); ++checkRank ) {
312 if( checkRank == comm->getRank() ) {
313 std::cout <<
"Debug output matrix for rank: " << checkRank << std::endl;
343 if (outputFile !=
"") {
344 std::ofstream permFile;
349 std::stringstream
fname;
350 fname << outputFile <<
"." << comm->getSize() <<
"." << rank;
351 permFile.open(fname.str().c_str());
352 for (
size_t i=0; i<checkLength; i++){
353 permFile <<
" " << checkPerm[i] << std::endl;
360 std::cout <<
"Checking permutation" << std::endl;
364 if (testReturn)
return testReturn;
368 std::cout <<
"Checking inverse permutation" << std::endl;
370 for (
size_t i=0; i< checkLength; i++){
371 testReturn = (checkInvPerm[checkPerm[i]] !=
z2TestLO(i));
372 if (testReturn)
return testReturn;
377 std::cout <<
"Checking num blocks" << std::endl;
379 testReturn = !((NumBlocks > 0) && (NumBlocks<
z2TestLO(checkLength)));
380 if (testReturn)
return testReturn;
385 std::cout <<
"Checking range" << std::endl;
387 testReturn = RangeTab[0];
388 if (testReturn)
return testReturn;
390 for (
z2TestLO i = 0; i < NumBlocks; i++){
391 testReturn = !(RangeTab[i] < RangeTab[i+1]);
392 if (testReturn)
return testReturn;
398 std::cout <<
"Checking Separator Tree" << std::endl;
402 testReturn = (TreeTab[0] != -1);
406 std::cout <<
"TreeTab[0] = " << TreeTab[0] <<
" != -1" << std::endl;
410 for (
size_t i=1; i< checkLength; i++){
411 testReturn = !(TreeTab[i] < NumBlocks);
413 std::cout <<
"TreeTab[" << i <<
"] = " << TreeTab[i] <<
" >= NumBlocks "
414 <<
" = " << NumBlocks << std::endl;
420 std::cout <<
"Going to compute the bandwidth" << std::endl;
428 std::cout <<
"Original Bandwidth: " << originalBandwidth << std::endl;
429 std::cout <<
"Permuted Bandwidth: " << permutedBandwidth << std::endl;
432 if(permutedBandwidth >= originalBandwidth) {
434 std::cout <<
"Test failed: bandwidth was not improved!" << std::endl;
436 std::cout <<
"Test in progress - returning OK for now..." << std::endl;
443 std::cout <<
"The bandwidth was improved. Good!" << std::endl;
447 catch (std::exception &e) {
448 std::cout <<
"Exception caught in ordering" << std::endl;
449 std::cout << e.what() << std::endl;
458 Tpetra::ScopeGuard tscope(&narg, &arg);
459 Teuchos::RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm();
466 reduceAll<int,int>(*comm, Teuchos::EReductionType::REDUCE_MAX, 1,
467 &result, &resultReduced);
471 if (comm->getRank() == 0) {
472 std::cout <<
"Scotch Ordering test with " << comm->getSize()
473 <<
" processes has test return code " << resultReduced
474 <<
" and is exiting in the "
475 << ((resultReduced == 0 ) ?
"PASSED" :
"FAILED") <<
" state."
Provides access for Zoltan2 to Xpetra::CrsMatrix data.
Tpetra::CrsMatrix< z2TestScalar, z2TestLO, z2TestGO > SparseMatrix
int main(int narg, char **arg)
common code used by tests
size_t computeBandwidth(RCP< SparseMatrix > A, z2TestLO *iperm)
Tpetra::Vector< z2TestScalar, z2TestLO, z2TestGO > Vector
OrderingProblem sets up ordering problems for the user.
Defines the XpetraCrsMatrixAdapter class.
size_t getPermutationSize() const
Get (local) size of permutation.
lno_t getNumSeparatorBlocks() const
Get number of separator column blocks.
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.
void solve(bool updateInputData=true)
Direct the problem to create a solution.
map_t::local_ordinal_type lno_t
bool haveSeparators() const
Do we have the separators?
lno_t * getSeparatorRangeView() const
Get pointer to separator range.
Tpetra::Map::local_ordinal_type zlno_t
Defines the OrderingProblem class.
int validatePerm()
returns 0 if permutation is valid, negative if invalid.
Zoltan2::XpetraCrsMatrixAdapter< SparseMatrix > SparseMatrixAdapter
lno_t * getSeparatorTreeView() const
Get pointer to separator tree.
void tempDebugTest(RCP< SparseMatrix > origMatrix, Zoltan2::LocalOrderingSolution< z2TestLO > *soln)
bool mainExecute(int narg, char *arg[], RCP< const Comm< int > > &comm)
Tpetra::Map::global_ordinal_type zgno_t
typename InputTraits< User >::lno_t lno_t
LocalOrderingSolution< lno_t > * getLocalOrderingSolution()
Get the local ordering solution to the problem.
std::string testDataFilePath(".")