61 #include <Teuchos_GlobalMPISession.hpp> 62 #include <Teuchos_DefaultComm.hpp> 63 #include <Teuchos_RCP.hpp> 64 #include <Teuchos_Comm.hpp> 65 #include <Teuchos_CommHelpers.hpp> 70 using Teuchos::rcp_const_cast;
72 using Teuchos::DefaultComm;
74 typedef Tpetra::MultiVector<zscalar_t, zlno_t, zgno_t, znode_t>
tvector_t;
75 typedef Xpetra::MultiVector<zscalar_t, zlno_t, zgno_t, znode_t>
xvector_t;
77 template <
typename User>
82 RCP<const Comm<int> > comm = vector.getMap()->getComm();
83 int fail = 0, gfail=0;
91 size_t length = vector.getLocalLength();
104 if (nvals != vector.getLocalLength())
109 for (
int v=0; v < nvec; v++){
112 if (!fail && stride != 1)
125 for (
int w=0; !fail && w < wdim; w++){
128 if (!fail && stride != strides[w])
131 for (
size_t v=0; !fail && v < vector.getLocalLength(); v++){
132 if (wgt[v*stride] != weights[w][v*stride])
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;
171 tV = rcp(
new tvector_t(uinput->getUITpetraCrsGraph()->getRowMap(), nVec));
174 size_t vlen = tV->getLocalLength();
184 typedef ia_t::part_t part_t;
186 part_t *p =
new part_t [vlen];
187 memset(p, 0,
sizeof(part_t) * vlen);
188 ArrayRCP<part_t> solnParts(p, 0, vlen,
true);
190 soln_t solution(env, comm, nWeights);
191 solution.setParts(solnParts);
193 std::vector<const zscalar_t *> emptyWeights;
194 std::vector<int> emptyStrides;
200 std::cout <<
"Constructed with Tpetra::MultiVector" << std::endl;
202 RCP<const tvector_t> ctV = rcp_const_cast<
const tvector_t>(tV);
203 RCP<Zoltan2::XpetraMultiVectorAdapter<tvector_t> > tVInput;
208 emptyWeights, emptyStrides));
210 catch (std::exception &e){
212 std::cout << e.what() << std::endl;
216 fail = verifyInputAdapter<tvector_t>(*tVInput, *tV, nVec, 0, NULL, NULL);
223 tVInput->applyPartitioningSolution(*tV, vMigrate, solution);
224 newV = rcp(vMigrate);
226 catch (std::exception &e){
233 RCP<const tvector_t> cnewV = rcp_const_cast<
const tvector_t>(newV);
234 RCP<Zoltan2::XpetraMultiVectorAdapter<tvector_t> > newInput;
237 cnewV, emptyWeights, emptyStrides));
239 catch (std::exception &e){
241 std::cout << e.what() << std::endl;
246 std::cout <<
"Constructed with ";
247 std::cout <<
"Tpetra::MultiVector migrated to proc 0" << std::endl;
249 fail = verifyInputAdapter<tvector_t>(*newInput, *newV, nVec, 0, NULL, NULL);
250 if (fail) fail += 100;
263 std::cout <<
"Constructed with Xpetra::MultiVector" << std::endl;
266 rcp(
new tvector_t(uinput->getUITpetraCrsGraph()->getRowMap(), nVec));
269 RCP<const xvector_t> cxV = rcp_const_cast<
const xvector_t>(xV);
270 RCP<Zoltan2::XpetraMultiVectorAdapter<xvector_t> > xVInput;
275 emptyWeights, emptyStrides));
277 catch (std::exception &e){
279 std::cout << e.what() << std::endl;
283 fail = verifyInputAdapter<xvector_t>(*xVInput, *tV, nVec, 0, NULL, NULL);
290 xVInput->applyPartitioningSolution(*xV, vMigrate, solution);
292 catch (std::exception &e){
299 RCP<const xvector_t> cnewV(vMigrate);
300 RCP<Zoltan2::XpetraMultiVectorAdapter<xvector_t> > newInput;
304 cnewV, emptyWeights, emptyStrides));
306 catch (std::exception &e){
308 std::cout << e.what() << std::endl;
313 std::cout <<
"Constructed with ";
314 std::cout <<
"Xpetra::MultiVector migrated to proc 0" << std::endl;
316 fail = verifyInputAdapter<xvector_t>(*newInput, *newV, nVec, 0, NULL, NULL);
317 if (fail) fail += 100;
326 #ifdef HAVE_EPETRA_DATA_TYPES 329 typedef Epetra_MultiVector evector_t;
332 std::cout <<
"Constructed with Epetra_MultiVector" << std::endl;
335 rcp(
new Epetra_MultiVector(uinput->getUIEpetraCrsGraph()->RowMap(),
338 RCP<const evector_t> ceV = rcp_const_cast<
const evector_t>(eV);
339 RCP<Zoltan2::XpetraMultiVectorAdapter<evector_t> > eVInput;
341 bool goodAdapter =
true;
345 emptyWeights, emptyStrides));
347 catch (std::exception &e){
348 if (std::is_same<znode_t, Xpetra::EpetraNode>::value) {
351 std::cout << e.what() << std::endl;
356 std::cout <<
"Node type is not supported by Xpetra's Epetra interface;" 357 <<
" Skipping this test." << std::endl;
358 std::cout <<
"FYI: Here's the exception message: " << std::endl
359 << e.what() << std::endl;
366 fail = verifyInputAdapter<evector_t>(*eVInput, *tV, nVec, 0, NULL, NULL);
371 evector_t *vMigrate =NULL;
373 eVInput->applyPartitioningSolution(*eV, vMigrate, solution);
375 catch (std::exception &e){
382 RCP<const evector_t> cnewV(vMigrate,
true);
383 RCP<Zoltan2::XpetraMultiVectorAdapter<evector_t> > newInput;
387 emptyWeights, emptyStrides));
389 catch (std::exception &e){
391 std::cout << e.what() << std::endl;
396 std::cout <<
"Constructed with ";
397 std::cout <<
"Epetra_MultiVector migrated to proc 0" << std::endl;
399 fail = verifyInputAdapter<evector_t>(*newInput, *newV, nVec, 0, NULL, NULL);
400 if (fail) fail += 100;
415 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.
int getNumEntriesPerID() const
Return the number of vectors (typically one).
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 printFailureCode(const RCP< 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
std::string testDataFilePath(".")