From 5b7bd3a878161420d1b4634855f210d631cb0080 Mon Sep 17 00:00:00 2001 From: William McLendon Date: Wed, 19 Dec 2018 09:52:06 -0700 Subject: [PATCH 1/5] Tpetra: Clean up CrsGraph::Swap testing There were some `#if 0` blocks in the test which needed to be changed to use `Tpetra::Details::Behavior::verbose()` for consistency. --- .../test/CrsGraph/CrsGraph_UnitTests_Swap.cpp | 73 ++++++++++--------- 1 file changed, 39 insertions(+), 34 deletions(-) diff --git a/packages/tpetra/core/test/CrsGraph/CrsGraph_UnitTests_Swap.cpp b/packages/tpetra/core/test/CrsGraph/CrsGraph_UnitTests_Swap.cpp index 9bef4be744a7..aff975e2dc65 100644 --- a/packages/tpetra/core/test/CrsGraph/CrsGraph_UnitTests_Swap.cpp +++ b/packages/tpetra/core/test/CrsGraph/CrsGraph_UnitTests_Swap.cpp @@ -144,6 +144,8 @@ generate_crsgraph(Teuchos::RCP comm, typedef typename std::vector vec_go_t; typedef typename std::map map_row_to_cols_t; + const bool verbose = Tpetra::Details::Behavior::verbose(); + const size_t comm_rank = comm->getRank(); map_row_to_cols_t gbl_rows; @@ -160,20 +162,21 @@ generate_crsgraph(Teuchos::RCP comm, for(auto& p: gbl_row_owners) { gbl_row2pid.insert(p); } // Print out some debugging information on what's in the graph - #if 0 - std::cout << "p=0 | gbl_num_rows: " << gbl_rows.size() << std::endl; - for(auto& p: gbl_rows) + if(verbose) { - std::cout << "p=0 | gbl_row : " << p.first << " (" << p.second.size() << ") "; - for(auto& j: p.second) + std::cout << "p=0 | gbl_num_rows: " << gbl_rows.size() << std::endl; + for(auto& p: gbl_rows) { - std::cout << j << " "; + std::cout << "p=0 | gbl_row : " << p.first << " (" << p.second.size() << ") "; + for(auto& j: p.second) + { + std::cout << j << " "; + } + std::cout << std::endl; } - std::cout << std::endl; + for(auto& p: gbl_row2pid) + std::cout << "p=0 | gbl_row2pid : " << p.first << " => " << p.second << std::endl; } - for(auto& p: gbl_row2pid) - std::cout << "p=0 | gbl_row2pid : " << p.first << " => " << p.second << std::endl; - #endif GO gbl_num_rows = gbl_rows.size(); // the number of global rows LO lcl_num_rows = 0; // this will be updated later @@ -187,9 +190,8 @@ generate_crsgraph(Teuchos::RCP comm, } } - #if 0 - std::cout << "p=" << comm_rank << " | " << "lcl_num_rows = " << lcl_num_rows << std::endl; - #endif + if(verbose) + std::cout << "p=" << comm_rank << " | " << "lcl_num_rows = " << lcl_num_rows << std::endl; // Set up global ids std::vector global_ids; @@ -200,18 +202,18 @@ generate_crsgraph(Teuchos::RCP comm, global_ids.push_back(r.first); } } - #if 0 - for(size_t i = 0; i < global_ids.size(); i++) + + if(verbose) { - std::cout << "p=" << comm_rank << " | " << "global_ids[" << i << "] = " << global_ids[i] << std::endl; + for(size_t i = 0; i < global_ids.size(); i++) + { + std::cout << "p=" << comm_rank << " | " << "global_ids[" << i << "] = " << global_ids[i] << std::endl; + } + std::cout << "p=" << comm_rank << " | " << "row_map = map_t(" << gbl_num_rows << ", " + << "global_ids.data(), " << lcl_num_rows << ", 0, comm)" << std::endl; } - #endif // Create the Row Map - #if 0 - std::cout << "p=" << comm_rank << " | " << "row_map = map_t(" << gbl_num_rows << ", " << "global_ids.data(), " - << lcl_num_rows << ", 0, comm)" << std::endl; - #endif RCP row_map(new map_t(gbl_num_rows, global_ids.data(), lcl_num_rows, 0, comm)); Teuchos::ArrayRCP num_ent_per_row(lcl_num_rows); @@ -226,13 +228,15 @@ generate_crsgraph(Teuchos::RCP comm, } } - #if 0 - std::cout << "p=" << comm_rank << " | lcl_num_rows = " << lcl_num_rows << std::endl; - for(int i=0; iinsertGlobalIndices(irow, r.second.size(), gbl_inds.data()); } } From bc8ed7f77f8ded06ecc1b102db86ac5729ae4940 Mon Sep 17 00:00:00 2001 From: William McLendon Date: Wed, 19 Dec 2018 12:31:13 -0700 Subject: [PATCH 2/5] Tpetra: Address comments on PR 4089 Addressing comments from @mhoemmen on PR 4089. - Changed my typedefs naming convention from `foo_t` to `foo_type` --- .../test/CrsGraph/CrsGraph_UnitTests_Swap.cpp | 72 +++++++++---------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/packages/tpetra/core/test/CrsGraph/CrsGraph_UnitTests_Swap.cpp b/packages/tpetra/core/test/CrsGraph/CrsGraph_UnitTests_Swap.cpp index aff975e2dc65..a7334994223e 100644 --- a/packages/tpetra/core/test/CrsGraph/CrsGraph_UnitTests_Swap.cpp +++ b/packages/tpetra/core/test/CrsGraph/CrsGraph_UnitTests_Swap.cpp @@ -125,9 +125,9 @@ TEUCHOS_STATIC_SETUP() // gbl_num_columns: Max # of columns in the matrix-representation of the graph. // This should be >= the highest value of v from all edges (u,v) in edges. // Note: u and v are 0-indexed, so if the highest v is 11, then this should be 12. -template +template Teuchos::RCP> -generate_crsgraph(Teuchos::RCP comm, +generate_crsgraph(Teuchos::RCP comm, const std::vector>& gbl_edges, const std::vector>& gbl_row_owners, const size_t gbl_num_columns, @@ -135,30 +135,30 @@ generate_crsgraph(Teuchos::RCP comm, { using Teuchos::Comm; - typedef Tpetra::CrsGraph graph_t; - typedef Tpetra::Map map_t; + typedef Tpetra::CrsGraph graph_type; + typedef Tpetra::Map map_type; - typedef typename std::map map_rows_t; // row_id, num_entries + typedef typename std::map map_rows_type; // row_id, num_entries - typedef typename std::vector vec_go_t; - typedef typename std::map map_row_to_cols_t; + typedef typename std::vector vec_go_type; + typedef typename std::map map_row_to_cols_type; const bool verbose = Tpetra::Details::Behavior::verbose(); const size_t comm_rank = comm->getRank(); - map_row_to_cols_t gbl_rows; + map_row_to_cols_type gbl_rows; for(auto& e: gbl_edges) { if(gbl_rows.find(e.first) == gbl_rows.end()) { - gbl_rows[ e.first ] = vec_go_t(); + gbl_rows[ e.first ] = vec_go_type(); } gbl_rows[ e.first ].push_back(e.second); } - map_rows_t gbl_row2pid; + map_rows_type gbl_row2pid; for(auto& p: gbl_row_owners) { gbl_row2pid.insert(p); } // Print out some debugging information on what's in the graph @@ -209,12 +209,12 @@ generate_crsgraph(Teuchos::RCP comm, { std::cout << "p=" << comm_rank << " | " << "global_ids[" << i << "] = " << global_ids[i] << std::endl; } - std::cout << "p=" << comm_rank << " | " << "row_map = map_t(" << gbl_num_rows << ", " + std::cout << "p=" << comm_rank << " | " << "row_map = map_type(" << gbl_num_rows << ", " << "global_ids.data(), " << lcl_num_rows << ", 0, comm)" << std::endl; } // Create the Row Map - RCP row_map(new map_t(gbl_num_rows, global_ids.data(), lcl_num_rows, 0, comm)); + RCP row_map(new map_type(gbl_num_rows, global_ids.data(), lcl_num_rows, 0, comm)); Teuchos::ArrayRCP num_ent_per_row(lcl_num_rows); size_t idx = 0; @@ -233,12 +233,12 @@ generate_crsgraph(Teuchos::RCP comm, std::cout << "p=" << comm_rank << " | lcl_num_rows = " << lcl_num_rows << std::endl; for(int i=0; i comm, } } - RCP range_map = row_map; + RCP range_map = row_map; const GO index_base = 0; - RCP domain_map(new map_t(gbl_num_columns, index_base, comm)); + RCP domain_map(new map_type(gbl_num_columns, index_base, comm)); if(do_fillComplete) { @@ -293,14 +293,14 @@ TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL(CrsGraph, Swap, LO, GO, Node) using Teuchos::outArg; using Teuchos::RCP; - typedef Teuchos::Comm comm_t; - typedef Tpetra::CrsGraph graph_t; + typedef Teuchos::Comm comm_type; + typedef Tpetra::CrsGraph graph_type; - typedef typename std::pair pair_edge_t; - typedef typename std::pair pair_owner_t; + typedef typename std::pair pair_edge_type; + typedef typename std::pair pair_owner_type; - typedef typename std::vector vec_edges_t; - typedef typename std::vector vec_owners_t; + typedef typename std::vector vec_edges_type; + typedef typename std::vector vec_owners_type; bool verbose = Tpetra::Details::Behavior::verbose(); @@ -323,10 +323,10 @@ TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL(CrsGraph, Swap, LO, GO, Node) success = true; - vec_edges_t vec_edges = {pair_edge_t(0, 0), pair_edge_t(0, 11), pair_edge_t(1, 3), pair_edge_t(1, 4), - pair_edge_t(3, 2), pair_edge_t(7, 5), pair_edge_t(7, 7), pair_edge_t(10, 6)}; - vec_owners_t vec_owners = {pair_owner_t(0, 0), pair_owner_t(1, 0), pair_owner_t(3, 0), pair_owner_t(7, 1), - pair_owner_t(10, 1)}; + vec_edges_type vec_edges = {pair_edge_type(0, 0), pair_edge_type(0, 11), pair_edge_type(1, 3), pair_edge_type(1, 4), + pair_edge_type(3, 2), pair_edge_type(7, 5), pair_edge_type(7, 7), pair_edge_type(10, 6)}; + vec_owners_type vec_owners = {pair_owner_type(0, 0), pair_owner_type(1, 0), pair_owner_type(3, 0), pair_owner_type(7, 1), + pair_owner_type(10, 1)}; if(verbose) { @@ -335,27 +335,27 @@ TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL(CrsGraph, Swap, LO, GO, Node) } out << ">>> create graph_a" << std::endl; - RCP graph_a = generate_crsgraph(comm, vec_edges, vec_owners, 12); + RCP graph_a = generate_crsgraph(comm, vec_edges, vec_owners, 12); //graph_a->describe(out, Teuchos::VERB_DEFAULT); out << ">>> create graph_b" << std::endl; - RCP graph_b = generate_crsgraph(comm, vec_edges, vec_owners, 12); + RCP graph_b = generate_crsgraph(comm, vec_edges, vec_owners, 12); //graph_b->describe(out, Teuchos::VERB_DEFAULT); vec_edges.clear(); vec_owners.clear(); - vec_edges = {pair_edge_t(0, 0), pair_edge_t(0, 11), pair_edge_t(1, 7), pair_edge_t(1, 8), - pair_edge_t(3, 1), pair_edge_t(7, 5), pair_edge_t(10, 4) }; - vec_owners = {pair_owner_t(0, 0), pair_owner_t(1, 0), pair_owner_t(3, 1), pair_owner_t(7, 1), - pair_owner_t(10, 1)}; + vec_edges = {pair_edge_type(0, 0), pair_edge_type(0, 11), pair_edge_type(1, 7), pair_edge_type(1, 8), + pair_edge_type(3, 1), pair_edge_type(7, 5), pair_edge_type(10, 4) }; + vec_owners = {pair_owner_type(0, 0), pair_owner_type(1, 0), pair_owner_type(3, 1), pair_owner_type(7, 1), + pair_owner_type(10, 1)}; out << ">>> create graph_c" << std::endl; - RCP graph_c = generate_crsgraph(comm, vec_edges, vec_owners, 12); + RCP graph_c = generate_crsgraph(comm, vec_edges, vec_owners, 12); //graph_c->describe(out, Teuchos::VERB_DEFAULT); out << ">>> create graph_d" << std::endl; - RCP graph_d = generate_crsgraph(comm, vec_edges, vec_owners, 12); + RCP graph_d = generate_crsgraph(comm, vec_edges, vec_owners, 12); //graph_d->describe(out, Teuchos::VERB_DEFAULT); TEST_EQUALITY(graph_a->isIdenticalTo(*graph_b), true); // graph_a and graph_b should be the same From f9cd138705c2a7e88602d251605df5b4bf3e396c Mon Sep 17 00:00:00 2001 From: William McLendon Date: Wed, 19 Dec 2018 15:42:40 -0700 Subject: [PATCH 3/5] Tpetra: Fix requested changes from PR 4089 --- .../test/CrsGraph/CrsGraph_UnitTests_Swap.cpp | 69 +++++++++---------- 1 file changed, 33 insertions(+), 36 deletions(-) diff --git a/packages/tpetra/core/test/CrsGraph/CrsGraph_UnitTests_Swap.cpp b/packages/tpetra/core/test/CrsGraph/CrsGraph_UnitTests_Swap.cpp index a7334994223e..a9b489769ea7 100644 --- a/packages/tpetra/core/test/CrsGraph/CrsGraph_UnitTests_Swap.cpp +++ b/packages/tpetra/core/test/CrsGraph/CrsGraph_UnitTests_Swap.cpp @@ -125,28 +125,25 @@ TEUCHOS_STATIC_SETUP() // gbl_num_columns: Max # of columns in the matrix-representation of the graph. // This should be >= the highest value of v from all edges (u,v) in edges. // Note: u and v are 0-indexed, so if the highest v is 11, then this should be 12. -template -Teuchos::RCP> -generate_crsgraph(Teuchos::RCP comm, - const std::vector>& gbl_edges, - const std::vector>& gbl_row_owners, - const size_t gbl_num_columns, - const bool do_fillComplete=true) +template +Teuchos::RCP > +generate_crsgraph(Teuchos::RCP >& comm, + const std::vector >& gbl_edges, + const std::vector >& gbl_row_owners, + const size_t gbl_num_columns, + const bool do_fillComplete=true) { using Teuchos::Comm; - typedef Tpetra::CrsGraph graph_type; - typedef Tpetra::Map map_type; - - typedef typename std::map map_rows_type; // row_id, num_entries - - - typedef typename std::vector vec_go_type; - typedef typename std::map map_row_to_cols_type; + using graph_type = Tpetra::CrsGraph; // Tpetra CrsGraph type + using map_type = Tpetra::Map; // Tpetra Map type + using map_rows_type = std::map; // map rows to pid's + using vec_go_type = std::vector; // vector of GlobalOrdinals + using map_row_to_cols_type = std::map; // Map rows to columns const bool verbose = Tpetra::Details::Behavior::verbose(); - const size_t comm_rank = comm->getRank(); + const int comm_rank = (size_t)comm->getRank(); map_row_to_cols_type gbl_rows; for(auto& e: gbl_edges) @@ -221,8 +218,8 @@ generate_crsgraph(Teuchos::RCP comm, for(auto& r: gbl_rows) { const GO irow = r.first; - const size_t row_pid = gbl_row2pid.find(irow)->second; - if(row_pid == comm_rank) + const int row_pid = gbl_row2pid.find(irow)->second; + if(comm_rank == row_pid) { num_ent_per_row[ idx++ ] = r.second.size(); } @@ -243,8 +240,8 @@ generate_crsgraph(Teuchos::RCP comm, for(auto& r: gbl_rows) { const GO irow = r.first; - const size_t pid = gbl_row2pid.find(irow)->second; - if(pid == comm_rank) + const int pid = gbl_row2pid.find(irow)->second; + if(comm_rank == pid) { std::vector gbl_inds; for(auto& v: r.second) @@ -293,18 +290,17 @@ TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL(CrsGraph, Swap, LO, GO, Node) using Teuchos::outArg; using Teuchos::RCP; - typedef Teuchos::Comm comm_type; - typedef Tpetra::CrsGraph graph_type; + using graph_type = Tpetra::CrsGraph; // Tpetra CrsGraph type + using pair_edge_type = std::pair; // Edge typs, (u,v) using GlobalOrdinal type + using pair_owner_type = std::pair; // For row owners, pairs are (rowid, comm rank) - typedef typename std::pair pair_edge_type; - typedef typename std::pair pair_owner_type; - - typedef typename std::vector vec_edges_type; - typedef typename std::vector vec_owners_type; + using vec_edges_type = std::vector; // For vectors of edges + using vec_owners_type = std::vector; // For vectors of owners bool verbose = Tpetra::Details::Behavior::verbose(); auto initialComm = getDefaultComm(); + TEUCHOS_TEST_FOR_EXCEPTION(initialComm->getSize() < 2, std::runtime_error, "This test requires at least two processors."); // Set up a communicator that has exactly two processors in it for the actual test. @@ -335,12 +331,12 @@ TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL(CrsGraph, Swap, LO, GO, Node) } out << ">>> create graph_a" << std::endl; - RCP graph_a = generate_crsgraph(comm, vec_edges, vec_owners, 12); - //graph_a->describe(out, Teuchos::VERB_DEFAULT); + RCP graph_a = generate_crsgraph(comm, vec_edges, vec_owners, 12); + if(verbose) graph_a->describe(out, Teuchos::VERB_DEFAULT); out << ">>> create graph_b" << std::endl; - RCP graph_b = generate_crsgraph(comm, vec_edges, vec_owners, 12); - //graph_b->describe(out, Teuchos::VERB_DEFAULT); + RCP graph_b = generate_crsgraph(comm, vec_edges, vec_owners, 12); + if(verbose) graph_b->describe(out, Teuchos::VERB_DEFAULT); vec_edges.clear(); vec_owners.clear(); @@ -351,23 +347,24 @@ TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL(CrsGraph, Swap, LO, GO, Node) pair_owner_type(10, 1)}; out << ">>> create graph_c" << std::endl; - RCP graph_c = generate_crsgraph(comm, vec_edges, vec_owners, 12); - //graph_c->describe(out, Teuchos::VERB_DEFAULT); + RCP graph_c = generate_crsgraph(comm, vec_edges, vec_owners, 12); + if(verbose) graph_c->describe(out, Teuchos::VERB_DEFAULT); out << ">>> create graph_d" << std::endl; - RCP graph_d = generate_crsgraph(comm, vec_edges, vec_owners, 12); - //graph_d->describe(out, Teuchos::VERB_DEFAULT); + RCP graph_d = generate_crsgraph(comm, vec_edges, vec_owners, 12); + if(verbose) graph_d->describe(out, Teuchos::VERB_DEFAULT); + // Verify the initial identical-to state of the graphs. TEST_EQUALITY(graph_a->isIdenticalTo(*graph_b), true); // graph_a and graph_b should be the same TEST_EQUALITY(graph_c->isIdenticalTo(*graph_d), true); // graph_c and graph_d should be the same TEST_EQUALITY(graph_a->isIdenticalTo(*graph_c), false); // graph_a and graph_c should be different TEST_EQUALITY(graph_b->isIdenticalTo(*graph_d), false); // graph_b and graph_d should be different - // Swap graph b and c out << ">>> swap graph_b and graph_c" << std::endl; graph_c->swap(*graph_b); + // Verify that the graphs did get swapped. TEST_EQUALITY(graph_a->isIdenticalTo(*graph_b), false); // graph_a and graph_b should be different TEST_EQUALITY(graph_c->isIdenticalTo(*graph_d), false); // graph_c and graph_d should be different TEST_EQUALITY(graph_a->isIdenticalTo(*graph_c), true); // graph_a and graph_c should be the same From 0c182056d6d650f10310b12252a63760aee7e972 Mon Sep 17 00:00:00 2001 From: William McLendon Date: Wed, 19 Dec 2018 15:43:14 -0700 Subject: [PATCH 4/5] Tpetra: Fix requested changes from PR 4089 --- packages/tpetra/core/test/CrsGraph/CrsGraph_UnitTests_Swap.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/tpetra/core/test/CrsGraph/CrsGraph_UnitTests_Swap.cpp b/packages/tpetra/core/test/CrsGraph/CrsGraph_UnitTests_Swap.cpp index a9b489769ea7..651c1b7d25db 100644 --- a/packages/tpetra/core/test/CrsGraph/CrsGraph_UnitTests_Swap.cpp +++ b/packages/tpetra/core/test/CrsGraph/CrsGraph_UnitTests_Swap.cpp @@ -114,8 +114,6 @@ TEUCHOS_STATIC_SETUP() " this option is ignored and a serial comm is always used."); clp.setOption("error-tol-slack", &errorTolSlack, "Slack off of machine epsilon used to check test results"); } -// todo: update options so that this test won't run in serial (it's not set up for that currently) - From 039aef01be36c4e485a67843ad5d6c68fcb31d51 Mon Sep 17 00:00:00 2001 From: William McLendon Date: Wed, 19 Dec 2018 17:33:30 -0700 Subject: [PATCH 5/5] Tpetra: Fix requested changes from PR 4089 --- packages/tpetra/core/test/CrsGraph/CrsGraph_UnitTests_Swap.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/tpetra/core/test/CrsGraph/CrsGraph_UnitTests_Swap.cpp b/packages/tpetra/core/test/CrsGraph/CrsGraph_UnitTests_Swap.cpp index 651c1b7d25db..6e019b2174f8 100644 --- a/packages/tpetra/core/test/CrsGraph/CrsGraph_UnitTests_Swap.cpp +++ b/packages/tpetra/core/test/CrsGraph/CrsGraph_UnitTests_Swap.cpp @@ -141,7 +141,7 @@ generate_crsgraph(Teuchos::RCP >& comm, const bool verbose = Tpetra::Details::Behavior::verbose(); - const int comm_rank = (size_t)comm->getRank(); + const int comm_rank = comm->getRank(); map_row_to_cols_type gbl_rows; for(auto& e: gbl_edges)