Zoltan2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
mapRemotes.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 
10 // Small test program showing how to locate off-process GIDs
11 // Trying to use Tpetra::Map like the Zoltan DDirectory
12 //
13 // Bug in Tpetra::Map? Filed as Bug 6412
14 // Behavior differs between default Tpetra Map distribution
15 // and user-defined distribution when there are duplicate search entries.
16 
17 #include "Teuchos_DefaultComm.hpp"
18 #include "Teuchos_RCP.hpp"
19 #include "Teuchos_ArrayRCP.hpp"
20 #include "Tpetra_Map.hpp"
21 #include <string>
22 #include <iostream>
23 
24 using Teuchos::arcp;
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 
31 int searchIt(const map_t &myMap, const std::string &myName)
32 {
33  int me = myMap.getComm()->getRank();
34  int nFail = 0;
35 
36  // Print the map elements
37  std::cout << me << " " << myName << " MINE: ";
38  for (size_t i = 0; i < myMap.getLocalNumElements(); i++)
39  std::cout << myMap.getGlobalElement(i) << " ";
40  std::cout << std::endl;
41 
42  // Memory for Gids for which to search
43  size_t nSearch = 6;
44  Teuchos::ArrayRCP<gno_t> searchGids = arcp(new gno_t[nSearch],
45  0, nSearch, true);
46  Teuchos::ArrayRCP<int> searchRemoteRanks = arcp(new int[nSearch],
47  0, nSearch, true);
48  Teuchos::ArrayRCP<lno_t> searchRemoteLids = arcp(new lno_t[nSearch],
49  0, nSearch, true);
50 
51  // Search without duplicates
52  for (size_t i = 0; i < nSearch; i++) searchGids[i] = i;
53  myMap.getRemoteIndexList(searchGids(),
54  searchRemoteRanks(), searchRemoteLids());
55 
56  for (size_t i = 0; i < nSearch; i++) {
57  std::cout << me << " " << myName
58  << " NoDuplicates: GID " << searchGids[i]
59  << " RANK " << searchRemoteRanks[i]
60  << " LID " << searchRemoteLids[i]
61  << (searchRemoteRanks[i] == -1 ? " BAD!" : " ")
62  << std::endl;
63  if (searchRemoteRanks[i] == -1) nFail++;
64  }
65 
66  // Search with duplicates
67  for (size_t i = 0; i < nSearch; i++) searchGids[i] = i/2;
68  myMap.getRemoteIndexList(searchGids(),
69  searchRemoteRanks(), searchRemoteLids());
70 
71  for (size_t i = 0; i < nSearch; i++) {
72  std::cout << me << " " << myName
73  << " WithDuplicates: GID " << searchGids[i]
74  << " RANK " << searchRemoteRanks[i]
75  << " LID " << searchRemoteLids[i]
76  << (searchRemoteRanks[i] == -1 ? " BAD!" : " ")
77  << std::endl;
78  if (searchRemoteRanks[i] == -1) nFail++;
79  }
80 
81  return nFail;
82 }
83 
84 
86 
87 int main(int narg, char **arg)
88 {
89  Tpetra::ScopeGuard tscope(&narg, &arg);
90  Teuchos::RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm();
91 
92  int me = comm->getRank();
93  int np = comm->getSize();
94  int nFail = 0;
95 
96  gno_t nGlobal = 24; // Global number of Gids
97 
98  // Create and search Default Tpetra Map
99  const map_t defaultMap(nGlobal, 0, comm);
100 
101  nFail += searchIt(defaultMap, "defaultMap");
102 
103  // Create and seach customized map
104  // Identify locally owned GIDs: same as default map (if nGlobal%np == 0)
105  lno_t nLocal = nGlobal / np + (me < (nGlobal%np));
106  gno_t myFirst = me * (nGlobal / np) + (me < (nGlobal%np) ? me : (nGlobal%np));
107  Teuchos::ArrayRCP<gno_t> myGids = arcp(new gno_t[nLocal], 0, nLocal, true);
108  for (lno_t i = 0; i < nLocal; i++)
109  myGids[i] = myFirst + i;
110 
111  // Construct customMap
112  gno_t dummy = Teuchos::OrdinalTraits<gno_t>::invalid();
113  const map_t customMap(dummy, myGids(), 0, comm);
114 
115  nFail += searchIt(customMap, "customMap");
116 
117  if (nFail) std::cout << "FAIL" << std::endl;
118  else std::cout << "PASS" << std::endl;
119 
120  return 0;
121 }
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
int searchIt(const map_t &myMap, const std::string &myName)
Definition: mapRemotes.cpp:31