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;
78 int rank = comm->getRank();
79 int nprocs = comm->getSize();
81 for (
int p=0; p < nprocs; p++){
83 std::cout << rank <<
":" << std::endl;
84 for (
zlno_t i=0; i < vlen; i++){
85 std::cout <<
" " << vtxIds[i] <<
": " << vals[i] << std::endl;
94 template <
typename User>
99 RCP<const Comm<int> > comm = vector.getMap()->getComm();
100 int fail = 0, gfail=0;
114 const zgno_t *vtxIds=NULL;
119 if (nvals != vector.getLocalLength())
125 if (!fail && stride != 1)
139 for (
int w=0; !fail && w < wdim; w++){
142 if (!fail && stride != strides[w])
145 for (
size_t v=0; !fail && v < vector.getLocalLength(); v++){
146 if (wgt[v*stride] != weights[w][v*stride])
157 int main(
int argc,
char *argv[])
159 Teuchos::GlobalMPISession session(&argc, &argv);
160 RCP<const Comm<int> > comm = DefaultComm<int>::getComm();
161 int rank = comm->getRank();
162 int fail = 0, gfail=0;
167 RCP<UserInputForTests> uinput;
173 catch(std::exception &e){
180 tV = rcp(
new tvector_t(uinput->getUITpetraCrsGraph()->getRowMap()));
182 size_t vlen = tV->getLocalLength();
191 typedef adapter_t::part_t part_t;
193 part_t *p =
new part_t [vlen];
194 memset(p, 0,
sizeof(part_t) * vlen);
195 ArrayRCP<part_t> solnParts(p, 0, vlen,
true);
197 std::vector<const zscalar_t *> emptyWeights;
198 std::vector<int> emptyStrides;
206 RCP<const tvector_t> ctV = rcp_const_cast<
const tvector_t>(tV);
207 RCP<adapter_t> tVInput;
212 emptyWeights, emptyStrides));
214 catch (std::exception &e){
216 string(
"XpetraMultiVectorAdapter ")+e.what(), 1);
220 std::cout <<
"Constructed with ";
221 std::cout <<
"Tpetra::Vector" << std::endl;
224 fail = verifyInputAdapter<tvector_t>(*tVInput, *tV, 0, NULL, NULL);
231 tVInput->applyPartitioningSolution(*tV, vMigrate, solution);
232 newV = rcp(vMigrate);
234 catch (std::exception &e){
241 RCP<const tvector_t> cnewV = rcp_const_cast<
const tvector_t>(newV);
242 RCP<Zoltan2::XpetraMultiVectorAdapter<tvector_t> > newInput;
245 emptyWeights, emptyStrides));
247 catch (std::exception &e){
249 string(
"XpetraMultiVectorAdapter 2 ")+e.what(), 1);
253 std::cout <<
"Constructed with ";
254 std::cout <<
"Tpetra::Vector migrated to proc 0" << std::endl;
256 fail = verifyInputAdapter<tvector_t>(*newInput, *newV, 0, NULL, NULL);
257 if (fail) fail += 100;
270 rcp(
new tvector_t(uinput->getUITpetraCrsGraph()->getRowMap()));
273 RCP<const xvector_t> cxV = rcp_const_cast<
const xvector_t>(xV);
274 RCP<Zoltan2::XpetraMultiVectorAdapter<xvector_t> > xVInput;
279 emptyWeights, emptyStrides));
281 catch (std::exception &e){
283 string(
"XpetraMultiVectorAdapter 3 ")+e.what(), 1);
287 std::cout <<
"Constructed with ";
288 std::cout <<
"Xpetra::Vector" << std::endl;
290 fail = verifyInputAdapter<xvector_t>(*xVInput, *tV, 0, NULL, NULL);
297 xVInput->applyPartitioningSolution(*xV, vMigrate, solution);
299 catch (std::exception &e){
306 RCP<const xvector_t> cnewV(vMigrate);
307 RCP<Zoltan2::XpetraMultiVectorAdapter<xvector_t> > newInput;
311 emptyWeights, emptyStrides));
313 catch (std::exception &e){
315 string(
"XpetraMultiVectorAdapter 4 ")+e.what(), 1);
319 std::cout <<
"Constructed with ";
320 std::cout <<
"Xpetra::Vector migrated to proc 0" << std::endl;
322 fail = verifyInputAdapter<xvector_t>(*newInput, *newV, 0, NULL, NULL);
323 if (fail) fail += 100;
332 #ifdef HAVE_EPETRA_DATA_TYPES 337 rcp(
new Epetra_Vector(uinput->getUIEpetraCrsGraph()->RowMap()));
339 RCP<const evector_t> ceV = rcp_const_cast<
const evector_t>(eV);
340 RCP<Zoltan2::XpetraMultiVectorAdapter<evector_t> > eVInput;
345 emptyWeights, emptyStrides));
347 catch (std::exception &e){
349 string(
"XpetraMultiVectorAdapter 5 ")+e.what(), 1);
353 std::cout <<
"Constructed with ";
354 std::cout <<
"Epetra_Vector" << std::endl;
356 fail = verifyInputAdapter<evector_t>(*eVInput, *tV, 0, NULL, 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 string(
"XpetraMultiVectorAdapter 6 ")+e.what(), 1);
385 std::cout <<
"Constructed with ";
386 std::cout <<
"Epetra_Vector migrated to proc 0" << std::endl;
388 fail = verifyInputAdapter<evector_t>(*newInput, *newV, 0, NULL, NULL);
389 if (fail) fail += 100;
403 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 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
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(".")