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 typedef Tpetra::Vector<zscalar_t, zlno_t, zgno_t, znode_t>
tvector_t;
72 typedef Xpetra::Vector<zscalar_t, zlno_t, zgno_t, znode_t>
xvector_t;
77 int rank = comm->getRank();
78 int nprocs = comm->getSize();
80 for (
int p=0; p < nprocs; p++){
82 std::cout << rank <<
":" << std::endl;
83 for (
zlno_t i=0; i < vlen; i++){
84 std::cout <<
" " << vtxIds[i] <<
": " <<
vals[i] << std::endl;
93 template <
typename User>
98 RCP<const Comm<int> > comm = vector.getMap()->getComm();
99 int fail = 0, gfail=0;
113 const zgno_t *vtxIds=NULL;
118 if (nvals != vector.getLocalLength())
124 if (!
fail && stride != 1)
138 for (
int w=0; !
fail && w < wdim; w++){
141 if (!
fail && stride != strides[w])
144 for (
size_t v=0; !
fail && v < vector.getLocalLength(); v++){
145 if (wgt[v*stride] !=
weights[w][v*stride])
156 int main(
int argc,
char *argv[])
158 Teuchos::GlobalMPISession session(&argc, &argv);
159 RCP<const Comm<int> > comm = DefaultComm<int>::getComm();
160 int rank = comm->getRank();
161 int fail = 0, gfail=0;
167 RCP<UserInputForTests> uinput;
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();
193 typedef adapter_t::part_t part_t;
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);
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);
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);
423 std::cout <<
"PASS" << std::endl;
int globalFail(const RCP< const Comm< int > > &comm, int fail)
#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.
size_t getLocalNumIDs() const
Returns the number of objects on this process.
A PartitioningSolution is a solution to a partitioning problem.
int getNumEntriesPerID() const
Return the number of vectors (typically one).
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...
An adapter for Xpetra::MultiVector.
static const std::string fail
void setParts(ArrayRCP< part_t > &partList)
The algorithm uses setParts to set the solution.
void printFailureCode(const RCP< const Comm< int > > &comm, int fail)
void getIDsView(const gno_t *&ids) const
Provide a pointer to this process' identifiers.
int getNumWeightsPerID() const
Returns the number of weights per object. Number of weights per object should be zero or greater...
void getWeightsView(const scalar_t *&weights, int &stride, int idx) const
std::string testDataFilePath(".")