Chi-Tech
GhostedParallelSTLVector.h
Go to the documentation of this file.
1#ifndef GHOSTED_PARALLEL_VECTOR_H
2#define GHOSTED_PARALLEL_VECTOR_H
3
4#include "ParallelSTLVector.h"
5
7
8namespace chi_math
9{
10
12{
13public:
14 /**
15 * Initialize the ghosted parallel vector with the given local and global
16 * sizes, with the specified global ghost indices.
17 */
18 GhostedParallelSTLVector(const uint64_t local_size,
19 const uint64_t global_size,
20 const std::vector<int64_t>& ghost_ids,
21 const MPI_Comm communicator = MPI_COMM_WORLD)
22 : ParallelSTLVector(local_size, global_size, communicator),
23 ghost_comm_(local_size, global_size, ghost_ids, communicator)
24 {
26 }
27
28 /// Initialize a ghosted parallel vector from a ghost communicator.
30 : ParallelSTLVector(ghost_comm.LocalSize(),
31 ghost_comm.GlobalSize(),
32 ghost_comm.Communicator()),
33 ghost_comm_(ghost_comm)
34 {
36 }
37
38 /**Copy constructor.*/
40 : ParallelSTLVector(other),
42 {
43 }
44
45 /**Move constructor.*/
47 : ParallelSTLVector(std::move(other)),
48 ghost_comm_(std::move(other.ghost_comm_))
49 {
50 }
51
52 std::unique_ptr<ParallelVector> MakeCopy() const override;
53 std::unique_ptr<ParallelVector> MakeClone() const override;
54
55 /// Return the number of ghosts associated with the local vector.
56 uint64_t NumGhosts() const { return ghost_comm_.NumGhosts(); }
57
58 /// Return the total size of the local vector, including ghosts.
59 uint64_t LocalSizeWithGhosts() const { return values_.size(); }
60
61 /// Return the ghost indices associated with the local vector.
62 const std::vector<int64_t>& GhostIndices() const
63 {
65 }
66
67 /// Map a global ghost id to its respective local id.
68 int64_t MapGhostToLocal(const int64_t ghost_id) const
69 {
70 return ghost_comm_.MapGhostToLocal(ghost_id);
71 }
72
73 /// Return a vector containing the locally owned data and ghost data.
74 std::vector<double> MakeGhostedLocalVector() const { return values_; }
75
76 /**
77 * Return the value of the parallel vector for the specified global index.
78 *
79 * An error is thrown if the global index does not belong to a locally
80 * owned, or ghost entry.
81 */
82 double GetGlobalValue(int64_t global_id) const;
83
84 /**
85 * Communicate the current ghost entries to all other processes to
86 * update the locally stored ghost data.
87 */
89 {
91 }
92
93private:
95};
96
97} // namespace chi_math
98
99#endif // GHOSTED_PARALLEL_VECTOR_H
const std::vector< int64_t > & GhostIndices() const
Return the ghost indices associated with the local vector.
uint64_t NumGhosts() const
Return the number of ghosts associated with the local vector.
GhostedParallelSTLVector(const uint64_t local_size, const uint64_t global_size, const std::vector< int64_t > &ghost_ids, const MPI_Comm communicator=MPI_COMM_WORLD)
std::unique_ptr< ParallelVector > MakeClone() const override
int64_t MapGhostToLocal(const int64_t ghost_id) const
Map a global ghost id to its respective local id.
double GetGlobalValue(int64_t global_id) const
std::unique_ptr< ParallelVector > MakeCopy() const override
GhostedParallelSTLVector(const VectorGhostCommunicator &ghost_comm)
Initialize a ghosted parallel vector from a ghost communicator.
GhostedParallelSTLVector(const GhostedParallelSTLVector &other)
std::vector< double > MakeGhostedLocalVector() const
Return a vector containing the locally owned data and ghost data.
uint64_t LocalSizeWithGhosts() const
Return the total size of the local vector, including ghosts.
GhostedParallelSTLVector(GhostedParallelSTLVector &&other) noexcept
ParallelSTLVector(uint64_t local_size, uint64_t global_size, MPI_Comm communicator)
std::vector< double > values_
const uint64_t local_size_
uint64_t GlobalSize() const
Return the global size of the parallel vector.
uint64_t LocalSize() const
Return the size of the locally owned portion of the parallel vector.
int64_t MapGhostToLocal(int64_t ghost_id) const
const std::vector< int64_t > & GhostIndices() const
void CommunicateGhostEntries(std::vector< double > &ghosted_vector) const