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;
78 template <
typename User>
81 int wdim,
zscalar_t **weights,
int *strides)
83 RCP<const Comm<int> > comm = vector.getMap()->getComm();
84 int fail = 0, gfail=0;
92 size_t length = vector.getLocalLength();
100 const zgno_t *vtxIds=NULL;
105 if (nvals != vector.getLocalLength())
110 for (
int v=0; v < nvec; v++){
113 if (!fail && stride != 1)
126 for (
int w=0; !fail && w < wdim; w++){
129 if (!fail && stride != strides[w])
132 for (
size_t v=0; !fail && v < vector.getLocalLength(); v++){
133 if (wgt[v*stride] != weights[w][v*stride])
144 int main(
int argc,
char *argv[])
146 Teuchos::GlobalMPISession session(&argc, &argv);
147 RCP<const Comm<int> > comm = DefaultComm<int>::getComm();
148 int rank = comm->getRank();
149 int fail = 0, gfail=0;
154 RCP<UserInputForTests> uinput;
160 catch(std::exception &e){
169 tV = rcp(
new tvector_t(uinput->getUITpetraCrsGraph()->getRowMap(), nVec));
172 size_t vlen = tV->getLocalLength();
182 typedef ia_t::part_t part_t;
184 part_t *p =
new part_t [vlen];
185 memset(p, 0,
sizeof(part_t) * vlen);
186 ArrayRCP<part_t> solnParts(p, 0, vlen,
true);
188 soln_t solution(env, comm, nWeights);
189 solution.setParts(solnParts);
191 std::vector<const zscalar_t *> emptyWeights;
192 std::vector<int> emptyStrides;
197 RCP<const tvector_t> ctV = rcp_const_cast<
const tvector_t>(tV);
198 RCP<Zoltan2::XpetraMultiVectorAdapter<tvector_t> > tVInput;
203 emptyWeights, emptyStrides));
205 catch (std::exception &e){
207 string(
"XpetraMultiVectorAdapter ")+e.what(), 1);
211 std::cout <<
"Constructed with ";
212 std::cout <<
"Tpetra::MultiVector" << std::endl;
215 fail = verifyInputAdapter<tvector_t>(*tVInput, *tV, nVec, 0, NULL, NULL);
222 tVInput->applyPartitioningSolution(*tV, vMigrate, solution);
223 newV = rcp(vMigrate);
225 catch (std::exception &e){
232 RCP<const tvector_t> cnewV = rcp_const_cast<
const tvector_t>(newV);
233 RCP<Zoltan2::XpetraMultiVectorAdapter<tvector_t> > newInput;
236 cnewV, emptyWeights, emptyStrides));
238 catch (std::exception &e){
240 string(
"XpetraMultiVectorAdapter 2 ")+e.what(), 1);
244 std::cout <<
"Constructed with ";
245 std::cout <<
"Tpetra::MultiVector migrated to proc 0" << std::endl;
247 fail = verifyInputAdapter<tvector_t>(*newInput, *newV, nVec, 0, NULL, NULL);
248 if (fail) fail += 100;
261 rcp(
new tvector_t(uinput->getUITpetraCrsGraph()->getRowMap(), nVec));
264 RCP<const xvector_t> cxV = rcp_const_cast<
const xvector_t>(xV);
265 RCP<Zoltan2::XpetraMultiVectorAdapter<xvector_t> > xVInput;
270 emptyWeights, emptyStrides));
272 catch (std::exception &e){
274 string(
"XpetraMultiVectorAdapter 3 ")+e.what(), 1);
278 std::cout <<
"Constructed with ";
279 std::cout <<
"Xpetra::MultiVector" << std::endl;
281 fail = verifyInputAdapter<xvector_t>(*xVInput, *tV, nVec, 0, NULL, NULL);
288 xVInput->applyPartitioningSolution(*xV, vMigrate, solution);
290 catch (std::exception &e){
297 RCP<const xvector_t> cnewV(vMigrate);
298 RCP<Zoltan2::XpetraMultiVectorAdapter<xvector_t> > newInput;
302 cnewV, emptyWeights, emptyStrides));
304 catch (std::exception &e){
306 string(
"XpetraMultiVectorAdapter 4 ")+e.what(), 1);
310 std::cout <<
"Constructed with ";
311 std::cout <<
"Xpetra::MultiVector migrated to proc 0" << std::endl;
313 fail = verifyInputAdapter<xvector_t>(*newInput, *newV, nVec, 0, NULL, NULL);
314 if (fail) fail += 100;
323 #ifdef HAVE_EPETRA_DATA_TYPES 328 rcp(
new Epetra_MultiVector(uinput->getUIEpetraCrsGraph()->RowMap(),
331 RCP<const evector_t> ceV = rcp_const_cast<
const evector_t>(eV);
332 RCP<Zoltan2::XpetraMultiVectorAdapter<evector_t> > eVInput;
337 emptyWeights, emptyStrides));
339 catch (std::exception &e){
341 string(
"XpetraMultiVectorAdapter 5 ")+e.what(), 1);
345 std::cout <<
"Constructed with ";
346 std::cout <<
"Epetra_MultiVector" << std::endl;
348 fail = verifyInputAdapter<evector_t>(*eVInput, *tV, nVec, 0, NULL, NULL);
355 eVInput->applyPartitioningSolution(*eV, vMigrate, solution);
357 catch (std::exception &e){
364 RCP<const evector_t> cnewV(vMigrate,
true);
365 RCP<Zoltan2::XpetraMultiVectorAdapter<evector_t> > newInput;
369 emptyWeights, emptyStrides));
371 catch (std::exception &e){
373 string(
"XpetraMultiVectorAdapter 6 ")+e.what(), 1);
377 std::cout <<
"Constructed with ";
378 std::cout <<
"Epetra_MultiVector migrated to proc 0" << std::endl;
380 fail = verifyInputAdapter<evector_t>(*newInput, *newV, nVec, 0, NULL, NULL);
381 if (fail) fail += 100;
395 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
Provide a pointer to the elements of the specified vector.
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.
void printFailureCode(const RCP< const Comm< int > > &comm, int fail)
void getIDsView(const gno_t *&ids) const
size_t getLocalNumIDs() const
Returns the number of objects on this process.
void getWeightsView(const scalar_t *&weights, int &stride, int idx) const
Provide pointer to a weight array with stride.
std::string testDataFilePath(".")