58 #include <Teuchos_DefaultComm.hpp>
59 #include <Teuchos_RCP.hpp>
60 #include <Teuchos_Comm.hpp>
61 #include <Teuchos_CommHelpers.hpp>
65 using Teuchos::rcp_const_cast;
68 typedef Tpetra::Vector<zscalar_t, zlno_t, zgno_t, znode_t>
tvector_t;
69 typedef Xpetra::Vector<zscalar_t, zlno_t, zgno_t, znode_t>
xvector_t;
74 int rank = comm->getRank();
75 int nprocs = comm->getSize();
77 for (
int p=0; p < nprocs; p++){
79 std::cout << rank <<
":" << std::endl;
80 for (
zlno_t i=0; i < vlen; i++){
81 std::cout <<
" " << vtxIds[i] <<
": " << vals[i] << std::endl;
90 template <
typename User>
95 RCP<const Comm<int> > comm = vector.getMap()->getComm();
96 int fail = 0, gfail=0;
110 const zgno_t *vtxIds=NULL;
115 if (nvals != vector.getLocalLength())
121 if (!fail && stride != 1)
135 for (
int w=0; !fail && w < wdim; w++){
138 if (!fail && stride != strides[w])
141 for (
size_t v=0; !fail && v < vector.getLocalLength(); v++){
142 if (wgt[v*stride] != weights[w][v*stride])
154 int main(
int narg,
char *arg[])
156 Tpetra::ScopeGuard tscope(&narg, &arg);
157 Teuchos::RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm();
159 int rank = comm->getRank();
160 int fail = 0, gfail=0;
166 RCP<UserInputForTests> uinput;
167 Teuchos::ParameterList params;
168 params.set(
"input file",
"simple");
169 params.set(
"file type",
"Chaco");
173 catch(std::exception &e){
175 std::cout << e.what() << std::endl;
182 tV = rcp(
new tvector_t(uinput->getUITpetraCrsGraph()->getRowMap()));
184 size_t vlen = tV->getLocalLength();
195 part_t *p =
new part_t [vlen];
196 memset(p, 0,
sizeof(part_t) * vlen);
197 ArrayRCP<part_t> solnParts(p, 0, vlen,
true);
199 std::vector<const zscalar_t *> emptyWeights;
200 std::vector<int> emptyStrides;
209 std::cout <<
"Constructed with Tpetra::Vector" << std::endl;
211 RCP<const tvector_t> ctV = rcp_const_cast<
const tvector_t>(tV);
212 RCP<adapter_t> tVInput;
217 emptyWeights, emptyStrides));
219 catch (std::exception &e){
221 std::cout << e.what() << std::endl;
225 fail = verifyInputAdapter<tvector_t>(*tVInput, *tV, 0, NULL, NULL);
232 tVInput->applyPartitioningSolution(*tV, vMigrate, solution);
233 newV = rcp(vMigrate);
235 catch (std::exception &e){
242 RCP<const tvector_t> cnewV = rcp_const_cast<
const tvector_t>(newV);
243 RCP<Zoltan2::XpetraMultiVectorAdapter<tvector_t> > newInput;
246 emptyWeights, emptyStrides));
248 catch (std::exception &e){
250 std::cout << e.what() << std::endl;
255 std::cout <<
"Constructed with ";
256 std::cout <<
"Tpetra::Vector migrated to proc 0" << std::endl;
258 fail = verifyInputAdapter<tvector_t>(*newInput, *newV, 0, NULL, NULL);
259 if (fail) fail += 100;
272 std::cout <<
"Constructed with Xpetra::Vector" << std::endl;
275 rcp(
new tvector_t(uinput->getUITpetraCrsGraph()->getRowMap()));
278 RCP<const xvector_t> cxV = rcp_const_cast<
const xvector_t>(xV);
279 RCP<Zoltan2::XpetraMultiVectorAdapter<xvector_t> > xVInput;
284 emptyWeights, emptyStrides));
286 catch (std::exception &e){
288 std::cout << e.what() << std::endl;
292 fail = verifyInputAdapter<xvector_t>(*xVInput, *tV, 0, NULL, NULL);
299 xVInput->applyPartitioningSolution(*xV, vMigrate, solution);
301 catch (std::exception &e){
308 RCP<const xvector_t> cnewV(vMigrate);
309 RCP<Zoltan2::XpetraMultiVectorAdapter<xvector_t> > newInput;
313 emptyWeights, emptyStrides));
315 catch (std::exception &e){
317 std::cout << e.what() << std::endl;
322 std::cout <<
"Constructed with ";
323 std::cout <<
"Xpetra::Vector migrated to proc 0" << std::endl;
325 fail = verifyInputAdapter<xvector_t>(*newInput, *newV, 0, NULL, NULL);
326 if (fail) fail += 100;
335 #ifdef HAVE_EPETRA_DATA_TYPES
338 typedef Epetra_Vector evector_t;
341 std::cout <<
"Constructed with Epetra_Vector" << std::endl;
344 rcp(
new Epetra_Vector(uinput->getUIEpetraCrsGraph()->RowMap()));
346 RCP<const evector_t> ceV = rcp_const_cast<
const evector_t>(eV);
347 RCP<Zoltan2::XpetraMultiVectorAdapter<evector_t> > eVInput;
349 bool goodAdapter =
true;
353 emptyWeights, emptyStrides));
355 catch (std::exception &e){
356 if (std::is_same<znode_t, Xpetra::EpetraNode>::value) {
359 std::cout << e.what() << std::endl;
364 std::cout <<
"Node type is not supported by Xpetra's Epetra interface;"
365 <<
" Skipping this test." << std::endl;
366 std::cout <<
"FYI: Here's the exception message: " << std::endl
367 << e.what() << std::endl;
374 fail = verifyInputAdapter<evector_t>(*eVInput, *tV, 0, NULL, NULL);
379 evector_t *vMigrate =NULL;
381 eVInput->applyPartitioningSolution(*eV, vMigrate, solution);
383 catch (std::exception &e){
390 RCP<const evector_t> cnewV(vMigrate,
true);
391 RCP<Zoltan2::XpetraMultiVectorAdapter<evector_t> > newInput;
395 emptyWeights, emptyStrides));
397 catch (std::exception &e){
399 std::cout << e.what() << std::endl;
404 std::cout <<
"Constructed with ";
405 std::cout <<
"Epetra_Vector migrated to proc 0" << std::endl;
407 fail = verifyInputAdapter<evector_t>(*newInput, *newV, 0, NULL, NULL);
408 if (fail) fail += 100;
423 std::cout <<
"PASS" << std::endl;
void printFailureCode(const Comm< int > &comm, int fail)
int main(int narg, char *arg[])
#define TEST_FAIL_AND_EXIT(comm, ok, s, code)
common code used by tests
static RCP< User > convertToXpetra(const RCP< User > &a)
Convert the object to its Xpetra wrapped version.
Defines the XpetraMultiVectorAdapter.
int getNumEntriesPerID() const
Return the number of vectors.
SparseMatrixAdapter_t::part_t part_t
A PartitioningSolution is a solution to a partitioning problem.
void getEntriesView(const scalar_t *&elements, int &stride, int idx=0) const
The user parameters, debug, timing and memory profiling output objects, and error checking methods...
int getNumWeightsPerID() const
Returns the number of weights per object. Number of weights per object should be zero or greater...
An adapter for Xpetra::MultiVector.
static const std::string fail
void setParts(ArrayRCP< part_t > &partList)
The algorithm uses setParts to set the solution.
int globalFail(const Comm< int > &comm, int fail)
void getIDsView(const gno_t *&ids) const
Provide a pointer to this process' identifiers.
size_t getLocalNumIDs() const
Returns the number of objects on this process.
void getWeightsView(const scalar_t *&weights, int &stride, int idx) const