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;
208 RCP<const tvector_t> ctV = rcp_const_cast<
const tvector_t>(tV);
209 RCP<adapter_t> tVInput;
214 emptyWeights, emptyStrides));
216 catch (std::exception &e){
218 std::cout << e.what() << std::endl;
223 std::cout <<
"Constructed with ";
224 std::cout <<
"Tpetra::Vector" << std::endl;
227 fail = verifyInputAdapter<tvector_t>(*tVInput, *tV, 0, NULL, NULL);
234 tVInput->applyPartitioningSolution(*tV, vMigrate, solution);
235 newV = rcp(vMigrate);
237 catch (std::exception &e){
244 RCP<const tvector_t> cnewV = rcp_const_cast<
const tvector_t>(newV);
245 RCP<Zoltan2::XpetraMultiVectorAdapter<tvector_t> > newInput;
248 emptyWeights, emptyStrides));
250 catch (std::exception &e){
252 std::cout << e.what() << std::endl;
257 std::cout <<
"Constructed with ";
258 std::cout <<
"Tpetra::Vector migrated to proc 0" << std::endl;
260 fail = verifyInputAdapter<tvector_t>(*newInput, *newV, 0, NULL, NULL);
261 if (fail) fail += 100;
274 rcp(
new tvector_t(uinput->getUITpetraCrsGraph()->getRowMap()));
277 RCP<const xvector_t> cxV = rcp_const_cast<
const xvector_t>(xV);
278 RCP<Zoltan2::XpetraMultiVectorAdapter<xvector_t> > xVInput;
283 emptyWeights, emptyStrides));
285 catch (std::exception &e){
287 std::cout << e.what() << std::endl;
292 std::cout <<
"Constructed with ";
293 std::cout <<
"Xpetra::Vector" << std::endl;
295 fail = verifyInputAdapter<xvector_t>(*xVInput, *tV, 0, NULL, NULL);
302 xVInput->applyPartitioningSolution(*xV, vMigrate, solution);
304 catch (std::exception &e){
311 RCP<const xvector_t> cnewV(vMigrate);
312 RCP<Zoltan2::XpetraMultiVectorAdapter<xvector_t> > newInput;
316 emptyWeights, emptyStrides));
318 catch (std::exception &e){
320 std::cout << e.what() << std::endl;
325 std::cout <<
"Constructed with ";
326 std::cout <<
"Xpetra::Vector migrated to proc 0" << std::endl;
328 fail = verifyInputAdapter<xvector_t>(*newInput, *newV, 0, NULL, NULL);
329 if (fail) fail += 100;
338 #ifdef HAVE_EPETRA_DATA_TYPES 341 typedef Epetra_Vector evector_t;
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;
352 emptyWeights, emptyStrides));
354 catch (std::exception &e){
356 std::cout << e.what() << std::endl;
361 std::cout <<
"Constructed with ";
362 std::cout <<
"Epetra_Vector" << std::endl;
364 fail = verifyInputAdapter<evector_t>(*eVInput, *tV, 0, NULL, NULL);
369 evector_t *vMigrate =NULL;
371 eVInput->applyPartitioningSolution(*eV, vMigrate, solution);
373 catch (std::exception &e){
380 RCP<const evector_t> cnewV(vMigrate,
true);
381 RCP<Zoltan2::XpetraMultiVectorAdapter<evector_t> > newInput;
385 emptyWeights, emptyStrides));
387 catch (std::exception &e){
389 std::cout << e.what() << std::endl;
394 std::cout <<
"Constructed with ";
395 std::cout <<
"Epetra_Vector migrated to proc 0" << std::endl;
397 fail = verifyInputAdapter<evector_t>(*newInput, *newV, 0, NULL, NULL);
398 if (fail) fail += 100;
412 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 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(".")