61static std::vector<double>
blockOf(
const std::vector<double>& g,
const BlockDecomposer<3>& dec,
63 const auto b = dec.block(rank);
64 const int ox = (int)b.origin[0], oy = (
int)b.origin[1], oz = (int)b.origin[2];
65 const int lnx = (int)b.size[0], lny = (
int)b.size[1], lnz = (int)b.size[2];
66 std::vector<double> l((std::size_t)lnx * lny * lnz);
67 for (
int z = 0; z < lnz; ++z)
68 for (
int y = 0; y < lny; ++y)
69 for (
int x = 0; x < lnx; ++x)
70 l[(std::size_t)x + (std::size_t)y * lnx + (std::size_t)z * lnx * lny] =
71 g[(std::size_t)(x + ox) + (std::size_t)(y + oy) *
N + (std::size_t)(z + oz) *
N *
N];
93static std::vector<double>
gatherGlobal(
const std::vector<double>& local,
94 const BlockDecomposer<3>& dec,
int rank,
int size) {
95 std::vector<double> global;
97 global.assign((std::size_t)
N *
N *
N, 0.0);
98 for (
int r = 0; r < size; ++r) {
99 const auto b = dec.block(r);
100 const int ox = (int)b.origin[0], oy = (
int)b.origin[1], oz = (int)b.origin[2];
101 const int lnx = (int)b.size[0], lny = (
int)b.size[1], lnz = (int)b.size[2];
102 std::vector<double> buf;
107 MPI_Send(buf.data(), (
int)buf.size(), MPI_DOUBLE, 0, 300 + r, MPI_COMM_WORLD);
108 else if (rank == 0) {
109 buf.resize((std::size_t)lnx * lny * lnz);
110 MPI_Recv(buf.data(), (
int)buf.size(), MPI_DOUBLE, r, 300 + r, MPI_COMM_WORLD,
115 for (
int z = 0; z < lnz; ++z)
116 for (
int y = 0; y < lny; ++y)
118 &global[(std::size_t)ox + (std::size_t)(y + oy) *
N + (std::size_t)(z + oz) *
N *
N],
119 &buf[(std::size_t)y * lnx + (std::size_t)z * lnx * lny],
120 (std::size_t)lnx *
sizeof(
double));
125int main(
int argc,
char** argv) {
126 MPI_Init(&argc, &argv);
127 Kokkos::initialize(argc, argv);
128 int fail = 0, size = 1, rank = 0;
130 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
131 MPI_Comm_size(MPI_COMM_WORLD, &size);
132 const std::vector<double> gsdf =
packingSdf();
133 std::vector<double> geps((std::size_t)
N *
N *
N);
134 for (
int z = 0; z <
N; ++z)
135 for (
int y = 0; y <
N; ++y)
136 for (
int x = 0; x <
N; ++x)
137 geps[(std::size_t)x + (std::size_t)y *
N + (std::size_t)z *
N *
N] =
epsAt(x, y, z);
141 BlockDecomposer<3> D1((std::size_t)size, IVec<3>{
N,
N,
N});
142 std::vector<peclet::core::Real> w((std::size_t)
N *
N *
N, 1.0);
143 for (
int z = 0; z <
N; ++z)
144 for (
int y = 0; y <
N; ++y)
145 for (
int x = 0; x <
N; ++x)
146 if (x <
N / 3 || z <
N / 4)
147 w[(std::size_t)x + (std::size_t)y *
N + (std::size_t)z *
N *
N] = 5.0;
148 BlockDecomposer<3> D2((std::size_t)size, IVec<3>{
N,
N,
N}, w);
150 for (
int k = 0; k < 3; ++k)
151 resized |= D1.block(rank).size[k] != D2.block(rank).size[k];
153 const auto b1 = D1.block(rank);
154 IbmSolver sd((
int)b1.size[0], (
int)b1.size[1], (
int)b1.size[2]);
155 sd.initMpi(D1, MPI_COMM_WORLD);
157 for (
int it = 0; it <
STEPS / 2; ++it)
165 MPI_Allreduce(&resized, &anyResized, 1, MPI_INT, MPI_MAX, MPI_COMM_WORLD);
170 for (
int it = 0; it <
STEPS; ++it)
172 const std::vector<double> ur = ref.getVelocity(0), wr = ref.getVelocity(2);
173 double du = 0, dw = 0, mu = 0;
174 for (std::size_t i = 0; i < ur.size(); ++i) {
175 du = std::max(du, std::fabs(ud[i] - ur[i]));
176 dw = std::max(dw, std::fabs(wd[i] - wr[i]));
177 mu = std::max(mu, std::fabs(ur[i]));
179 const double rel = std::max(du, dw) / mu;
180 const double tol = (size == 1) ? 0.0 : 1e-6;
182 " np=%d: blocks resized %s; max|du|=%.3e max|dw|=%.3e (max|u| %.3e) rel=%.2e"
184 size, anyResized ?
"yes" :
"no", du, dw, mu, rel, tol);
185 if (!(rel <= tol) || (size > 1 && !anyResized))
190 MPI_Allreduce(&fail, &totalFail, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
192 std::printf(totalFail == 0 ?
"OK (np=%d): a porous redistribute leaves the solution unchanged\n"
193 :
"FAILED (np=%d)\n",
197 return totalFail == 0 ? 0 : 1;