58 #include <Teuchos_GlobalMPISession.hpp> 59 #include <Teuchos_DefaultComm.hpp> 60 #include <Teuchos_RCP.hpp> 61 #include <Teuchos_Comm.hpp> 62 #include <Teuchos_CommHelpers.hpp> 67 using Teuchos::rcp_const_cast;
69 using Teuchos::DefaultComm;
71 using Teuchos::ArrayView;
73 typedef Tpetra::CrsGraph<zlno_t, zgno_t, znode_t>
tgraph_t;
74 typedef Xpetra::CrsGraph<zlno_t, zgno_t, znode_t>
xgraph_t;
79 int rank = comm->getRank();
80 int nprocs = comm->getSize();
82 for (
int p=0; p < nprocs; p++){
84 std::cout << rank <<
":" << std::endl;
85 for (
zlno_t i=0; i < nvtx; i++){
86 std::cout <<
" vertex " << vtxIds[i] <<
": ";
87 for (
zlno_t j=offsets[i]; j < offsets[i+1]; j++){
88 std::cout << edgeIds[j] <<
" ";
90 std::cout << std::endl;
99 template <
typename User>
105 RCP<const Comm<int> > comm = graph.getComm();
106 int fail = 0, gfail=0;
118 const zgno_t *vtxIds=NULL, *edgeIds=NULL;
119 const zlno_t *offsets=NULL;
128 if (nvtx != graph.getNodeNumRows())
134 printGraph(comm, nvtx, vtxIds, offsets, edgeIds);
143 int main(
int argc,
char *argv[])
145 Teuchos::GlobalMPISession session(&argc, &argv);
146 RCP<const Comm<int> > comm = DefaultComm<int>::getComm();
147 int rank = comm->getRank();
148 int fail = 0, gfail=0;
154 RCP<UserInputForTests> uinput;
160 catch(std::exception &e){
162 std::cout << e.what() << std::endl;
169 tG = uinput->getUITpetraCrsGraph();
170 size_t nvtx = tG->getNodeNumRows();
181 typedef adapter_t::part_t part_t;
183 part_t *p =
new part_t [nvtx];
184 memset(p, 0,
sizeof(part_t) * nvtx);
185 ArrayRCP<part_t> solnParts(p, 0, nvtx,
true);
187 soln_t solution(env, comm, nWeights);
188 solution.setParts(solnParts);
194 std::cout <<
"Input adapter for Tpetra::CrsGraph" << std::endl;
196 RCP<const tgraph_t> ctG = rcp_const_cast<
const tgraph_t>(tG);
197 RCP<Zoltan2::XpetraCrsGraphAdapter<tgraph_t> > tGInput;
203 catch (std::exception &e){
205 std::cout << e.what() << std::endl;
209 fail = verifyInputAdapter<tgraph_t>(*tGInput, *tG);
216 tGInput->applyPartitioningSolution( *tG, mMigrate, solution);
217 newG = rcp(mMigrate);
219 catch (std::exception &e){
226 RCP<const tgraph_t> cnewG = rcp_const_cast<
const tgraph_t>(newG);
227 RCP<Zoltan2::XpetraCrsGraphAdapter<tgraph_t> > newInput;
231 catch (std::exception &e){
233 std::cout << e.what() << std::endl;
239 "Input adapter for Tpetra::CrsGraph migrated to proc 0" <<
242 fail = verifyInputAdapter<tgraph_t>(*newInput, *newG);
256 std::cout <<
"Input adapter for Xpetra::CrsGraph" << std::endl;
258 RCP<xgraph_t> xG = uinput->getUIXpetraCrsGraph();
259 RCP<const xgraph_t> cxG = rcp_const_cast<
const xgraph_t>(xG);
260 RCP<Zoltan2::XpetraCrsGraphAdapter<xgraph_t> > xGInput;
266 catch (std::exception &e){
268 std::cout << e.what() << std::endl;
272 fail = verifyInputAdapter<xgraph_t>(*xGInput, *tG);
279 xGInput->applyPartitioningSolution( *xG, mMigrate, solution);
281 catch (std::exception &e){
288 RCP<const xgraph_t> cnewG(mMigrate);
289 RCP<Zoltan2::XpetraCrsGraphAdapter<xgraph_t> > newInput;
294 catch (std::exception &e){
296 std::cout << e.what() << std::endl;
302 "Input adapter for Xpetra::CrsGraph migrated to proc 0" <<
305 fail = verifyInputAdapter<xgraph_t>(*newInput, *newG);
315 #ifdef HAVE_EPETRA_DATA_TYPES 318 typedef Epetra_CrsGraph egraph_t;
321 std::cout <<
"Input adapter for Epetra_CrsGraph" << std::endl;
323 RCP<egraph_t> eG = uinput->getUIEpetraCrsGraph();
324 RCP<const egraph_t> ceG = rcp_const_cast<
const egraph_t>(eG);
325 RCP<Zoltan2::XpetraCrsGraphAdapter<egraph_t> > eGInput;
327 bool goodAdapter =
true;
332 catch (std::exception &e){
333 if (std::is_same<znode_t, Xpetra::EpetraNode>::value) {
336 std::cout << e.what() << std::endl;
341 std::cout <<
"Node type is not supported by Xpetra's Epetra interface;" 342 <<
" Skipping this test." << std::endl;
343 std::cout <<
"FYI: Here's the exception message: " << std::endl
344 << e.what() << std::endl;
351 fail = verifyInputAdapter<egraph_t>(*eGInput, *tG);
356 egraph_t *mMigrate =NULL;
358 eGInput->applyPartitioningSolution( *eG, mMigrate, solution);
360 catch (std::exception &e){
367 RCP<const egraph_t> cnewG(mMigrate,
true);
368 RCP<Zoltan2::XpetraCrsGraphAdapter<egraph_t> > newInput;
373 catch (std::exception &e){
375 std::cout << e.what() << std::endl;
381 "Input adapter for Epetra_CrsGraph migrated to proc 0" <<
384 fail = verifyInputAdapter<egraph_t>(*newInput, *newG);
400 std::cout <<
"PASS" << std::endl;
void getVertexIDsView(const gno_t *&ids) const
Sets pointers to this process' graph entries.
int globalFail(const RCP< const Comm< int > > &comm, int fail)
#define TEST_FAIL_AND_EXIT(comm, ok, s, code)
Provides access for Zoltan2 to Xpetra::CrsGraph data.
size_t getLocalNumEdges() const
Returns the number of edges on this process.
Defines the PartitioningSolution class.
common code used by tests
size_t getLocalNumVertices() const
Returns the number of vertices on this process.
Defines XpetraCrsGraphAdapter class.
A PartitioningSolution is a solution to a partitioning problem.
The user parameters, debug, timing and memory profiling output objects, and error checking methods...
static const std::string fail
void printFailureCode(const RCP< const Comm< int > > &comm, int fail)
void getEdgesView(const lno_t *&offsets, const gno_t *&adjIds) const
Gets adjacency lists for all vertices in a compressed sparse row (CSR) format.
std::string testDataFilePath(".")