https://mooseframework.inl.gov
Public Member Functions | Protected Attributes | List of all members
StochasticTools::DistributedData< T > Class Template Reference

Templated class that specifies a distributed storage of a vector of given objects. More...

#include <DistributedData.h>

Inheritance diagram for StochasticTools::DistributedData< T >:
[legend]

Public Member Functions

 DistributedData (const libMesh::Parallel::Communicator &comm_in)
 
void initializeContainer (unsigned int num_global_entries)
 Initialize the container with a given number of samples. More...
 
void changeEntry (unsigned int glob_i, const T &sample)
 Changing a sample with a global index if it is owned locally. More...
 
void addNewEntry (unsigned int glob_i, const T &sample)
 Adding a new sample locally with a global index. More...
 
void closeContainer ()
 Closes the container meaning that no new samples can be added or the already existing samples canot be changed. More...
 
bool hasGlobalEntry (unsigned int glob_i) const
 Checking of sample with global ID is locally owned ot not. More...
 
std::vector< T >::iterator localEntryBegin ()
 Getting an itertor to the beginning of the local samples. More...
 
std::vector< T >::iterator localEntryEnd ()
 Getting an iterator to the end of the locally owned samples. More...
 
std::vector< unsigned int >::iterator localEntryIDBegin ()
 Getting an iterator to the beginning of the locally owned sample IDs. More...
 
std::vector< unsigned int >::iterator localEntryIDEnd ()
 Getting an iterator to the end of the locally owned sample IDs. More...
 
const T & getGlobalEntry (unsigned int glob_i) const
 Getting a sample using its global index. More...
 
const T & getLocalEntry (unsigned int loc_i) const
 Getting a sample using its local index. More...
 
const std::vector< T > & getLocalEntries () const
 Getting all of the locally owned samples. More...
 
const std::vector< unsigned int > & getLocalEntryIDs () const
 Getting the vector of sample IDs for locally owned samples. More...
 
unsigned int getNumberOfGlobalEntries () const
 Getting the number of global samples. More...
 
unsigned int getNumberOfLocalEntries () const
 Getting the number of locally owned samples. More...
 
unsigned int getLocalIndex (unsigned int glob_i) const
 Getting the local index of a global sample if locally owned. More...
 
unsigned int getGlobalIndex (unsigned int loc_i) const
 Getting the global index of a locally owned sample. More...
 
const Parallel::Communicator & comm () const
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 

Protected Attributes

std::vector< T > _local_entries
 The vector where the samples are stored. More...
 
std::vector< unsigned int_local_entry_ids
 The vector where the global sample IDs are stored. More...
 
bool _closed
 Flag which shows if the container is closed or not. More...
 
unsigned int _n_local_entries
 Number of local samples. More...
 
const Parallel::Communicator & _communicator
 

Detailed Description

template<typename T>
class StochasticTools::DistributedData< T >

Templated class that specifies a distributed storage of a vector of given objects.

It has a helper vector that contains global IDs for every stored item.

Definition at line 24 of file DistributedData.h.

Constructor & Destructor Documentation

◆ DistributedData()

template<typename T >
StochasticTools::DistributedData< T >::DistributedData ( const libMesh::Parallel::Communicator comm_in)

Definition at line 19 of file DistributedData.C.

20  : libMesh::ParallelObject(comm_in), _closed(false), _n_local_entries(0)
21 {
22 }
unsigned int _n_local_entries
Number of local samples.
bool _closed
Flag which shows if the container is closed or not.

Member Function Documentation

◆ addNewEntry()

template<typename T >
void StochasticTools::DistributedData< T >::addNewEntry ( unsigned int  glob_i,
const T &  sample 
)

Adding a new sample locally with a global index.

Definition at line 56 of file DistributedData.C.

57 {
58  auto it = std::find(_local_entry_ids.begin(), _local_entry_ids.end(), glob_i);
59  if (it != _local_entry_ids.end())
60  ::mooseError("Local object ID (", glob_i, ") already exists!");
61  if (_closed)
62  ::mooseError("DistributeData has already been closed, cannot add new elements!");
63 
64  _local_entries.push_back(entry);
65  _local_entry_ids.push_back(glob_i);
66  _n_local_entries += 1;
67 }
void mooseError(Args &&... args)
unsigned int _n_local_entries
Number of local samples.
std::vector< T > _local_entries
The vector where the samples are stored.
bool _closed
Flag which shows if the container is closed or not.
std::vector< unsigned int > _local_entry_ids
The vector where the global sample IDs are stored.

◆ changeEntry()

template<typename T >
void StochasticTools::DistributedData< T >::changeEntry ( unsigned int  glob_i,
const T &  sample 
)

Changing a sample with a global index if it is owned locally.

Definition at line 71 of file DistributedData.C.

