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