51 #ifndef _ZOLTAN2_FINDUNIQUEGIDS_HPP_
52 #define _ZOLTAN2_FINDUNIQUEGIDS_HPP_
57 #include <Tpetra_MultiVector.hpp>
58 #include <Tpetra_Vector.hpp>
62 #include <zoltan_dd.h>
63 #include <zoltan_dd_const.h>
68 template <
typename gno_t>
79 int num_user =
sizeof(gno_t);
81 Zoltan_DD_Struct *dd = NULL;
82 Zoltan_DD_Create(&dd, mpicomm, num_gid, num_lid, num_user, num_keys,
85 ZOLTAN_ID_PTR ddnotneeded = NULL;
86 Zoltan_DD_Update(dd, ddkeys, ddnotneeded, ddnewgids, NULL,
int(num_keys));
92 typedef long long mpi_t;
93 mpi_t nDDEntries = (mpi_t)(dd->nodecnt);
95 MPI_Scan(&nDDEntries, &firstIdx, 1, MPI_LONG_LONG, MPI_SUM, mpicomm);
96 firstIdx -= nDDEntries;
101 for (DD_NodeIdx i = 0; i < dd->nodelistlen; i++) {
102 DD_Node *ptr = &(dd->nodelist[i]);
104 char *userchar = (
char*)(ptr->gid + (dd->gid_length + dd->lid_length));
105 gno_t *newgid = (gno_t*) userchar;
106 *newgid = gno_t(firstIdx + cnt);
113 Zoltan_DD_Find(dd, ddkeys, ddnotneeded, ddnewgids, NULL,
int(num_keys), NULL);
115 Zoltan_DD_Destroy(&dd);
118 MPI_Allreduce(&nDDEntries, &nUnique, 1, MPI_LONG_LONG, MPI_SUM, mpicomm);
120 return size_t(nUnique);
124 template <
typename lno_t,
typename gno_t>
126 Tpetra::MultiVector<gno_t, lno_t, gno_t> &keys,
127 Tpetra::Vector<gno_t, lno_t, gno_t> &gids
137 size_t num_keys = keys.getLocalLength();
138 size_t num_entries = keys.getNumVectors();
140 #ifdef HAVE_ZOLTAN2_MPI
141 MPI_Comm mpicomm = Teuchos::getRawMpiComm(*(keys.getMap()->getComm()));
146 MPI_Initialized(&flag);
150 MPI_Init(&narg, &argv);
153 MPI_Comm mpicomm = MPI_COMM_WORLD;
157 int num_user =
sizeof(gno_t);
160 Teuchos::ArrayRCP<const gno_t> *tmpKeyVecs =
161 new Teuchos::ArrayRCP<const gno_t>[num_entries];
162 for (
size_t v = 0; v < num_entries; v++) tmpKeyVecs[v] = keys.getData(v);
164 ZOLTAN_ID_PTR ddkeys =
new ZOLTAN_ID_TYPE[num_gid * num_keys];
166 for (
size_t i = 0; i < num_keys; i++) {
167 for (
size_t v = 0; v < num_entries; v++) {
168 ZOLTAN_ID_PTR ddkey = &(ddkeys[idx]);
173 delete [] tmpKeyVecs;
176 char *ddnewgids =
new char[num_user * num_keys];
179 size_t nUnique = findUniqueGidsCommon<gno_t>(num_keys, num_gid,
180 ddkeys, ddnewgids, mpicomm);
183 gno_t *result = (gno_t *)ddnewgids;
184 for (
size_t i = 0; i < num_keys; i++)
185 gids.replaceLocalValue(i, result[i]);
195 template <
typename key_t,
typename gno_t>
197 std::vector<key_t> &keys,
198 std::vector<gno_t> &gids,
199 const Teuchos::Comm<int> &comm
217 size_t num_keys = keys.size();
219 size_t num_entries = dummy.size();
221 #ifdef HAVE_ZOLTAN2_MPI
222 MPI_Comm mpicomm = Teuchos::getRawMpiComm(comm);
227 MPI_Initialized(&flag);
231 MPI_Init(&narg, &argv);
234 MPI_Comm mpicomm = MPI_COMM_WORLD;
238 int num_user =
sizeof(gno_t);
241 ZOLTAN_ID_PTR ddkeys =
new ZOLTAN_ID_TYPE[num_gid * num_keys];
243 for (
size_t i = 0; i < num_keys; i++) {
244 for (
size_t v = 0; v < num_entries; v++) {
245 ZOLTAN_ID_PTR ddkey = &(ddkeys[idx]);
252 char *ddnewgids =
new char[num_user * num_keys];
255 size_t nUnique = findUniqueGidsCommon<gno_t>(num_keys, num_gid,
256 ddkeys, ddnewgids, mpicomm);
259 gno_t *result = (gno_t *)ddnewgids;
260 for (
size_t i = 0; i < num_keys; i++)
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.