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 ssize_t nDDEntries = (ssize_t)(dd->nodecnt);
94 MPI_Scan(&nDDEntries, &firstIdx, 1, MPI_LONG_LONG, MPI_SUM, mpicomm);
95 firstIdx -= nDDEntries;
99 for (DD_NodeIdx i = 0; i < dd->nodelistlen; i++) {
100 DD_Node *ptr = &(dd->nodelist[i]);
102 char *userchar = (
char*)(ptr->gid + (dd->gid_length + dd->lid_length));
103 gno_t *newgid = (gno_t*) userchar;
104 *newgid = gno_t(firstIdx + cnt);
111 Zoltan_DD_Find(dd, ddkeys, ddnotneeded, ddnewgids, NULL,
int(num_keys), NULL);
113 Zoltan_DD_Destroy(&dd);
116 MPI_Allreduce(&nDDEntries, &nUnique, 1, MPI_LONG_LONG, MPI_SUM, mpicomm);
118 return size_t(nUnique);
122 template <
typename lno_t,
typename gno_t>
124 Tpetra::MultiVector<gno_t, lno_t, gno_t> &keys,
125 Tpetra::Vector<gno_t, lno_t, gno_t> &gids
135 size_t num_keys = keys.getLocalLength();
136 size_t num_entries = keys.getNumVectors();
138 #ifdef HAVE_ZOLTAN2_MPI 139 MPI_Comm mpicomm = Teuchos::getRawMpiComm(*(keys.getMap()->getComm()));
144 MPI_Initialized(&flag);
148 MPI_Init(&narg, &argv);
151 MPI_Comm mpicomm = MPI_COMM_WORLD;
154 int num_gid =
sizeof(gno_t)/
sizeof(ZOLTAN_ID_TYPE) * num_entries;
155 int num_user =
sizeof(gno_t);
158 Teuchos::ArrayRCP<const gno_t> *tmpKeyVecs =
159 new Teuchos::ArrayRCP<const gno_t>[num_entries];
160 for (
size_t v = 0; v < num_entries; v++) tmpKeyVecs[v] = keys.getData(v);
162 ZOLTAN_ID_PTR ddkeys =
new ZOLTAN_ID_TYPE[num_gid * num_keys];
164 for (
size_t i = 0; i < num_keys; i++) {
165 for (
size_t v = 0; v < num_entries; v++) {
166 ZOLTAN_ID_PTR ddkey = &(ddkeys[idx]);
171 delete [] tmpKeyVecs;
174 char *ddnewgids =
new char[num_user * num_keys];
177 size_t nUnique = findUniqueGidsCommon<gno_t>(num_keys, num_gid,
178 ddkeys, ddnewgids, mpicomm);
181 gno_t *result = (gno_t *)ddnewgids;
182 for (
size_t i = 0; i < num_keys; i++)
183 gids.replaceLocalValue(i, result[i]);
193 template <
typename key_t,
typename gno_t>
195 std::vector<key_t> &keys,
196 std::vector<gno_t> &gids,
197 const Teuchos::Comm<int> &comm
215 size_t num_keys = keys.size();
217 size_t num_entries = dummy.size();
219 #ifdef HAVE_ZOLTAN2_MPI 220 MPI_Comm mpicomm = Teuchos::getRawMpiComm(comm);
225 MPI_Initialized(&flag);
229 MPI_Init(&narg, &argv);
232 MPI_Comm mpicomm = MPI_COMM_WORLD;
235 int num_gid =
sizeof(gno_t)/
sizeof(ZOLTAN_ID_TYPE) * num_entries;
236 int num_user =
sizeof(gno_t);
239 ZOLTAN_ID_PTR ddkeys =
new ZOLTAN_ID_TYPE[num_gid * num_keys];
241 for (
size_t i = 0; i < num_keys; i++) {
242 for (
size_t v = 0; v < num_entries; v++) {
243 ZOLTAN_ID_PTR ddkey = &(ddkeys[idx]);
250 char *ddnewgids =
new char[num_user * num_keys];
253 size_t nUnique = findUniqueGidsCommon<gno_t>(num_keys, num_gid,
254 ddkeys, ddnewgids, mpicomm);
257 gno_t *result = (gno_t *)ddnewgids;
258 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)
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.
static void ASSIGN_TPL_T(tpl_t &a, zno_t b)