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