72 {
73  auto it = std::find(_local_entry_ids.begin(), _local_entry_ids.end(), glob_i);
74  if (it == _local_entry_ids.end())
75  ::mooseError("Local object ID (", glob_i, ") does not exists!");
76  if (_closed)
77  ::mooseError("DistributeData has already been closed, cannot change elements!");
78 
79  _local_entries[std::distance(_local_entry_ids.begin(), it)] = entry;
80 }
void mooseError(Args &&... args)
std::vector< T > _local_entries
The vector where the samples are stored.
bool _closed
Flag which shows if the container is closed or not.
std::vector< unsigned int > _local_entry_ids
The vector where the global sample IDs are stored.

◆ closeContainer()

template<typename T >
void StochasticTools::DistributedData< T >::closeContainer ( )
inline

Closes the container meaning that no new samples can be added or the already existing samples canot be changed.

Definition at line 41 of file DistributedData.h.

41 { _closed = true; };
bool _closed
Flag which shows if the container is closed or not.

◆ getGlobalEntry()

template<typename T >
const T & StochasticTools::DistributedData< T >::getGlobalEntry ( unsigned int  glob_i) const

Getting a sample using its global index.

Definition at line 84 of file DistributedData.C.

85 {
86  auto it = std::find(_local_entry_ids.begin(), _local_entry_ids.end(), glob_i);
87  if (it == _local_entry_ids.end())
88  ::mooseError("Local object ID (", glob_i, ") does not exists!");
89 
90  return _local_entries[std::distance(_local_entry_ids.begin(), it)];
91 }
void mooseError(Args &&... args)
std::vector< T > _local_entries
The vector where the samples are stored.
std::vector< unsigned int > _local_entry_ids
The vector where the global sample IDs are stored.

◆ getGlobalIndex()

template<typename T >
unsigned int StochasticTools::DistributedData< T >::getGlobalIndex ( unsigned int  loc_i) const

Getting the global index of a locally owned sample.

Definition at line 140 of file DistributedData.C.

141 {
142  if (loc_i > _n_local_entries - 1)
143  ::mooseError("The requested local index (",
144  loc_i,
145  ") is greater than the size (",
147  ") of the locally stored vector!");
148 
149  return _local_entry_ids[loc_i];
150 }
unsigned int _n_local_entries
Number of local samples.
std::vector< unsigned int > _local_entry_ids
The vector where the global sample IDs are stored.

◆ getLocalEntries()

template<typename T >
const std::vector<T>& StochasticTools::DistributedData< T >::getLocalEntries ( ) const
inline

Getting all of the locally owned samples.

Definition at line 68 of file DistributedData.h.

68 { return _local_entries; };
std::vector< T > _local_entries
The vector where the samples are stored.

◆ getLocalEntry()

template<typename T >
const T & StochasticTools::DistributedData< T >::getLocalEntry ( unsigned int  loc_i) const

Getting a sample using its local index.

Definition at line 95 of file DistributedData.C.

96 {
97  if (loc_i > _n_local_entries - 1)
98  ::mooseError("The requested local index (",
99  loc_i,
100  ") is greater than the size (",
102  ") of the locally stored vector!");
103 
104  return _local_entries[loc_i];
105 }
unsigned int _n_local_entries
Number of local samples.
std::vector< T > _local_entries
The vector where the samples are stored.

◆ getLocalEntryIDs()

template<typename T >
const std::vector<unsigned int>& StochasticTools::DistributedData< T >::getLocalEntryIDs ( ) const
inline

Getting the vector of sample IDs for locally owned samples.

Definition at line 71 of file DistributedData.h.

71 { return _local_entry_ids; };
std::vector< unsigned int > _local_entry_ids
The vector where the global sample IDs are stored.

◆ getLocalIndex()

template<typename T >
unsigned int StochasticTools::DistributedData< T >::getLocalIndex ( unsigned int  glob_i) const

Getting the local index of a global sample if locally owned.

Definition at line 129 of file DistributedData.C.

130 {
131  const auto it = std::find(_local_entry_ids.begin(), _local_entry_ids.end(), glob_i);
132  if (it == _local_entry_ids.end())
133  ::mooseError("Local object ID (", glob_i, ") does not exists!");
134 
135  return std::distance(_local_entry_ids.begin(), it);
136 }
void mooseError(Args &&... args)
std::vector< unsigned int > _local_entry_ids
The vector where the global sample IDs are stored.

◆ getNumberOfGlobalEntries()

template<typename T >
unsigned int StochasticTools::DistributedData< T >::getNumberOfGlobalEntries ( ) const

Getting the number of global samples.

Definition at line 109 of file DistributedData.C.

110 {
111  unsigned int val = _n_local_entries;
112  _communicator.sum(val);
113  return val;
114 }
unsigned int _n_local_entries
Number of local samples.
const Parallel::Communicator & _communicator

◆ getNumberOfLocalEntries()

template<typename T >
unsigned int StochasticTools::DistributedData< T >::getNumberOfLocalEntries ( ) const
inline

