Zoltan2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
mapOneToOne.cpp
Go to the documentation of this file.
1 
6 #include "Teuchos_CommHelpers.hpp"
7 #include "Teuchos_DefaultComm.hpp"
8 #include "Teuchos_RCP.hpp"
9 #include "Teuchos_Array.hpp"
10 #include "Tpetra_Core.hpp"
11 #include "Tpetra_Map.hpp"
12 
13 #include <string>
14 #include <sstream>
15 #include <iostream>
16 
18 
19 int main(int narg, char **arg)
20 {
21  Tpetra::ScopeGuard tscope(&narg, &arg);
22  Teuchos::RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm();
23  int me = comm->getRank();
24 
25  typedef Tpetra::Map<> map_t;
26  typedef map_t::local_ordinal_type lno_t;
27  typedef map_t::global_ordinal_type gno_t;
28 
29  // Create a map with duplicated entries (mapWithCopies)
30  // Each rank has 15 IDs, the last five of which overlap with the next rank.
31 
32  lno_t numLocalCoords = 15;
33  lno_t offset = me * 10;
34 
35  Teuchos::Array<gno_t> gids(numLocalCoords);
36  for (lno_t i = 0 ; i < numLocalCoords; i++)
37  gids[i] = static_cast<gno_t> (offset + i);
38 
39  Tpetra::global_size_t numGlobalCoords =
40  Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid();
41  Teuchos::RCP<const map_t> mapWithCopies =
42  rcp(new map_t(numGlobalCoords, gids(), 0, comm));
43 
44  // Create a new map with IDs uniquely assigned to ranks (oneToOneMap)
45  Teuchos::RCP<const map_t> oneToOneMap =
46  Tpetra::createOneToOne<lno_t, gno_t>(mapWithCopies);
47 
48 
49  // Print the entries of each map
50  std::cout << me << " MAP WITH COPIES ("
51  << mapWithCopies->getGlobalNumElements() << "): ";
52  lno_t nlocal = lno_t(mapWithCopies->getLocalNumElements());
53  for (lno_t i = 0; i < nlocal; i++)
54  std::cout << mapWithCopies->getGlobalElement(i) << " ";
55  std::cout << std::endl;
56 
57  std::cout << me << " ONE TO ONE MAP ("
58  << oneToOneMap->getGlobalNumElements() << "): ";
59  nlocal = lno_t(oneToOneMap->getLocalNumElements());
60  for (lno_t i = 0; i < nlocal; i++)
61  std::cout << oneToOneMap->getGlobalElement(i) << " ";
62  std::cout << std::endl;
63 
64  return 0;
65 }
map_t::global_ordinal_type gno_t
Definition: mapRemotes.cpp:18
int main(int narg, char **arg)
Definition: coloring1.cpp:199
Tpetra::Map map_t
Definition: mapRemotes.cpp:16
map_t::local_ordinal_type lno_t
Definition: mapRemotes.cpp:17
Tpetra::global_size_t global_size_t