ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
transfer.h
Go to the documentation of this file.
1#ifndef HCONTAINERTRANSFER_H
2#define HCONTAINERTRANSFER_H
3
4#include <unordered_map>
5#include <vector>
6
7#include "./hcontainer.h"
8
9#ifdef __MPI
10namespace hamilt
11{
12
13// MPI tags for the HContainer serial<->parallel transfer (transfer.cpp) and
14// Read_HContainer::read() (read_hcontainer.cpp). They must match between the
15// send and the recv side, so they live here to be shared. Deliberately odd,
16// high values: the transfer previously used fixed tags 0/1/2 on
17// MPI_COMM_WORLD, which collide with unrelated p2p traffic (write_eig_occ,
18// output_log, func_transfer, ...) on any other call path and cause
19// MPI_ERR_TRUNCATE races or deadlocks. Moving to these uncommon tags removes
20// the need for the masking MPI_Barrier calls in op_exx_lcao.cpp.
21constexpr int kHctTagSize = 14431; // payload size (MPI_LONG)
22constexpr int kHctTagIndex = 14471; // atom/orbital index array (MPI_INT)
23constexpr int kHctTagValue = 14533; // matrix values (T)
24
25template <typename T>
27{
28 public:
29 HTransPara(int n_processes, HContainer<T> *hr_in);
31
41 void cal_orb_indexes(int irank, std::vector<int> *orb_indexes = nullptr);
42
48 void receive_ap_indexes(int irank, const int *ap_indexes_in = nullptr, const long &size_ap_indexes_in = 0);
49
54 void send_orb_indexes(int irank, MPI_Request *request = nullptr);
55
60 void send_data(int irank, MPI_Request *request = nullptr);
61
66 void receive_data(int irank, const T *values = nullptr);
67
72 void pack_data(int irank, T *values = nullptr);
73
74 long get_max_size() const;
75 void get_value_size(int *out) const;
76
77 private:
78 std::vector<std::vector<int>> ap_indexes;
79 HContainer<T> *hr = nullptr;
80
81 // temporary variables
82 std::vector<std::vector<int>> atom_i_index;
83
84 const Parallel_Orbitals *paraV = nullptr;
85
86 // unpack BaseMatrix-values from ith rank
87 void unpack_data(int irank, const T *values);
88
89 // size of data of all BaseMatrixes
90 std::vector<long> size_values;
91};
92
93template <typename T>
95{
96 public:
97 HTransSerial(int n_processes, HContainer<T> *hr_in);
99
105 void cal_ap_indexes(int irank, std::vector<int> *ap_indexes = nullptr);
106
111 void send_ap_indexes(int irank, MPI_Request *request = nullptr);
112
117 void receive_orb_indexes(int irank, const int *orb_indexes_in = nullptr, const long &size_orb_indexes_in = 0);
118
123 void send_data(int irank, MPI_Request *request = nullptr);
124
129 void receive_data(int irank, const T *values = nullptr);
130
135 void pack_data(int irank, T *values = nullptr);
136
137 long get_max_size() const;
138 void get_value_size(int *out) const;
139
140 private:
141 std::vector<std::vector<int>> orb_indexes;
142 HContainer<T> *hr = nullptr;
143
148 void unpack_data(int irank, const T *values);
149
150 // temporary variables
151 std::vector<std::unordered_map<int, int>> orb_col_indexes;
152 std::vector<std::unordered_map<int, int>> orb_row_indexes;
153
154 // size of data of all BaseMatrixes
155 std::vector<long> size_values;
156};
157
158} // namespace hamilt
159
163template <typename T>
165
166template <>
167struct MPITraits<int>
168{
169 static MPI_Datatype datatype() { return MPI_INT; }
170};
171
172template <>
173struct MPITraits<double>
174{
175 static MPI_Datatype datatype() { return MPI_DOUBLE; }
176};
177
178template <>
179struct MPITraits<std::complex<double>>
180{
181 static MPI_Datatype datatype() { return MPI_DOUBLE_COMPLEX; }
182};
183
184#endif // __MPI
185
186#endif // HCONTAINERTRANSFER_H
Definition parallel_orbitals.h:16
Definition hcontainer.h:147
std::vector< long > size_values
Definition transfer.h:90
std::vector< std::vector< int > > atom_i_index
Definition transfer.h:82
void pack_data(int irank, T *values=nullptr)
pack BaseMatrix-values for ith rank
Definition transfer.cpp:195
void send_data(int irank, MPI_Request *request=nullptr)
pack data in this->hr, and send to ith rank
Definition transfer.cpp:162
void cal_orb_indexes(int irank, std::vector< int > *orb_indexes=nullptr)
calculate Orbital indexes and will be send to irank the format of the return value is: [size_i,...
Definition transfer.cpp:36
const Parallel_Orbitals * paraV
Definition transfer.h:84
HContainer< T > * hr
Definition transfer.h:79
HTransPara(int n_processes, HContainer< T > *hr_in)
Definition transfer.cpp:20
std::vector< std::vector< int > > ap_indexes
Definition transfer.h:78
void receive_ap_indexes(int irank, const int *ap_indexes_in=nullptr, const long &size_ap_indexes_in=0)
receive AtomPair_indexes from the ith rank save to this->ap_indexes[irank]
Definition transfer.cpp:92
void receive_data(int irank, const T *values=nullptr)
receive data from ith rank, save them to this->hr
Definition transfer.cpp:177
void unpack_data(int irank, const T *values)
Definition transfer.cpp:237
~HTransPara()
Definition transfer.cpp:30
long get_max_size() const
Definition transfer.cpp:282
void send_orb_indexes(int irank, MPI_Request *request=nullptr)
pack data in this->hr, and send to ith rank
Definition transfer.cpp:144
void get_value_size(int *out) const
Definition transfer.cpp:288
long get_max_size() const
Definition transfer.cpp:647
HContainer< T > * hr
Definition transfer.h:142
void send_ap_indexes(int irank, MPI_Request *request=nullptr)
calculate AtomPair_indexes of hr_in and send to the ith rank
Definition transfer.cpp:378
void pack_data(int irank, T *values=nullptr)
pack BaseMatrix-values for ith rank
Definition transfer.cpp:479
std::vector< std::vector< int > > orb_indexes
Definition transfer.h:141
void get_value_size(int *out) const
Definition transfer.cpp:652
void receive_data(int irank, const T *values=nullptr)
receive data from ith rank, save them to this->hr
Definition transfer.cpp:461
HTransSerial(int n_processes, HContainer< T > *hr_in)
Definition transfer.cpp:302
void receive_orb_indexes(int irank, const int *orb_indexes_in=nullptr, const long &size_orb_indexes_in=0)
receive Orbital_indexes from the ith rank save to this->orb_indexes[irank]
Definition transfer.cpp:397
void send_data(int irank, MPI_Request *request=nullptr)
pack data in this->hr, and send to ith rank
Definition transfer.cpp:446
std::vector< long > size_values
Definition transfer.h:155
std::vector< std::unordered_map< int, int > > orb_col_indexes
Definition transfer.h:151
void cal_ap_indexes(int irank, std::vector< int > *ap_indexes=nullptr)
calculate AtomPair indexes and will be send to irank called in plan_indexes
Definition transfer.cpp:317
void unpack_data(int irank, const T *values)
unpack BaseMatrix-values from ith rank
Definition transfer.cpp:563
std::vector< std::unordered_map< int, int > > orb_row_indexes
Definition transfer.h:152
~HTransSerial()
Definition transfer.cpp:312
#define complex
Definition elpa_new.h:28
#define T
Definition exp.cpp:237
Definition wf_op.cpp:6
constexpr int kHctTagSize
Definition transfer.h:21
constexpr int kHctTagValue
Definition transfer.h:23
constexpr int kHctTagIndex
Definition transfer.h:22
static MPI_Datatype datatype()
Definition transfer.h:175
static MPI_Datatype datatype()
Definition transfer.h:169
static MPI_Datatype datatype()
Definition transfer.h:181
Struct to get MPI_datatype.
Definition transfer.h:164