61 #include <Teuchos_DefaultComm.hpp> 
   62 #include <Teuchos_RCP.hpp> 
   63 #include <Teuchos_Comm.hpp> 
   64 #include <Teuchos_CommHelpers.hpp> 
   68 using Teuchos::rcp_const_cast;
 
   71 typedef Tpetra::MultiVector<zscalar_t, zlno_t, zgno_t, znode_t> 
tvector_t;
 
   72 typedef Xpetra::MultiVector<zscalar_t, zlno_t, zgno_t, znode_t> 
xvector_t;
 
   75 template <
typename User>
 
   79   RCP<const Comm<int> > comm = vector.getMap()->getComm();
 
   80   int fail = 0, gfail=0;
 
   85   size_t length = vector.getLocalLength();
 
   98     if (nvals != vector.getLocalLength())
 
  103     for (
int v=0; v < nvec; v++){
 
  104       auto vecdata = vector.getData(v);
 
  108       if (!fail && stride != 1)
 
  112       for (
size_t i = 0; i < length; i++)
 
  113         if (vals[i*stride] != vecdata[i]) {
 
  126 template <
typename User>
 
  129     std::vector<const zscalar_t *> &
weights, std::vector<int> &strides)
 
  135   RCP<const Comm<int> > comm = vector.getMap()->getComm();
 
  136   int wdim = weights.size();
 
  143   if (!gfail && wdim) {
 
  147     for (
int w=0; !fail && w < wdim; w++){
 
  150       if (!fail && stride != strides[w])
 
  153       for (
size_t v=0; !fail && v < vector.getLocalLength(); v++){
 
  154         if (wgt[v*stride] != weights[w][v*stride])
 
  176   std::getline(fp, line);
 
  177   while (line[0]==
'#') std::getline(fp, line); 
 
  178   std::istringstream issHeader(line);
 
  179   issHeader >> nIDs >> nEdges >> code;
 
  180   if (!strcmp(code, 
"010") || !strcmp(code, 
"011")) {
 
  181     if (!(issHeader >> nWgts)) nWgts = 1;
 
  185 template <
typename User>
 
  188   const char *fileprefixInp,
 
  189   const Teuchos::Comm<int> &comm
 
  195   int fail = 0, gfail=0;
 
  197   std::string tmp(fileprefixInp);
 
  198   tmp = tmp + 
"_generated";
 
  199   const char *fileprefixGen = tmp.c_str();
 
  204   if (comm.getRank() == 0) {
 
  206     size_t nIDsGen, nIDsInp;
 
  207     size_t nEdgesGen, nEdgesInp;
 
  208     char codeGen[4], codeInp[4];
 
  209     int nWgtsGen = 0, nWgtsInp = 0;
 
  210     std::string lineGen, lineInp;
 
  212     std::ifstream fpGen, fpInp;
 
  213     std::string graphFilenameGen = fileprefixGen;
 
  214     graphFilenameGen = graphFilenameGen + 
".graph";
 
  215     std::string graphFilenameInp = fileprefixInp;
 
  216     graphFilenameInp = graphFilenameInp + 
".graph";
 
  219     fpGen.open(graphFilenameGen.c_str(), std::ios::in);
 
  223     fpInp.open(graphFilenameInp.c_str(), std::ios::in);
 
  227     if (nIDsGen != nIDsInp) {
 
  228       std::cout << 
"GenerateFiles:  nIDsGen " << nIDsGen
 
  229                 << 
" != nIDsInp " << nIDsInp << std::endl;
 
  234     if (!fail && nEdgesGen != 0) {
 
  235       std::cout << 
"GenerateFiles:  nEdgesGen " << nEdgesGen << 
" != 0"  
  241     if (!fail && nWgtsGen) {
 
  245         for (cntWgtLines = 0; cntWgtLines < nIDsGen &&
 
  246                               std::getline(fpGen, lineGen) &&
 
  247                               std::getline(fpInp, lineInp); cntWgtLines++) {
 
  249           std::istringstream issGen(lineGen);
 
  250           std::istringstream issInp(lineInp);
 
  253           double wgtGen, wgtInp;
 
  255           while (issGen >> wgtGen) {
 
  259               if (wgtGen != wgtInp) fail = 2224;  
 
  264           if (nw != nWgtsGen) fail = 2225;  
 
  266         if (cntWgtLines != nIDsGen) fail = 2226;  
 
  271         size_t cntWgtLines = 0;
 
  272         for (cntWgtLines = 0; cntWgtLines < nIDsGen && 
 
  273                               std::getline(fpGen, lineGen); cntWgtLines++) {
 
  274           std::istringstream issGen(lineGen);
 
  277           while (issGen) { issGen >> wgtGen; nw++; }
 
  278           if (nw != nWgtsGen) fail = 2227;  
 
  280         if (cntWgtLines != nIDsGen) fail = 2228;  
 
  289       std::string coordsFilenameGen = fileprefixGen;
 
  290       coordsFilenameGen = coordsFilenameGen + 
".coords";
 
  291       std::string coordsFilenameInp = fileprefixInp;
 
  292       coordsFilenameInp = coordsFilenameInp + 
".coords";
 
  294       fpGen.open(coordsFilenameGen.c_str(), std::ios::in);
 
  295       fpInp.open(coordsFilenameInp.c_str(), std::ios::in);
 
  298       for (cnt = 0; std::getline(fpGen,lineGen) &&
 
  299                     std::getline(fpInp,lineInp); cnt++) { 
 
  302         std::istringstream issGen(lineGen);
 
  303         std::istringstream issInp(lineInp);
 
  308         while (issGen && issInp) {
 
  311             std::cout << 
"Coordinates " << xGen << 
" != " << xInp 
 
  320         if (issGen || issInp) {
 
  321           std::cout << 
"Dimension of generated file != dimension of input file" 
  328       if (!fail && cnt != nIDsGen) {
 
  329         std::cout << 
"Number of coordinates read " << cnt 
 
  330                   << 
" != number of IDs " << nIDsGen << std::endl;
 
  345 int main(
int narg, 
char *arg[])
 
  347   Tpetra::ScopeGuard tscope(&narg, &arg);
 
  348   Teuchos::RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm();
 
  350   int rank = comm->getRank();
 
  351   int fail = 0, gfail=0;
 
  355   std::string inputFilePrefix(
"simple");
 
  356   Teuchos::CommandLineProcessor cmdp (
false, 
false);
 
  357   cmdp.setOption(
"file", &inputFilePrefix,
 
  358                  "chaco file (prefix) to be used in test");
 
  359   cmdp.parse(narg, arg);
 
  364   RCP<UserInputForTests> uinput;
 
  365   Teuchos::ParameterList params;
 
  366   params.set(
"input file", inputFilePrefix);
 
  367   params.set(
"file type", 
"Chaco");
 
  372   catch(std::exception &e){
 
  374     std::cout << e.what() << std::endl;
 
  378   RCP<tvector_t> inputMVector;     
 
  379   RCP<tvector_t> migratedMVector;   
 
  383   inputMVector = uinput->getUICoordinates();
 
  384   size_t vlen = inputMVector->getLocalLength();
 
  387   std::vector<const zscalar_t *> IDWeights;
 
  388   std::vector<int> IDWeightsStrides;
 
  391   if (uinput->hasUIWeights()) {
 
  393     auto uiweights = uinput->getUIWeights();
 
  395     nWeights = uiweights->getNumVectors();
 
  396     IDWeights.resize(nWeights);
 
  397     IDWeightsStrides.resize(nWeights);
 
  399     for (
int w = 0; w < nWeights; w++) {
 
  400       IDWeights[w] = uiweights->getData(w).getRawPtr();
 
  401       IDWeightsStrides[w] = 1;
 
  413   part_t *p = 
new part_t [vlen];
 
  414   memset(p, 0, 
sizeof(part_t) * vlen);
 
  415   ArrayRCP<part_t> solnParts(p, 0, vlen, 
true);
 
  417   soln_t solution(env, comm, nWeights);
 
  418   solution.setParts(solnParts);
 
  425       std::cout << 
"Constructed with Tpetra::MultiVector" << std::endl;
 
  427     RCP<const tvector_t> ctV = rcp_const_cast<
const tvector_t>(inputMVector);
 
  428     RCP<Zoltan2::XpetraMultiVectorAdapter<tvector_t> > tVInput;
 
  433           IDWeights, IDWeightsStrides));
 
  435     catch (std::exception &e){
 
  437       std::cout << e.what() << std::endl;
 
  441     fail = verifyInputAdapter<tvector_t>(*tVInput, *inputMVector, nVec,
 
  442                                          IDWeights, IDWeightsStrides);
 
  450         tVInput->applyPartitioningSolution(*inputMVector, vMigrate, solution);
 
  451         migratedMVector = rcp(vMigrate);
 
  453       catch (std::exception &e){
 
  460         RCP<const tvector_t> cnewV = 
 
  461             rcp_const_cast<
const tvector_t>(migratedMVector);
 
  462         RCP<Zoltan2::XpetraMultiVectorAdapter<tvector_t> > newInput;
 
  467         catch (std::exception &e){
 
  469           std::cout << e.what() << std::endl;
 
  474           std::cout << 
"Constructed with ";
 
  475           std::cout << 
"Tpetra::MultiVector migrated to proc 0" << std::endl;
 
  479         fail = verifyInputAdapter<tvector_t>(*newInput, *migratedMVector, nVec);
 
  480         if (fail) fail += 100;
 
  493       std::cout << 
"Constructed with Xpetra::MultiVector" << std::endl;
 
  497     RCP<const xvector_t> cxV = rcp_const_cast<
const xvector_t>(xV);
 
  498     RCP<Zoltan2::XpetraMultiVectorAdapter<xvector_t> > xVInput;
 
  506     catch (std::exception &e){
 
  508       std::cout << e.what() << std::endl;
 
  512     fail = verifyInputAdapter<xvector_t>(*xVInput, *inputMVector, nVec, 
 
  513                                          IDWeights, IDWeightsStrides);
 
  520         xVInput->applyPartitioningSolution(*xV, vMigrate, solution);
 
  522       catch (std::exception &e){
 
  529         RCP<const xvector_t> cnewV(vMigrate);
 
  530         RCP<Zoltan2::XpetraMultiVectorAdapter<xvector_t> > newInput;
 
  535         catch (std::exception &e){
 
  537           std::cout << e.what() << std::endl;
 
  542           std::cout << 
"Constructed with ";
 
  543           std::cout << 
"Xpetra::MultiVector migrated to proc 0" << std::endl;
 
  545         fail = verifyInputAdapter<xvector_t>(*newInput, *migratedMVector, nVec);
 
  546         if (fail) fail += 100;
 
  555 #ifdef HAVE_EPETRA_DATA_TYPES 
  558   typedef Epetra_MultiVector evector_t;
 
  561       std::cout << 
"Constructed with Epetra_MultiVector" << std::endl;
 
  564         rcp(
new Epetra_MultiVector(uinput->getUIEpetraCrsGraph()->RowMap(),
 
  566     for (
int v = 0; v < nVec; v++) {
 
  567       auto inV = inputMVector->getData(v);
 
  568       for (
int i = 0; i < eV->MyLength(); i++)
 
  569         eV->ReplaceMyValue(i, v, inV[i]);
 
  572     RCP<const evector_t> ceV = rcp_const_cast<
const evector_t>(eV);
 
  573     RCP<Zoltan2::XpetraMultiVectorAdapter<evector_t> > eVInput;
 
  575     bool goodAdapter = 
true;
 
  579               IDWeights, IDWeightsStrides));
 
  581     catch (std::exception &e){
 
  582       if (std::is_same<znode_t, Xpetra::EpetraNode>::value) {
 
  585         std::cout << e.what() << std::endl;
 
  590         std::cout << 
"Node type is not supported by Xpetra's Epetra interface;" 
  591                   << 
" Skipping this test." << std::endl;
 
  592         std::cout << 
"FYI:  Here's the exception message: " << std::endl
 
  593                   << e.what() << std::endl;
 
  600       fail = verifyInputAdapter<evector_t>(*eVInput, *inputMVector, nVec,
 
  601                                            IDWeights, IDWeightsStrides);
 
  606         evector_t *vMigrate =NULL;
 
  608           eVInput->applyPartitioningSolution(*eV, vMigrate, solution);
 
  610         catch (std::exception &e){
 
  617           RCP<const evector_t> cnewV(vMigrate, 
true);
 
  618           RCP<Zoltan2::XpetraMultiVectorAdapter<evector_t> > newInput;
 
  623           catch (std::exception &e){
 
  625             std::cout << e.what() << std::endl;
 
  630             std::cout << 
"Constructed with ";
 
  631             std::cout << 
"Epetra_MultiVector migrated to proc 0" << std::endl;
 
  633           fail = verifyInputAdapter<evector_t>(*newInput, *migratedMVector, 
 
  635           if (fail) fail += 100;
 
  650     std::cout << 
"PASS" << std::endl;
 
void printFailureCode(const Comm< int > &comm, int fail)
 
void generateFiles(const char *fileprefix, const Teuchos::Comm< int > &comm) const 
Write files that can be used as input to Zoltan or Zoltan2 driver Creates chaco-formatted input files...
 
int main(int narg, char *arg[])
 
#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. 
 
SparseMatrixAdapter_t::part_t part_t
 
A PartitioningSolution is a solution to a partitioning problem. 
 
VectorAdapter defines the interface for vector input. 
 
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
 
int globalFail(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