Zoltan2
XpetraTraits.cpp
Go to the documentation of this file.
1 // @HEADER
2 //
3 // ***********************************************************************
4 //
5 // Zoltan2: A package of combinatorial algorithms for scientific computing
6 // Copyright 2012 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Karen Devine (kddevin@sandia.gov)
39 // Erik Boman (egboman@sandia.gov)
40 // Siva Rajamanickam (srajama@sandia.gov)
41 //
42 // ***********************************************************************
43 //
44 // @HEADER
45 //
46 // Basic test of the XpetraTraits definitions.
47 //
48 // TODO - a real test would figure out if the migrated objects are
49 // the same as the original, here we just look at them on stdout.
50 // TODO look at number of diagonals and max number of entries in
51 // Tpetra and Xpetra migrated graphs. They're garbage.
52 
53 #include <Zoltan2_XpetraTraits.hpp>
54 #include <Zoltan2_TestHelpers.hpp>
55 
56 #include <string>
57 #include <Teuchos_DefaultComm.hpp>
58 #include <Teuchos_RCP.hpp>
59 #include <Teuchos_Array.hpp>
60 #include <Teuchos_ArrayRCP.hpp>
61 #include <Teuchos_Comm.hpp>
62 #include <Teuchos_VerboseObject.hpp>
63 #include <Tpetra_CrsMatrix.hpp>
64 #include <Tpetra_Vector.hpp>
65 
66 #ifdef HAVE_ZOLTAN_EPETRA
67 #include <Xpetra_EpetraUtils.hpp>
68 #endif
69 
70 using std::string;
71 using Teuchos::RCP;
72 using Teuchos::ArrayRCP;
73 using Teuchos::ArrayView;
74 using Teuchos::Array;
75 using Teuchos::rcp;
76 using Teuchos::Comm;
77 
78 ArrayRCP<zgno_t> roundRobinMapShared(
79  int proc,
80  int nprocs,
81  zgno_t basegid,
82  zgno_t maxgid,
83  size_t nglobalrows
84 )
85 {
86  if (nglobalrows != size_t(maxgid - basegid + 1)){
87  std::cout << "Error: Map is invalid for test - fix test" << std::endl;
88  std::cerr << "Error: Map is invalid for test - fix test" << std::endl;
89  std::cout << "FAIL" << std::endl;
90  exit(1);
91  }
92  RCP<Array<zgno_t> > mygids = rcp(new Array<zgno_t>);
93  zgno_t firstzgno_t = proc;
94  if (firstzgno_t < basegid){
95  zgno_t n = basegid % proc;
96  if (n>0)
97  firstzgno_t = basegid - n + proc;
98  else
99  firstzgno_t = basegid;
100  }
101  for (zgno_t gid=firstzgno_t; gid <= maxgid; gid+=nprocs){
102  (*mygids).append(gid);
103  }
104 
105  ArrayRCP<zgno_t> newIdArcp = Teuchos::arcp(mygids);
106 
107  return newIdArcp;
108 }
109 
110 #ifdef HAVE_EPETRA_DATA_TYPES
111 ArrayRCP<zgno_t> roundRobinMap(const Epetra_BlockMap &emap)
112 {
113  const Epetra_Comm &comm = emap.Comm();
114  int proc = comm.MyPID();
115  int nprocs = comm.NumProc();
116  zgno_t basegid = emap.MinAllGID();
117  zgno_t maxgid = emap.MaxAllGID();
118  size_t nglobalrows = emap.NumGlobalElements();
119 
120  return roundRobinMapShared(proc, nprocs, basegid, maxgid, nglobalrows);
121 }
122 #endif
123 
124 ArrayRCP<zgno_t> roundRobinMap(const Tpetra::Map<zlno_t, zgno_t, znode_t> &tmap)
125 {
126  const RCP<const Comm<int> > &comm = tmap.getComm();
127  int proc = comm->getRank();
128  int nprocs = comm->getSize();
129  zgno_t basegid = tmap.getMinAllGlobalIndex();
130  zgno_t maxgid = tmap.getMaxAllGlobalIndex();
131  size_t nglobalrows = tmap.getGlobalNumElements();
132 
133  return roundRobinMapShared(proc, nprocs, basegid, maxgid, nglobalrows);
134 }
135 
136 ArrayRCP<zgno_t> roundRobinMap(const Xpetra::Map<zlno_t, zgno_t, znode_t> &xmap)
137 {
138  const RCP<const Comm<int> > &comm = xmap.getComm();
139  int proc = comm->getRank();
140  int nprocs = comm->getSize();
141  zgno_t basegid = xmap.getMinAllGlobalIndex();
142  zgno_t maxgid = xmap.getMaxAllGlobalIndex();
143  size_t nglobalrows = xmap.getGlobalNumElements();
144 
145  return roundRobinMapShared(proc, nprocs, basegid, maxgid, nglobalrows);
146 }
147 
148 int main(int narg, char *arg[])
149 {
150  Tpetra::ScopeGuard tscope(&narg, &arg);
151  Teuchos::RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm();
152 
153  int rank = comm->getRank();
154  bool aok = true;
155 
156  Teuchos::RCP<Teuchos::FancyOStream> outStream =
157  Teuchos::VerboseObjectBase::getDefaultOStream();
158  Teuchos::EVerbosityLevel v=Teuchos::VERB_EXTREME;
159 
160  typedef Tpetra::CrsMatrix<zscalar_t,zlno_t,zgno_t,znode_t> tmatrix_t;
161  typedef Tpetra::CrsGraph<zlno_t,zgno_t,znode_t> tgraph_t;
162  typedef Tpetra::Vector<zscalar_t,zlno_t,zgno_t,znode_t> tvector_t;
163  typedef Tpetra::MultiVector<zscalar_t,zlno_t,zgno_t,znode_t> tmvector_t;
164  typedef Xpetra::CrsMatrix<zscalar_t,zlno_t,zgno_t,znode_t> xmatrix_t;
165  typedef Xpetra::CrsGraph<zlno_t,zgno_t,znode_t> xgraph_t;
166  typedef Xpetra::Vector<zscalar_t,zlno_t,zgno_t,znode_t> xvector_t;
167  typedef Xpetra::MultiVector<zscalar_t,zlno_t,zgno_t,znode_t> xmvector_t;
168 
169  // Create object that can give us test Tpetra and Xpetra input.
170 
171  RCP<UserInputForTests> uinput;
172 
173  try{
174  uinput =
175  rcp(new UserInputForTests(testDataFilePath,std::string("simple"), comm, true));
176  }
177  catch(std::exception &e){
178  aok = false;
179  std::cout << e.what() << std::endl;
180  }
181  TEST_FAIL_AND_EXIT(*comm, aok, "input ", 1);
182 
184  // Tpetra::CrsMatrix
185  // Tpetra::CrsGraph
186  // Tpetra::Vector
187  // Tpetra::MultiVector
189 
190 
191  // XpetraTraits<Tpetra::CrsMatrix<zscalar_t, zlno_t, zgno_t, znode_t> >
192  {
193  RCP<tmatrix_t> M;
194 
195  try{
196  M = uinput->getUITpetraCrsMatrix();
197  }
198  catch(std::exception &e){
199  aok = false;
200  std::cout << e.what() << std::endl;
201  }
202  TEST_FAIL_AND_EXIT(*comm, aok, "getTpetraCrsMatrix ", 1);
203 
204  if (rank== 0)
205  std::cout << "Original Tpetra matrix " << M->getGlobalNumRows()
206  << " x " << M->getGlobalNumCols() << std::endl;
207 
208  M->describe(*outStream,v);
209 
210  ArrayRCP<zgno_t> newRowIds = roundRobinMap(*(M->getRowMap()));
211 
212  zgno_t localNumRows = newRowIds.size();
213 
214  RCP<const tmatrix_t> newM;
215  try{
217  localNumRows, newRowIds.getRawPtr());
218  }
219  catch(std::exception &e){
220  aok = false;
221  std::cout << e.what() << std::endl;
222  }
223  TEST_FAIL_AND_EXIT(*comm, aok,
224  " Zoltan2::XpetraTraits<tmatrix_t>::doMigration ", 1);
225 
226  if (rank== 0)
227  std::cout << "Migrated Tpetra matrix" << std::endl;
228 
229  newM->describe(*outStream,v);
230  }
231 
232  // XpetraTraits<Tpetra::CrsGraph<zscalar_t, zlno_t, zgno_t, znode_t> >
233  {
234  RCP<tgraph_t> G;
235 
236  try{
237  G = uinput->getUITpetraCrsGraph();
238  }
239  catch(std::exception &e){
240  aok = false;
241  std::cout << e.what() << std::endl;
242  }
243  TEST_FAIL_AND_EXIT(*comm, aok, "getTpetraCrsGraph ", 1);
244 
245  if (rank== 0)
246  std::cout << "Original Tpetra graph" << std::endl;
247 
248  G->describe(*outStream,v);
249 
250  ArrayRCP<zgno_t> newRowIds = roundRobinMap(*(G->getRowMap()));
251 
252  zgno_t localNumRows = newRowIds.size();
253 
254  RCP<const tgraph_t> newG;
255  try{
257  localNumRows, newRowIds.getRawPtr());
258  }
259  catch(std::exception &e){
260  aok = false;
261  std::cout << e.what() << std::endl;
262  }
263  TEST_FAIL_AND_EXIT(*comm, aok,
264  " Zoltan2::XpetraTraits<tgraph_t>::doMigration ", 1);
265 
266  if (rank== 0)
267  std::cout << "Migrated Tpetra graph" << std::endl;
268 
269  newG->describe(*outStream,v);
270  }
271 
272  // XpetraTraits<Tpetra::Vector<zscalar_t, zlno_t, zgno_t, znode_t>>
273  {
274  RCP<tvector_t> V;
275 
276  try{
277  V = rcp(new tvector_t(uinput->getUITpetraCrsGraph()->getRowMap(), 1));
278  V->randomize();
279  }
280  catch(std::exception &e){
281  aok = false;
282  std::cout << e.what() << std::endl;
283  }
284  TEST_FAIL_AND_EXIT(*comm, aok, "getTpetraVector", 1);
285 
286  if (rank== 0)
287  std::cout << "Original Tpetra vector" << std::endl;
288 
289  V->describe(*outStream,v);
290 
291  ArrayRCP<zgno_t> newRowIds = roundRobinMap(*(V->getMap()));
292 
293  zgno_t localNumRows = newRowIds.size();
294 
295  RCP<const tvector_t> newV;
296  try{
298  localNumRows, newRowIds.getRawPtr());
299  }
300  catch(std::exception &e){
301  aok = false;
302  std::cout << e.what() << std::endl;
303  }
304  TEST_FAIL_AND_EXIT(*comm, aok,
305  " Zoltan2::XpetraTraits<tvector_t>::doMigration ", 1);
306 
307  if (rank== 0)
308  std::cout << "Migrated Tpetra vector" << std::endl;
309 
310  newV->describe(*outStream,v);
311  }
312 
313  // XpetraTraits<Tpetra::MultiVector<zscalar_t, zlno_t, zgno_t, znode_t>>
314  {
315  RCP<tmvector_t> MV;
316 
317  try{
318  MV = rcp(new tmvector_t(uinput->getUITpetraCrsGraph()->getRowMap(), 3));
319  MV->randomize();
320  }
321  catch(std::exception &e){
322  aok = false;
323  std::cout << e.what() << std::endl;
324  }
325  TEST_FAIL_AND_EXIT(*comm, aok, "getTpetraMultiVector", 1);
326 
327  if (rank== 0)
328  std::cout << "Original Tpetra multivector" << std::endl;
329 
330  MV->describe(*outStream,v);
331 
332  ArrayRCP<zgno_t> newRowIds = roundRobinMap(*(MV->getMap()));
333 
334  zgno_t localNumRows = newRowIds.size();
335 
336  RCP<const tmvector_t> newMV;
337  try{
339  localNumRows, newRowIds.getRawPtr());
340  }
341  catch(std::exception &e){
342  aok = false;
343  std::cout << e.what() << std::endl;
344  }
345  TEST_FAIL_AND_EXIT(*comm, aok,
346  " Zoltan2::XpetraTraits<tmvector_t>::doMigration ", 1);
347 
348  if (rank== 0)
349  std::cout << "Migrated Tpetra multivector" << std::endl;
350 
351  newMV->describe(*outStream,v);
352  }
353 
355  // Xpetra::CrsMatrix
356  // Xpetra::CrsGraph
357  // Xpetra::Vector
358  // Xpetra::MultiVector
360 
361  // XpetraTraits<Xpetra::CrsMatrix<zscalar_t, zlno_t, zgno_t, znode_t> >
362  {
363  RCP<xmatrix_t> M;
364 
365  try{
366  M = uinput->getUIXpetraCrsMatrix();
367  }
368  catch(std::exception &e){
369  aok = false;
370  std::cout << e.what() << std::endl;
371  }
372  TEST_FAIL_AND_EXIT(*comm, aok, "getXpetraCrsMatrix ", 1);
373 
374  if (rank== 0)
375  std::cout << "Original Xpetra matrix" << std::endl;
376 
377  M->describe(*outStream,v);
378 
379  ArrayRCP<zgno_t> newRowIds = roundRobinMap(*(M->getRowMap()));
380 
381  zgno_t localNumRows = newRowIds.size();
382 
383  RCP<const xmatrix_t> newM;
384  try{
386  localNumRows, newRowIds.getRawPtr());
387  }
388  catch(std::exception &e){
389  aok = false;
390  std::cout << e.what() << std::endl;
391  }
392  TEST_FAIL_AND_EXIT(*comm, aok,
393  " Zoltan2::XpetraTraits<xmatrix_t>::doMigration ", 1);
394 
395  if (rank== 0)
396  std::cout << "Migrated Xpetra matrix" << std::endl;
397 
398  newM->describe(*outStream,v);
399  }
400 
401  // XpetraTraits<Xpetra::CrsGraph<zscalar_t, zlno_t, zgno_t, znode_t> >
402  {
403  RCP<xgraph_t> G;
404 
405  try{
406  G = uinput->getUIXpetraCrsGraph();
407  }
408  catch(std::exception &e){
409  aok = false;
410  std::cout << e.what() << std::endl;
411  }
412  TEST_FAIL_AND_EXIT(*comm, aok, "getXpetraCrsGraph ", 1);
413 
414  if (rank== 0)
415  std::cout << "Original Xpetra graph" << std::endl;
416 
417  G->describe(*outStream,v);
418 
419  ArrayRCP<zgno_t> newRowIds = roundRobinMap(*(G->getRowMap()));
420 
421  zgno_t localNumRows = newRowIds.size();
422 
423  RCP<const xgraph_t> newG;
424  try{
426  localNumRows, newRowIds.getRawPtr());
427  }
428  catch(std::exception &e){
429  aok = false;
430  std::cout << e.what() << std::endl;
431  }
432  TEST_FAIL_AND_EXIT(*comm, aok,
433  " Zoltan2::XpetraTraits<xgraph_t>::doMigration ", 1);
434 
435  if (rank== 0)
436  std::cout << "Migrated Xpetra graph" << std::endl;
437 
438  newG->describe(*outStream,v);
439  }
440 
441  // XpetraTraits<Xpetra::Vector<zscalar_t, zlno_t, zgno_t, znode_t>>
442  {
443  RCP<xvector_t> V;
444 
445  try{
446  RCP<tvector_t> tV =
447  rcp(new tvector_t(uinput->getUITpetraCrsGraph()->getRowMap(), 1));
448  tV->randomize();
450  }
451  catch(std::exception &e){
452  aok = false;
453  std::cout << e.what() << std::endl;
454  }
455  TEST_FAIL_AND_EXIT(*comm, aok, "getXpetraVector", 1);
456 
457  if (rank== 0)
458  std::cout << "Original Xpetra vector" << std::endl;
459 
460  V->describe(*outStream,v);
461 
462  ArrayRCP<zgno_t> newRowIds = roundRobinMap(*(V->getMap()));
463 
464  zgno_t localNumRows = newRowIds.size();
465 
466  RCP<const xvector_t> newV;
467  try{
469  localNumRows, newRowIds.getRawPtr());
470  }
471  catch(std::exception &e){
472  aok = false;
473  std::cout << e.what() << std::endl;
474  }
475  TEST_FAIL_AND_EXIT(*comm, aok,
476  " Zoltan2::XpetraTraits<xvector_t>::doMigration ", 1);
477 
478  if (rank== 0)
479  std::cout << "Migrated Xpetra vector" << std::endl;
480 
481  newV->describe(*outStream,v);
482  }
483 
484  // XpetraTraits<Xpetra::MultiVector<zscalar_t, zlno_t, zgno_t, znode_t>>
485  {
486  RCP<xmvector_t> MV;
487 
488  try{
489  RCP<tmvector_t> tMV =
490  rcp(new tmvector_t(uinput->getUITpetraCrsGraph()->getRowMap(), 3));
491  tMV->randomize();
493  }
494  catch(std::exception &e){
495  aok = false;
496  std::cout << e.what() << std::endl;
497  }
498  TEST_FAIL_AND_EXIT(*comm, aok, "getXpetraMultiVector", 1);
499 
500  if (rank== 0)
501  std::cout << "Original Xpetra multivector" << std::endl;
502 
503  MV->describe(*outStream,v);
504 
505  ArrayRCP<zgno_t> newRowIds = roundRobinMap(*(MV->getMap()));
506 
507  zgno_t localNumRows = newRowIds.size();
508 
509  RCP<const xmvector_t> newMV;
510  try{
512  localNumRows, newRowIds.getRawPtr());
513  }
514  catch(std::exception &e){
515  aok = false;
516  std::cout << e.what() << std::endl;
517  }
518  TEST_FAIL_AND_EXIT(*comm, aok,
519  " Zoltan2::XpetraTraits<xmvector_t>::doMigration ", 1);
520 
521  if (rank== 0)
522  std::cout << "Migrated Xpetra multivector" << std::endl;
523 
524  newMV->describe(*outStream,v);
525  }
526 
527 #ifdef HAVE_EPETRA_DATA_TYPES
528  // Epetra_CrsMatrix
530  // Epetra_CrsGraph
531  // Epetra_Vector
532  // Epetra_MultiVector
534 
535  typedef Epetra_CrsMatrix ematrix_t;
536  typedef Epetra_CrsGraph egraph_t;
537  typedef Epetra_Vector evector_t;
538  typedef Epetra_MultiVector emvector_t;
539  typedef Epetra_BlockMap emap_t;
540 
541  // Create object that can give us test Epetra input.
542 
543  RCP<UserInputForTests> euinput;
544 
545  try{
546  euinput =
547  rcp(new UserInputForTests(testDataFilePath,std::string("simple"), comm, true));
548  }
549  catch(std::exception &e){
550  aok = false;
551  std::cout << e.what() << std::endl;
552  }
553  TEST_FAIL_AND_EXIT(*comm, aok, "epetra input ", 1);
554 
555  // XpetraTraits<Epetra_CrsMatrix>
556  {
557  RCP<ematrix_t> M;
558 
559  try{
560  M = euinput->getUIEpetraCrsMatrix();
561  }
562  catch(std::exception &e){
563  aok = false;
564  std::cout << e.what() << std::endl;
565  }
566  TEST_FAIL_AND_EXIT(*comm, aok, "getEpetraCrsMatrix ", 1);
567 
568  if (rank== 0)
569  std::cout << "Original Epetra matrix" << std::endl;
570 
571  M->Print(std::cout);
572 
573  RCP<const emap_t> emap = Teuchos::rcpFromRef(M->RowMap());
574  ArrayRCP<zgno_t> newRowIds = roundRobinMap(*emap);
575 
576  zgno_t localNumRows = newRowIds.size();
577 
578  RCP<const ematrix_t> newM;
579  try{
581  localNumRows, newRowIds.getRawPtr());
582  }
583  catch(std::exception &e){
584  aok = false;
585  std::cout << e.what() << std::endl;
586  }
587  TEST_FAIL_AND_EXIT(*comm, aok,
588  " Zoltan2::XpetraTraits<ematrix_t>::doMigration ", 1);
589 
590  if (rank== 0)
591  std::cout << "Migrated Epetra matrix" << std::endl;
592 
593  newM->Print(std::cout);
594  }
595 
596  // XpetraTraits<Epetra_CrsGraph>
597  {
598  RCP<egraph_t> G;
599 
600  try{
601  G = euinput->getUIEpetraCrsGraph();
602  }
603  catch(std::exception &e){
604  aok = false;
605  std::cout << e.what() << std::endl;
606  }
607  TEST_FAIL_AND_EXIT(*comm, aok, "getEpetraCrsGraph ", 1);
608 
609  if (rank== 0)
610  std::cout << "Original Epetra graph" << std::endl;
611 
612  G->Print(std::cout);
613 
614  RCP<const emap_t> emap = Teuchos::rcpFromRef(G->RowMap());
615  ArrayRCP<zgno_t> newRowIds = roundRobinMap(*emap);
616 
617  zgno_t localNumRows = newRowIds.size();
618 
619  RCP<const egraph_t> newG;
620  try{
622  localNumRows, newRowIds.getRawPtr());
623  }
624  catch(std::exception &e){
625  aok = false;
626  std::cout << e.what() << std::endl;
627  }
628  TEST_FAIL_AND_EXIT(*comm, aok,
629  " Zoltan2::XpetraTraits<egraph_t>::doMigration ", 1);
630 
631  if (rank== 0)
632  std::cout << "Migrated Epetra graph" << std::endl;
633 
634  newG->Print(std::cout);
635  }
636 
637  // XpetraTraits<Epetra_Vector>
638  {
639  RCP<evector_t> V;
640 
641  try{
642  V = rcp(new Epetra_Vector(euinput->getUIEpetraCrsGraph()->RowMap()));
643  V->Random();
644  }
645  catch(std::exception &e){
646  aok = false;
647  std::cout << e.what() << std::endl;
648  }
649  TEST_FAIL_AND_EXIT(*comm, aok, "getEpetraVector", 1);
650 
651  if (rank== 0)
652  std::cout << "Original Epetra vector" << std::endl;
653 
654  V->Print(std::cout);
655 
656  RCP<const emap_t> emap = Teuchos::rcpFromRef(V->Map());
657  ArrayRCP<zgno_t> newRowIds = roundRobinMap(*emap);
658 
659  zgno_t localNumRows = newRowIds.size();
660 
661  RCP<const evector_t> newV;
662  try{
664  localNumRows, newRowIds.getRawPtr());
665  }
666  catch(std::exception &e){
667  aok = false;
668  std::cout << e.what() << std::endl;
669  }
670  TEST_FAIL_AND_EXIT(*comm, aok,
671  " Zoltan2::XpetraTraits<evector_t>::doMigration ", 1);
672 
673  if (rank== 0)
674  std::cout << "Migrated Epetra vector" << std::endl;
675 
676  newV->Print(std::cout);
677  }
678 
679  // XpetraTraits<Epetra_MultiVector>
680  {
681  RCP<emvector_t> MV;
682 
683  try{
684  MV =
685  rcp(new Epetra_MultiVector(euinput->getUIEpetraCrsGraph()->RowMap(),3));
686  MV->Random();
687  }
688  catch(std::exception &e){
689  aok = false;
690  std::cout << e.what() << std::endl;
691  }
692  TEST_FAIL_AND_EXIT(*comm, aok, "getEpetraMultiVector", 1);
693 
694  if (rank== 0)
695  std::cout << "Original Epetra multivector" << std::endl;
696 
697  MV->Print(std::cout);
698 
699  RCP<const emap_t> emap = Teuchos::rcpFromRef(MV->Map());
700  ArrayRCP<zgno_t> newRowIds = roundRobinMap(*emap);
701 
702  zgno_t localNumRows = newRowIds.size();
703 
704  RCP<const emvector_t> newMV;
705  try{
707  localNumRows, newRowIds.getRawPtr());
708  }
709  catch(std::exception &e){
710  aok = false;
711  std::cout << e.what() << std::endl;
712  }
713  TEST_FAIL_AND_EXIT(*comm, aok,
714  " Zoltan2::XpetraTraits<emvector_t>::doMigration ", 1);
715 
716  if (rank== 0)
717  std::cout << "Migrated Epetra multivector" << std::endl;
718 
719  newMV->Print(std::cout);
720  }
721 #endif // have epetra data types (int, int, double)
722 
724  // DONE
726 
727  if (rank==0)
728  std::cout << "PASS" << std::endl;
729 }
730 
main
int main(int narg, char *arg[])
Definition: XpetraTraits.cpp:148
xvector_t
Xpetra::MultiVector< zscalar_t, zlno_t, zgno_t, znode_t > xvector_t
Definition: XpetraMultiVectorInput.cpp:72
Zoltan2::XpetraTraits::convertToXpetra
static RCP< User > convertToXpetra(const RCP< User > &a)
Convert the object to its Xpetra wrapped version.
Definition: Zoltan2_XpetraTraits.hpp:98
testDataFilePath
std::string testDataFilePath(".")
xmatrix_t
Xpetra::CrsMatrix< zscalar_t, zlno_t, zgno_t, znode_t > xmatrix_t
Definition: XpetraCrsMatrixInput.cpp:70
UserInputForTests
Definition: UserInputForTests.hpp:126
Zoltan2::XpetraTraits::doMigration
static RCP< User > doMigration(const User &from, size_t numLocalRows, const gno_t *myNewRows)
Migrate the object Given a user object and a new row distribution, create and return a new user objec...
Definition: Zoltan2_XpetraTraits.hpp:116
Zoltan2_XpetraTraits.hpp
Traits of Xpetra classes, including migration method.
TEST_FAIL_AND_EXIT
#define TEST_FAIL_AND_EXIT(comm, ok, s, code)
Definition: ErrorHandlingForTests.hpp:70
zgno_t
int zgno_t
Definition: Zoltan2_TestHelpers.hpp:143
tvector_t
Tpetra::MultiVector< zscalar_t, zlno_t, zgno_t, znode_t > tvector_t
Definition: XpetraMultiVectorInput.cpp:71
roundRobinMap
ArrayRCP< zgno_t > roundRobinMap(const Tpetra::Map< zlno_t, zgno_t, znode_t > &tmap)
Definition: XpetraTraits.cpp:124
tgraph_t
Tpetra::CrsGraph< zlno_t, zgno_t, znode_t > tgraph_t
Definition: XpetraCrsGraphInput.cpp:70
roundRobinMapShared
ArrayRCP< zgno_t > roundRobinMapShared(int proc, int nprocs, zgno_t basegid, zgno_t maxgid, size_t nglobalrows)
Definition: XpetraTraits.cpp:78
Zoltan2_TestHelpers.hpp
common code used by tests
tmatrix_t
Tpetra::CrsMatrix< zscalar_t, zlno_t, zgno_t, znode_t > tmatrix_t
Definition: XpetraCrsMatrixInput.cpp:69
xgraph_t
Xpetra::CrsGraph< zlno_t, zgno_t, znode_t > xgraph_t
Definition: XpetraCrsGraphInput.cpp:71