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;
199 RCP<const tvector_t> ctV = rcp_const_cast<
const tvector_t>(tV);
200 RCP<Zoltan2::XpetraMultiVectorAdapter<tvector_t> > tVInput;
205 emptyWeights, emptyStrides));
207 catch (std::exception &e){
209 std::cout << e.what() << std::endl;
214 std::cout <<
"Constructed with ";
215 std::cout <<
"Tpetra::MultiVector" << std::endl;
218 fail = verifyInputAdapter<tvector_t>(*tVInput, *tV, nVec, 0, NULL, NULL);
225 tVInput->applyPartitioningSolution(*tV, vMigrate, solution);
226 newV = rcp(vMigrate);
228 catch (std::exception &e){
235 RCP<const tvector_t> cnewV = rcp_const_cast<
const tvector_t>(newV);
236 RCP<Zoltan2::XpetraMultiVectorAdapter<tvector_t> > newInput;
239 cnewV, emptyWeights, emptyStrides));
241 catch (std::exception &e){
243 std::cout << e.what() << std::endl;
248 std::cout <<
"Constructed with ";
249 std::cout <<
"Tpetra::MultiVector migrated to proc 0" << std::endl;
251 fail = verifyInputAdapter<tvector_t>(*newInput, *newV, nVec, 0, NULL, NULL);
252 if (fail) fail += 100;
265 rcp(
new tvector_t(uinput->getUITpetraCrsGraph()->getRowMap(), nVec));
268 RCP<const xvector_t> cxV = rcp_const_cast<
const xvector_t>(xV);
269 RCP<Zoltan2::XpetraMultiVectorAdapter<xvector_t> > xVInput;
274 emptyWeights, emptyStrides));
276 catch (std::exception &e){
278 std::cout << e.what() << std::endl;
283 std::cout <<
"Constructed with ";
284 std::cout <<
"Xpetra::MultiVector" << std::endl;
286 fail = verifyInputAdapter<xvector_t>(*xVInput, *tV, nVec, 0, NULL, NULL);
293 xVInput->applyPartitioningSolution(*xV, vMigrate, solution);
295 catch (std::exception &e){
302 RCP<const xvector_t> cnewV(vMigrate);
303 RCP<Zoltan2::XpetraMultiVectorAdapter<xvector_t> > newInput;
307 cnewV, emptyWeights, emptyStrides));
309 catch (std::exception &e){
311 std::cout << e.what() << std::endl;
316 std::cout <<
"Constructed with ";
317 std::cout <<
"Xpetra::MultiVector migrated to proc 0" << std::endl;
319 fail = verifyInputAdapter<xvector_t>(*newInput, *newV, nVec, 0, NULL, NULL);
320 if (fail) fail += 100;
329 #ifdef HAVE_EPETRA_DATA_TYPES 332 typedef Epetra_MultiVector evector_t;
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;
344 emptyWeights, emptyStrides));
346 catch (std::exception &e){
348 std::cout << e.what() << std::endl;
353 std::cout <<
"Constructed with ";
354 std::cout <<
"Epetra_MultiVector" << std::endl;
356 fail = verifyInputAdapter<evector_t>(*eVInput, *tV, nVec, 0, NULL, NULL);
361 evector_t *vMigrate =NULL;
363 eVInput->applyPartitioningSolution(*eV, vMigrate, solution);
365 catch (std::exception &e){
372 RCP<const evector_t> cnewV(vMigrate,
true);
373 RCP<Zoltan2::XpetraMultiVectorAdapter<evector_t> > newInput;
377 emptyWeights, emptyStrides));
379 catch (std::exception &e){
381 std::cout << e.what() << std::endl;
386 std::cout <<
"Constructed with ";
387 std::cout <<
"Epetra_MultiVector migrated to proc 0" << std::endl;
389 fail = verifyInputAdapter<evector_t>(*newInput, *newV, nVec, 0, NULL, NULL);
390 if (fail) fail += 100;
404 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.
static const std::string fail
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(".")