1 #ifndef SRC_SNAP_IMPLICIT_COMMUNICATION_HPP_
2 #define SRC_SNAP_IMPLICIT_COMMUNICATION_HPP_
11 #include <athena/globals.hpp>
12 #include <athena/hydro/hydro.hpp>
13 #include <athena/mesh/mesh.hpp>
30 std::string phy = std::to_string(k) +
"x" + std::to_string(
j) +
"x1";
32 memcpy(
buffer_[k][
j],
a.data(), s1 *
sizeof(Real));
34 if (nb.snb.rank != Globals::my_rank) {
37 MPI_Isend(
buffer_[k][
j], s1, MPI_ATHENA_REAL, nb.snb.rank, tag,
38 MPI_COMM_WORLD, &req_send_data1_[k][
j]);
42 std::memcpy(pbl->pimpl->phevi->buffer_[k][
j],
buffer_[k][
j],
47 template <
typename T1,
typename T2>
50 int s1 =
a.size(), s2 =
b.size();
52 std::string phy = std::to_string(k) +
"x" + std::to_string(
j) +
"x2";
54 memcpy(
buffer_[k][
j],
a.data(), s1 *
sizeof(Real));
55 memcpy(
buffer_[k][
j] + s1,
b.data(), s2 *
sizeof(Real));
57 if (nb.snb.rank != Globals::my_rank) {
60 MPI_Isend(
buffer_[k][
j], s1 + s2, MPI_ATHENA_REAL, nb.snb.rank, tag,
61 MPI_COMM_WORLD, &req_send_data2_[k][
j]);
65 std::memcpy(pbl->pimpl->phevi->buffer_[k][
j],
buffer_[k][
j],
66 (s1 + s2) *
sizeof(Real));
70 template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
73 T4
const &d, T5
const &
e, T6
const &f,
int k,
74 int j, NeighborBlock nb) {
75 int s1 =
a.size(), s2 =
b.size(), s3 = c.size(), s4 = d.size();
76 int s5 =
e.size(), s6 = f.size();
78 std::string phy = std::to_string(k) +
"x" + std::to_string(
j) +
"x6";
81 memcpy(it,
a.data(), s1 *
sizeof(Real));
83 memcpy(it,
b.data(), s2 *
sizeof(Real));
85 memcpy(it, c.data(), s3 *
sizeof(Real));
87 memcpy(it, d.data(), s4 *
sizeof(Real));
89 memcpy(it,
e.data(), s5 *
sizeof(Real));
91 memcpy(it, f.data(), s6 *
sizeof(Real));
93 int st = s1 + s2 + s3 + s4 + s5 + s6;
95 if (nb.snb.rank != Globals::my_rank) {
98 MPI_Isend(
buffer_[k][
j], st, MPI_ATHENA_REAL, nb.snb.rank, tag,
99 MPI_COMM_WORLD, &req_send_data6_[k][
j]);
103 std::memcpy(pbl->pimpl->phevi->buffer_[k][
j],
buffer_[k][
j],
108 template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
109 typename T6,
typename T7>
111 T4
const &d, T5
const &
e, T6
const &f,
112 T7
const &g,
int k,
int j, NeighborBlock nb) {
113 int s1 =
a.size(), s2 =
b.size(), s3 = c.size(), s4 = d.size();
114 int s5 =
e.size(), s6 = f.size(), s7 = g.size();
115 std::string phy = std::to_string(k) +
"x" + std::to_string(
j) +
"x7";
118 memcpy(it,
a.data(), s1 *
sizeof(Real));
120 memcpy(it,
b.data(), s2 *
sizeof(Real));
122 memcpy(it, c.data(), s3 *
sizeof(Real));
124 memcpy(it, d.data(), s4 *
sizeof(Real));
126 memcpy(it,
e.data(), s5 *
sizeof(Real));
128 memcpy(it, f.data(), s6 *
sizeof(Real));
130 memcpy(it, g.data(), s7 *
sizeof(Real));
132 int st = s1 + s2 + s3 + s4 + s5 + s6 + s7;
134 if (nb.snb.rank != Globals::my_rank) {
137 MPI_Isend(
buffer_[k][
j], st, MPI_ATHENA_REAL, nb.snb.rank, tag,
138 MPI_COMM_WORLD, &req_send_data7_[k][
j]);
142 std::memcpy(pbl->pimpl->phevi->buffer_[k][
j],
buffer_[k][
j],
147 template <
typename T>
151 std::string phy = std::to_string(k) +
"x" + std::to_string(
j) +
"x1";
156 if (nb.snb.rank != Globals::my_rank) {
159 MPI_Recv(
buffer_[k][
j], s1, MPI_ATHENA_REAL, nb.snb.rank, tag,
160 MPI_COMM_WORLD, &status);
164 memcpy(
a.data(),
buffer_[k][
j], s1 *
sizeof(Real));
167 template <
typename T1,
typename T2>
169 int s1 =
a.size(), s2 =
b.size();
171 std::string phy = std::to_string(k) +
"x" + std::to_string(
j) +
"x2";
176 if (nb.snb.rank != Globals::my_rank) {
179 MPI_Recv(
buffer_[k][
j], s1 + s2, MPI_ATHENA_REAL, nb.snb.rank, tag,
180 MPI_COMM_WORLD, &status);
184 memcpy(
a.data(),
buffer_[k][
j], s1 *
sizeof(Real));
185 memcpy(
b.data(),
buffer_[k][
j] + s1, s2 *
sizeof(Real));
188 template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
191 int j, NeighborBlock nb) {
192 int s1 =
a.size(), s2 =
b.size(), s3 = c.size(), s4 = d.size();
193 int s5 =
e.size(), s6 = f.size();
195 std::string phy = std::to_string(k) +
"x" + std::to_string(
j) +
"x6";
200 int st = s1 + s2 + s3 + s4 + s5 + s6;
202 if (nb.snb.rank != Globals::my_rank) {
205 MPI_Recv(
buffer_[k][
j], st, MPI_ATHENA_REAL, nb.snb.rank, tag,
206 MPI_COMM_WORLD, &status);
211 memcpy(
a.data(), it, s1 *
sizeof(Real));
213 memcpy(
b.data(), it, s2 *
sizeof(Real));
215 memcpy(c.data(), it, s3 *
sizeof(Real));
217 memcpy(d.data(), it, s4 *
sizeof(Real));
219 memcpy(
e.data(), it, s5 *
sizeof(Real));
221 memcpy(f.data(), it, s6 *
sizeof(Real));
224 template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
225 typename T6,
typename T7>
227 int k,
int j, NeighborBlock nb) {
228 int s1 =
a.size(), s2 =
b.size(), s3 = c.size(), s4 = d.size();
229 int s5 =
e.size(), s6 = f.size(), s7 = g.size();
231 std::string phy = std::to_string(k) +
"x" + std::to_string(
j) +
"x7";
236 int st = s1 + s2 + s3 + s4 + s5 + s6 + s7;
238 if (nb.snb.rank != Globals::my_rank) {
241 MPI_Recv(
buffer_[k][
j], st, MPI_ATHENA_REAL, nb.snb.rank, tag,
242 MPI_COMM_WORLD, &status);
247 memcpy(
a.data(), it, s1 *
sizeof(Real));
249 memcpy(
b.data(), it, s2 *
sizeof(Real));
251 memcpy(c.data(), it, s3 *
sizeof(Real));
253 memcpy(d.data(), it, s4 *
sizeof(Real));
255 memcpy(
e.data(), it, s5 *
sizeof(Real));
257 memcpy(f.data(), it, s6 *
sizeof(Real));
259 memcpy(g.data(), it, s7 *
sizeof(Real));
262 template <
typename T1,
typename T2>
264 int k,
int j,
int il,
int iu) {
265 for (
int i = il; i <= iu; ++i) {
266 int s1 =
a[i].size(), s2 =
b[i].size();
272 template <
typename T1,
typename T2,
typename T3,
typename T4>
274 std::vector<T3> &c, std::vector<T4> &d,
275 int k,
int j,
int il,
int iu) {
276 for (
int i = il; i <= iu; ++i) {
277 int s1 =
a[i].size(), s2 =
b[i].size(), s3 = c[i].size(), s4 = d[i].size();
286 template <
typename T1,
typename T2>
288 int k,
int j,
int il,
int iu) {
289 for (
int i = il; i <= iu; ++i) {
290 int s1 =
a[i].size(), s2 =
b[i].size();
296 template <
typename T1,
typename T2,
typename T3,
typename T4>
298 std::vector<T3> &c, std::vector<T4> &d,
299 int k,
int j,
int il,
int iu) {
300 for (
int i = il; i <= iu; ++i) {
301 int s1 =
a[i].size(), s2 =
b[i].size(), s3 = c[i].size(), s4 = d[i].size();
int CreateMPITag(int lid, int bufid, std::string phy)
void RecvBuffer(T &a, int k, int j, NeighborBlock nb)
AthenaArray< Real > coefficients_
void LoadCoefficients(std::vector< T1 > &a, std::vector< T2 > &b, int k, int j, int il, int iu)
void SaveCoefficients(std::vector< T1 > &a, std::vector< T2 > &b, int k, int j, int il, int iu)
MeshBlock const * pmy_block_
void SendBuffer(T const &a, int k, int j, NeighborBlock nb)