17 #include "Teuchos_CommHelpers.hpp"
18 #include "Teuchos_DefaultComm.hpp"
19 #include "Teuchos_RCP.hpp"
20 #include "Teuchos_Array.hpp"
21 #include "Tpetra_Core.hpp"
22 #include "Tpetra_Map.hpp"
23 #include "Tpetra_Vector.hpp"
31 int main(
int narg,
char **arg)
33 typedef Tpetra::Map<>
map_t;
34 typedef map_t::local_ordinal_type
lno_t;
35 typedef map_t::global_ordinal_type
gno_t;
38 Tpetra::ScopeGuard tscope(&narg, &arg);
39 Teuchos::RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm();
40 int me = comm->getRank();
46 lno_t numLocalCoords = 15;
47 lno_t offset = me * 10;
49 Teuchos::Array<gno_t> gids(numLocalCoords);
50 for (lno_t i = 0 ; i < numLocalCoords; i++)
51 gids[i] = static_cast<gno_t> (offset + i);
54 Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid();
55 Teuchos::RCP<const map_t> mapWithCopies =
56 rcp(
new map_t(numGlobalCoords, gids(), 0, comm));
59 Teuchos::RCP<const map_t> oneToOneMap =
60 Tpetra::createOneToOne<lno_t, gno_t>(mapWithCopies);
63 typedef Tpetra::Vector<scalar_t, lno_t, gno_t> vector_t;
65 vector_t vecWithCopies(mapWithCopies);
66 vector_t oneToOneVec(oneToOneMap);
69 for (lno_t i = 0; i <
lno_t(oneToOneMap->getLocalNumElements()); i++)
70 oneToOneVec.replaceLocalValue(i, me);
73 Teuchos::RCP<const Tpetra::Import<lno_t, gno_t> > importer =
74 Tpetra::createImport<lno_t, gno_t>(oneToOneMap, mapWithCopies);
75 vecWithCopies.doImport(oneToOneVec, *importer, Tpetra::REPLACE);
78 std::cout << me <<
" ONE TO ONE VEC ("
79 << oneToOneMap->getGlobalNumElements() <<
"): ";
80 lno_t nlocal =
lno_t(oneToOneMap->getLocalNumElements());
81 for (lno_t i = 0; i < nlocal; i++)
82 std::cout <<
"[" << oneToOneMap->getGlobalElement(i) <<
" "
83 << oneToOneVec.getData()[i] <<
"] ";
84 std::cout << std::endl;
87 std::cout << me <<
" VEC WITH COPIES ("
88 << mapWithCopies->getGlobalNumElements() <<
"): ";
89 nlocal =
lno_t(mapWithCopies->getLocalNumElements());
90 for (lno_t i = 0; i < nlocal; i++)
91 std::cout <<
"[" << mapWithCopies->getGlobalElement(i) <<
" "
92 << vecWithCopies.getData()[i] <<
"] ";
93 std::cout << std::endl;
map_t::global_ordinal_type gno_t
int main(int narg, char **arg)
map_t::local_ordinal_type lno_t
Tpetra::global_size_t global_size_t