15 #ifndef _ZOLTAN2_FINDUNIQUEGIDS_HPP_
16 #define _ZOLTAN2_FINDUNIQUEGIDS_HPP_
21 #include <Tpetra_MultiVector.hpp>
22 #include <Tpetra_Vector.hpp>
26 #include <zoltan_dd.h>
27 #include <zoltan_dd_const.h>
32 template <
typename gno_t>
43 int num_user =
sizeof(
gno_t);
45 Zoltan_DD_Struct *dd = NULL;
46 Zoltan_DD_Create(&dd, mpicomm, num_gid, num_lid, num_user, num_keys,
49 ZOLTAN_ID_PTR ddnotneeded = NULL;
50 Zoltan_DD_Update(dd, ddkeys, ddnotneeded, ddnewgids, NULL,
int(num_keys));
56 typedef long long mpi_t;
57 mpi_t nDDEntries = (mpi_t)(dd->nodecnt);
59 MPI_Scan(&nDDEntries, &firstIdx, 1, MPI_LONG_LONG, MPI_SUM, mpicomm);
60 firstIdx -= nDDEntries;
65 for (DD_NodeIdx i = 0; i < dd->nodelistlen; i++) {
66 DD_Node *ptr = &(dd->nodelist[i]);
68 char *userchar = (
char*)(ptr->gid + (dd->gid_length + dd->lid_length));
70 *newgid =
gno_t(firstIdx + cnt);
77 Zoltan_DD_Find(dd, ddkeys, ddnotneeded, ddnewgids, NULL,
int(num_keys), NULL);
79 Zoltan_DD_Destroy(&dd);
82 MPI_Allreduce(&nDDEntries, &nUnique, 1, MPI_LONG_LONG, MPI_SUM, mpicomm);
84 return size_t(nUnique);
88 template <
typename lno_t,
typename gno_t>
90 Tpetra::MultiVector<gno_t, lno_t, gno_t> &keys,
91 Tpetra::Vector<gno_t, lno_t, gno_t> &gids
101 size_t num_keys = keys.getLocalLength();
102 size_t num_entries = keys.getNumVectors();
104 #ifdef HAVE_ZOLTAN2_MPI
105 MPI_Comm mpicomm = Teuchos::getRawMpiComm(*(keys.getMap()->getComm()));
110 MPI_Initialized(&flag);
114 MPI_Init(&narg, &argv);
117 MPI_Comm mpicomm = MPI_COMM_WORLD;
121 int num_user =
sizeof(
gno_t);
124 Teuchos::ArrayRCP<const gno_t> *tmpKeyVecs =
125 new Teuchos::ArrayRCP<const gno_t>[num_entries];
126 for (
size_t v = 0; v < num_entries; v++) tmpKeyVecs[v] = keys.getData(v);
128 ZOLTAN_ID_PTR ddkeys =
new ZOLTAN_ID_TYPE[num_gid * num_keys];
130 for (
size_t i = 0; i < num_keys; i++) {
131 for (
size_t v = 0; v < num_entries; v++) {
132 ZOLTAN_ID_PTR ddkey = &(ddkeys[idx]);
137 delete [] tmpKeyVecs;
140 char *ddnewgids =
new char[num_user * num_keys];
143 size_t nUnique = findUniqueGidsCommon<gno_t>(num_keys, num_gid,
144 ddkeys, ddnewgids, mpicomm);
148 for (
size_t i = 0; i < num_keys; i++)
149 gids.replaceLocalValue(i, result[i]);
159 template <
typename key_t,
typename gno_t>
161 std::vector<key_t> &keys,
162 std::vector<gno_t> &gids,
163 const Teuchos::Comm<int> &comm
181 size_t num_keys = keys.size();
183 size_t num_entries = dummy.size();
185 #ifdef HAVE_ZOLTAN2_MPI
186 MPI_Comm mpicomm = Teuchos::getRawMpiComm(comm);
191 MPI_Initialized(&flag);
195 MPI_Init(&narg, &argv);
198 MPI_Comm mpicomm = MPI_COMM_WORLD;
202 int num_user =
sizeof(
gno_t);
205 ZOLTAN_ID_PTR ddkeys =
new ZOLTAN_ID_TYPE[num_gid * num_keys];
207 for (
size_t i = 0; i < num_keys; i++) {
208 for (
size_t v = 0; v < num_entries; v++) {
209 ZOLTAN_ID_PTR ddkey = &(ddkeys[idx]);
216 char *ddnewgids =
new char[num_user * num_keys];
219 size_t nUnique = findUniqueGidsCommon<gno_t>(num_keys, num_gid,
220 ddkeys, ddnewgids, mpicomm);
224 for (
size_t i = 0; i < num_keys; i++)
map_t::global_ordinal_type gno_t
size_t findUniqueGidsCommon(size_t num_keys, int num_gid, ZOLTAN_ID_PTR ddkeys, char *ddnewgids, MPI_Comm mpicomm)
size_t findUniqueGids(Tpetra::MultiVector< gno_t, lno_t, gno_t > &keys, Tpetra::Vector< gno_t, lno_t, gno_t > &gids)
static void ASSIGN(first_t &a, second_t b)
Traits class to handle conversions between gno_t/lno_t and TPL data types (e.g., ParMETIS's idx_t...
Gathering definitions used in software development.