10#ifndef ZOLTAN2_DIRECTORY_H_
11#define ZOLTAN2_DIRECTORY_H_
13#include <Teuchos_DefaultComm.hpp>
14#include <Teuchos_CommHelpers.hpp>
25#include <Kokkos_UnorderedMap.hpp>
35template <
typename g
id_t,
typename l
id_t,
typename user_t>
54template <
typename g
id_t,
typename l
id_t>
65template <
typename g
id_t,
typename l
id_t>
74template <
typename g
id_t,
typename l
id_t>
87template <
typename g
id_t,
typename l
id_t,
typename user_t>
107 Teuchos::RCP<
const Teuchos::Comm<int> > comm_,
126 const int * partition,
137 bool throw_if_missing =
true);
161 for(
size_t n = 0; n <
node_map.capacity(); ++n) {
162 if(
node_map.value_at(n).free == 0) {
163 local_gids[cnt++] =
node_map.key_at(n);
168 throw std::logic_error(
"Unexpected counts. Internal error with the"
169 " node_map behavior.");
178 typedef long long mpi_t;
179 mpi_t nDDEntries =
static_cast<mpi_t
>(
node_map.size());
181 Teuchos::scan(*
comm, Teuchos::REDUCE_SUM,
182 1, &nDDEntries, &firstIdx);
183 firstIdx -= nDDEntries;
185 for(
size_t n = 0; n <
node_map.capacity(); ++n) {
186 if(
node_map.value_at(n).free == 0) {
203 int partition,
int owner);
207 int *partition,
int *owner,
bool throw_if_missing =
true)
const;
218 typedef Kokkos::UnorderedMap<gid_t,
233 unsigned int hash_proc(
const gid_t & gid)
const;
236 Teuchos::RCP<const Teuchos::Comm<int> >
comm;
259 bool throw_if_missing =
true)
const {
return 0; };
264 void rehash_node_map(
size_t new_hash_size) {
269template <
typename g
id_t,
typename l
id_t,
typename user_t>
296 this->comm = src.
comm;
297 this->use_lid = src.use_lid;
298 this->debug_level = src.debug_level;
318 throw std::logic_error(
"Aggregate doesn't mean anything for single "
319 "types. Must use Zoltan2_Directory_Vector class.");
321 throw std::logic_error(
"AggregateAdd doesn't mean anything for single "
322 "types. Must use Zoltan2_Directory_Vector class.");
351 bool throw_if_missing =
true)
const {
362template <
typename g
id_t,
typename l
id_t,
typename user_t>
389 this->comm = src.
comm;
390 this->use_lid = src.use_lid;
391 this->debug_level = src.debug_level;
404 size_t * pLength = (
size_t*)(pRaw);
405 size_t read_array_length = *pLength;
413 dst.resize(read_array_length);
414 for(
size_t i = 0; i < read_array_length; ++i) {
422 if(dst.size() !=
static_cast<size_t>(read_array_length)) {
423 throw std::logic_error(
"The data lengths are not the same size");
426 for(
size_t i = 0; i < dst.size(); ++i) {
443 for(
size_t i = 0; i < read_array_length; ++i) {
445 if(dst.size() == 0 || (*pRead) > dst[dst.size()-1]) {
446 dst.push_back(*pRead);
450 for(
auto itr = dst.begin(); itr != dst.end(); ++itr) {
451 if((*itr) == (*pRead)) {
458 else if((*itr) > (*pRead)) {
459 dst.insert(itr, (*pRead));
507 for(
size_t i = 0; i < read_array_length; ++i) {
509 for(
auto itr = dst.begin(); itr != dst.end(); ++itr) {
510 if((*itr) == (*pRead)) {
517 dst.push_back(*pRead);
530 size_t *pLength = (
size_t*)(pRaw);
531 *pLength = src.size();
534 for(
size_t n = 0; n < src.size(); ++n) {
543 size_t* pLength = (
size_t*) pRaw;
544 dst.resize(
static_cast<size_t>(*pLength));
547 for(
size_t n = 0; n < dst.size(); ++n) {
556 return sizeof(
typename user_t::value_type);
572 size_t * pLength = (
size_t*) (pRaw);
573 return this->update_msg_size +
580 bool throw_if_missing =
true)
const {
581 if(this->node_map.exists(*gid)) {
583 this->node_map.value_at(this->node_map.find(*gid));
586 else if(throw_if_missing) {
587 throw std::logic_error(
"Could not find gid in map." );
601 if(msg->
proc == -1) {
609 size_t * pVectorLength =
611 return this->find_msg_size + (*pVectorLength) *
sizeof(
user_val_t);
Zoltan2::BasicUserTypes< zscalar_t, zlno_t, zgno_t > user_t
Zoltan2_Directory_Simple(const Zoltan2_Directory_Simple< gid_t, lid_t, user_t > &src)
Copy constructor.
virtual size_t get_update_msg_size(const user_t *pRaw) const
virtual void update_local_user(const user_t *pRaw, user_t &dst)
Zoltan2_Directory_Simple(Teuchos::RCP< const Teuchos::Comm< int > > comm_, bool use_lid_, int debug_level_)
Constructo directory which handles simple user data types.
virtual void raw_to_user(const user_t *pRaw, user_t &dst) const
virtual size_t get_local_find_msg_size(gid_t *gid, bool throw_if_missing=true) const
virtual bool is_Zoltan2_Directory_Vector() const
virtual size_t size_of_value_type() const
virtual size_t get_update_msg_size(const user_t &data) const
virtual void user_to_raw(const user_t &src, user_t *pRaw) const
virtual size_t get_incoming_find_msg_size(Zoltan2_DD_Find_Msg< gid_t, lid_t > *msg) const
user_t::value_type user_val_t
Zoltan2_Directory_Vector(const Zoltan2_Directory_Vector< gid_t, lid_t, user_t > &src)
Copy constructor.
virtual void update_local_user(const user_t *pRaw, user_t &dst)
virtual size_t get_incoming_find_msg_size(Zoltan2_DD_Find_Msg< gid_t, lid_t > *msg) const
Zoltan2_Directory_Vector(Teuchos::RCP< const Teuchos::Comm< int > > comm_, bool use_lid_, int debug_level_)
Constructo directory which handles std::vector user data types.
virtual size_t get_update_msg_size(const user_t &data) const
virtual void raw_to_user(const user_t *pRaw, user_t &dst) const
virtual size_t get_local_find_msg_size(gid_t *gid, bool throw_if_missing=true) const
virtual size_t size_of_value_type() const
virtual void user_to_raw(const user_t &src, user_t *pRaw) const
virtual size_t get_update_msg_size(const user_t *pRaw) const
virtual bool is_Zoltan2_Directory_Vector() const
Zoltan2_Directory is an abstract base class.
Update_Mode
Update_Mode determines how update executes.
@ Aggregate
For std::vector user data, aggregates all data so for example [1,2,5] and [3,5] becomes [1,...
@ AggregateAdd
In progress and needs discussion. Currently this mode will use operator== to determine if two items m...
@ Add
All values from different procs are summed.
@ Replace
The new value replaces the original value.
virtual size_t get_local_find_msg_size(gid_t *gid, bool throw_if_missing=true) const
Zoltan2_Directory(Teuchos::RCP< const Teuchos::Comm< int > > comm_, bool use_lid_, int debug_level_)
Construct Zoltan2_Directory (abstract class).
virtual bool is_Zoltan2_Directory_Vector() const
Kokkos::UnorderedMap< gid_t, Zoltan2_Directory_Node< gid_t, lid_t, user_t >, Kokkos::HostSpace > node_map_t
virtual size_t size_of_value_type() const
virtual void update_local_user(const user_t *pRaw, user_t &dst)
virtual size_t get_update_msg_size(const user_t &data) const
virtual void user_to_raw(const user_t &src, user_t *pRaw) const
int update_local(gid_t *gid, lid_t *lid, user_t *user, int partition, int owner)
void remap_user_data_as_unique_gids()
virtual size_t get_incoming_find_msg_size(Zoltan2_DD_Find_Msg< gid_t, lid_t > *msg) const
Teuchos::RCP< const Teuchos::Comm< int > > comm
int remove_local(gid_t *gid)
virtual ~Zoltan2_Directory()
Destructor currently does nothing.
bool is_use_lid() const
returns true if the directory is handling local ids.
virtual size_t get_update_msg_size(const user_t *pRaw) const
int print() const
gids to remove.
size_t node_map_size() const
int remove(size_t length, const gid_t *gid)
if true will throw if a gid is not found. This is used by the unit tests to properly assess if remove...
int update(size_t length, const gid_t *gid, const lid_t *lid, const user_t *user, const int *partition, Update_Mode update_mode)
update is called by user to submit new data.
virtual void raw_to_user(const user_t *pRaw, user_t &dst) const
int copy(const Zoltan2_Directory< gid_t, lid_t, user_t > &dd)
int find_local(gid_t *gid, lid_t *lid, user_t *user, int *partition, int *owner, bool throw_if_missing=true) const
void get_locally_managed_gids(std::vector< gid_t > &local_gids) const
void stats() const
stats. New Kokkos mode needs further development.
unsigned int hash_proc(const gid_t &gid) const
int find(size_t length, const gid_t *gid, lid_t *lid, user_t *user, int *partition, int *owner, bool throw_if_missing=true)
Can be Replace, Add, or Aggregate.
Created by mbenlioglu on Aug 31, 2020.