iterative-solver 0.0
DistrArrayGA.h
1#ifndef LINEARALGEBRA_SRC_MOLPRO_LINALG_ARRAY_DISTRARRAYGA_H
2#define LINEARALGEBRA_SRC_MOLPRO_LINALG_ARRAY_DISTRARRAYGA_H
3#include <map>
4
5#include "molpro/linalg/array/DistrArray.h"
6
7namespace molpro::linalg::array {
8
12class DistrArrayGA : public DistrArray {
13protected:
14 int m_comm_rank = 0;
15 int m_comm_size = 0;
16 int m_ga_handle = 0;
17 int m_ga_pgroup = 0;
18 int m_ga_chunk = 1;
19 bool m_ga_allocated = false;
21 static std::map<MPI_Comm, int> _ga_pgroups;
22 std::unique_ptr<Distribution> m_distribution;
23
24public:
25 DistrArrayGA() = delete;
26 DistrArrayGA(size_t dimension, MPI_Comm commun);
28 DistrArrayGA(const DistrArrayGA &source);
32 DistrArrayGA(DistrArrayGA &&source) noexcept;
34 DistrArrayGA &operator=(DistrArrayGA &&source) noexcept;
35 ~DistrArrayGA() override;
36
38 friend void swap(DistrArrayGA &a1, DistrArrayGA &a2) noexcept;
39 void sync() const override;
40
41protected:
43 explicit LocalBufferGA(DistrArrayGA &source);
44 };
45
46public:
47 [[nodiscard]] const Distribution &distribution() const override;
48 [[nodiscard]] std::unique_ptr<LocalBuffer> local_buffer() override;
49 [[nodiscard]] std::unique_ptr<const LocalBuffer> local_buffer() const override;
50 [[nodiscard]] value_type at(index_type ind) const override;
51 void set(index_type ind, value_type val) override;
52 void get(index_type lo, index_type hi, value_type *buf) const override;
53 [[nodiscard]] std::vector<value_type> get(index_type lo, index_type hi) const override;
54 void put(index_type lo, index_type hi, const value_type *data) override;
55 void acc(index_type lo, index_type hi, const value_type *data) override;
56 [[nodiscard]] std::vector<value_type> gather(const std::vector<index_type> &indices) const override;
57 void scatter(const std::vector<index_type> &indices, const std::vector<value_type> &data) override;
58 void scatter_acc(std::vector<index_type> &indices, const std::vector<value_type> &data) override;
59 [[nodiscard]] std::vector<value_type> vec() const override;
60 void error(const std::string &message) const override;
61
62protected:
65
68};
69
70} // namespace molpro::linalg::array
71
72#endif // LINEARALGEBRA_SRC_MOLPRO_LINALG_ARRAY_DISTRARRAYGA_H
Distributed array which uses Global Arrays for managing the array buffer and RMA calls.
Definition: DistrArrayGA.h:12
std::vector< value_type > vec() const override
Copies the whole buffer into a vector. Blocking.
void error(const std::string &message) const override
stops application with an error
static std::map< MPI_Comm, int > _ga_pgroups
Record every process group created, because GA can only allocate a fixed number of them.
Definition: DistrArrayGA.h:21
int m_ga_chunk
GA chunck size.
Definition: DistrArrayGA.h:18
Distribution make_distribution() const
void scatter_acc(std::vector< index_type > &indices, const std::vector< value_type > &data) override
array[indices[i]] += vals[i] Accumulates vals of elements into discontinuous indices of array....
bool m_ga_allocated
Definition: DistrArrayGA.h:19
void set(index_type ind, value_type val) override
Set one element to a scalar. Global operation.
value_type at(index_type ind) const override
friend void swap(DistrArrayGA &a1, DistrArrayGA &a2) noexcept
swap content of two arrays. Not collective.
std::unique_ptr< LocalBuffer > local_buffer() override
Access the buffer local to this process.
DistrArrayGA(size_t dimension, MPI_Comm commun)
DistrArrayGA & operator=(const DistrArrayGA &source)
Copy source, allocating buffer if necessary.
int m_ga_pgroup
Global Array processor group handle.
Definition: DistrArrayGA.h:17
void check_ga_ind_overlow(index_type ind) const
Checks if index will overflow when converted to int. Calls error() if it does.
std::unique_ptr< Distribution > m_distribution
Definition: DistrArrayGA.h:22
const Distribution & distribution() const override
Access distribution of the array among processes.
int m_comm_size
size of process group
Definition: DistrArrayGA.h:15
void get(index_type lo, index_type hi, value_type *buf) const override
Gets buffer[lo:hi) from global array (hi is past-the-end). Blocking.
DistrArrayGA(DistrArrayGA &&source) noexcept
Take ownership of source leaving it in undefined state. Not collective, no allocation/deallocation.
std::vector< value_type > get(index_type lo, index_type hi) const override
void put(index_type lo, index_type hi, const value_type *data) override
array[lo:hi) = data[:] (hi is past-the-end). Blocking
int m_comm_rank
rank in process group
Definition: DistrArrayGA.h:14
void acc(index_type lo, index_type hi, const value_type *data) override
array[lo:hi) += scaling_constant * data[:] (hi is past-the-end). Blocking
DistrArrayGA & operator=(DistrArrayGA &&source) noexcept
Take ownership of source leaving it in undefined state. Not collective, no allocation/deallocation.
int m_ga_handle
Global Array handle, needed by GA libary.
Definition: DistrArrayGA.h:16
void scatter(const std::vector< index_type > &indices, const std::vector< value_type > &data) override
array[indices[i]] = data[i] Puts vals of elements with discontinuous indices of array....
void sync() const override
Synchronizes all process in this group and ensures any outstanding operations on the array have compl...
std::unique_ptr< const LocalBuffer > local_buffer() const override
DistrArrayGA(const DistrArrayGA &source)
Make a copy of source, allocating buffer if necessary.
std::vector< value_type > gather(const std::vector< index_type > &indices) const override
gets elements with discontinuous indices from array. Blocking
Provides access to the local portion of the array.
Definition: DistrArray.h:123
Array distributed across many processes supporting remote-memory-access, access to process local buff...
Definition: DistrArray.h:90
double value_type
Definition: DistrArray.h:93
size_t index_type
Definition: DistrArray.h:94
Specifies distribution of a contiguous array into non-overlapping chunks.
Definition: Distribution.h:16
Definition: ArrayHandler.h:22