Getting the number of locally owned samples.

Definition at line 77 of file DistributedData.h.

77 { return _n_local_entries; };
unsigned int _n_local_entries
Number of local samples.

◆ hasGlobalEntry()

template<typename T >
bool StochasticTools::DistributedData< T >::hasGlobalEntry ( unsigned int  glob_i) const

Checking of sample with global ID is locally owned ot not.

Definition at line 118 of file DistributedData.C.

119 {
120  const auto it = std::find(_local_entry_ids.begin(), _local_entry_ids.end(), glob_i);
121  if (it != _local_entry_ids.end())
122  return true;
123 
124  return false;
125 }
std::vector< unsigned int > _local_entry_ids
The vector where the global sample IDs are stored.

◆ initializeContainer()

template<typename T >
void StochasticTools::DistributedData< T >::initializeContainer ( unsigned int  num_global_entries)

Initialize the container with a given number of samples.

this partitions the samples using linearPartitioning.

Definition at line 26 of file DistributedData.C.

27 {
28  // This function can be used when a linear partitioning is required and the
29  // number of global samples is known in advance. We must temporarily
30  // use dof_id_type for the last three args (pass by reference),
31  // but will cast back to unsigned int later
32  dof_id_type local_entry_begin;
33  dof_id_type local_entry_end;
34  dof_id_type n_local_entries;
35 
36  MooseUtils::linearPartitionItems(n_global_entries,
37  n_processors(),
38  processor_id(),
39  n_local_entries,
40  local_entry_begin,
41  local_entry_end);
42  _n_local_entries = n_local_entries;
45 
46  // Filling the sample ID vector, leaving the elements of the sample vector
47  // with the default constructor.
48  for (unsigned int entry_i = local_entry_begin; entry_i < (unsigned int)local_entry_end; ++entry_i)
49  {
50  _local_entry_ids[entry_i] = entry_i;
51  }
52 }
unsigned int _n_local_entries
Number of local samples.
std::vector< T > _local_entries
The vector where the samples are stored.
void linearPartitionItems(dof_id_type num_items, dof_id_type num_chunks, dof_id_type chunk_id, dof_id_type &num_local_items, dof_id_type &local_items_begin, dof_id_type &local_items_end)
processor_id_type n_processors() const
std::vector< unsigned int > _local_entry_ids
The vector where the global sample IDs are stored.
processor_id_type processor_id() const
void ErrorVector unsigned int
uint8_t dof_id_type

◆ localEntryBegin()

template<typename T >
std::vector<T>::iterator StochasticTools::DistributedData< T >::localEntryBegin ( )
inline

Getting an itertor to the beginning of the local samples.

Definition at line 47 of file DistributedData.h.

47 { return _local_entries.begin(); };
std::vector< T > _local_entries
The vector where the samples are stored.

◆ localEntryEnd()

template<typename T >
std::vector<T>::iterator StochasticTools::DistributedData< T >::localEntryEnd ( )
inline

Getting an iterator to the end of the locally owned samples.

Definition at line 50 of file DistributedData.h.

50 { return _local_entries.end(); };
std::vector< T > _local_entries
The vector where the samples are stored.

◆ localEntryIDBegin()

template<typename T >
std::vector<unsigned int>::iterator StochasticTools::DistributedData< T >::localEntryIDBegin ( )
inline

Getting an iterator to the beginning of the locally owned sample IDs.

Definition at line 53 of file DistributedData.h.

54  {
55  return _local_entry_ids.begin();
56  };
std::vector< unsigned int > _local_entry_ids
The vector where the global sample IDs are stored.

◆ localEntryIDEnd()

template<typename T >
std::vector<unsigned int>::iterator StochasticTools::DistributedData< T >::localEntryIDEnd ( )
inline

Getting an iterator to the end of the locally owned sample IDs.

Definition at line 59 of file DistributedData.h.

59 { return _local_entry_ids.end(); };
std::vector< unsigned int > _local_entry_ids
The vector where the global sample IDs are stored.

Member Data Documentation

◆ _closed

template<typename T >
bool StochasticTools::DistributedData< T >::_closed
protected

Flag which shows if the container is closed or not.

Definition at line 93 of file DistributedData.h.

Referenced by StochasticTools::DistributedData< T >::closeContainer().

◆ _local_entries

template<typename T >
std::vector<T> StochasticTools::DistributedData< T >::_local_entries
protected

◆ _local_entry_ids

template<typename T >
std::vector<unsigned int> StochasticTools::DistributedData< T >::_local_entry_ids
protected

◆ _n_local_entries

template<typename T >
unsigned int StochasticTools::DistributedData< T >::_n_local_entries
protected

Number of local samples.

Definition at line 96 of file DistributedData.h.

Referenced by StochasticTools::DistributedData< T >::getNumberOfLocalEntries().


The documentation for this class was generated from the following files: