76 auto hx = Kokkos::create_mirror_view(ox), hy = Kokkos::create_mirror_view(oy),
77 hz = Kokkos::create_mirror_view(oz), hb = Kokkos::create_mirror_view(b);
78 const IVec<3> gs = sc.gs;
79 double loc[2] = {0.0, 0.0}, glb[2];
80 for (
int pass = 0; pass < 2; ++pass) {
81 for (
int z = 0; z < ext.
z; ++z)
82 for (
int y = 0; y < ext.
y; ++y)
83 for (
int x = 0; x < ext.
x; ++x) {
84 const long i = (long)x + (
long)y * ext.
x + (long)z * (
long)ext.
x * ext.
y;
85 const int gx =
wrap(x -
G + og.x, (
int)gs[0]), gy =
wrap(y -
G + og.y, (
int)gs[1]),
86 gz =
wrap(z -
G + og.z, (
int)gs[2]);
87 const double cx = gx + 0.5, cy = gy + 0.5, cz = gz + 0.5;
89 x >=
G && x < ext.
x -
G && y >=
G && y < ext.
y -
G && z >=
G && z < ext.
z -
G;
90 const double f = std::sin(2.0 * M_PI * gx / gs[0]) * std::cos(M_PI * cy / gs[1]) +
91 0.5 * std::sin(2.0 * M_PI * (gz + 0.3 * sc.step) / gs[2]) +
93 const bool fluid = sc.open(cx, cy, cz) > 0.0 || sc.open(cx - 0.5, cy, cz) > 0.0;
95 hx(i) = sc.face(0, cx, cy, cz);
96 hy(i) = sc.face(1, cx, cy, cz);
97 hz(i) = sc.face(2, cx, cy, cz);
103 hb(i) = (inner && fluid) ? f - glb[0] / glb[1] : 0.0;
107 MPI_Allreduce(loc, glb, 2, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
109 Kokkos::deep_copy(ox, hx);
110 Kokkos::deep_copy(oy, hy);
111 Kokkos::deep_copy(oz, hz);
112 Kokkos::deep_copy(b, hb);
140 mg.initMpi(c.gs[0], c.gs[1], c.gs[2], c.nlev, MPI_COMM_WORLD);
145 const C3 ext = l0.
ext, og = l0.
og;
146 const std::size_t n = (std::size_t)ext.
x * ext.
y * ext.
z;
147 CCField ox(
"ox", n), oy(
"oy", n), oz(
"oz", n), b(
"b", n), x(
"x", n), r(
"r", n), p(
"p", n),
148 z(
"z", n), Ap(
"Ap", n);
151 for (
int s = 0; s <
STEPS; ++s) {
155 Kokkos::deep_copy(x, 0.0);
156 res.iters.push_back(mg.
solvePCG(b, x, r, p, z, Ap, 300, 1e-10, 2, 2, 8));
158 auto hx = Kokkos::create_mirror_view(x);
159 Kokkos::deep_copy(hx, x);
160 for (
int zz =
G; zz < ext.
z -
G; ++zz)
161 for (
int yy =
G; yy < ext.
y -
G; ++yy)
162 for (
int xx =
G; xx < ext.
x -
G; ++xx)
163 res.x.push_back(hx((
long)xx + (
long)yy * ext.
x + (
long)zz * (
long)ext.
x * ext.
y));
165 for (
int L = 0; L < res.levels; ++L) {
169 res.wrapAll = res.wrapAll && lv.wrapAxes == 7;
170 const long nf = (long)lv.halo->numNeighbors(), ns = (long)lv.shalo->numNeighbors();
171 const long gf = (long)lv.halo->numGhostRecv(), gsn = (long)lv.shalo->numGhostRecv();
175 res.ghStencil += gsn;
176 res.fewer = res.fewer && ns <= nf && gsn <= gf;
181int main(
int argc,
char** argv) {
182 MPI_Init(&argc, &argv);
183 Kokkos::initialize(argc, argv);
184 int rank = 0, size = 1;
185 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
186 MPI_Comm_size(MPI_COMM_WORLD, &size);
190 const Case cases[] = {
191 {
"walls y, periodic x z", {64, 48, 32}, 4, {0, 0, 1, 1, 0, 0}, -1, F64,
true,
true},
192 {
"walls y, band matvec", {64, 48, 32}, 4, {0, 0, 1, 1, 0, 0}, -1, F64,
false,
true},
193 {
"inflow -z / outflow +z, walls y",
201 {
"odd coarse z (48x40x30), walls y",
209 {
"forced telescope @1, walls y", {64, 48, 32}, 4, {0, 0, 1, 1, 0, 0}, 1, F64,
true,
true},
210 {
"all periodic (CA coarse levels)",
218 {
"FP32 V-cycle, walls y", {64, 48, 32}, 4, {0, 0, 1, 1, 0, 0}, -1, F32,
true,
true},
220 for (
const Case& c : cases) {
223 const bool sameIt = a.iters == h.iters;
224 const bool sameX = a.x.size() == h.x.size() &&
225 std::memcmp(a.x.data(), h.x.data(), a.x.size() *
sizeof(
double)) == 0;
226 int bad = (sameIt && sameX && a.fewer) ? 0 : 1;
227 if (size == 1 && c.wrap1 && !a.wrapAll)
230 MPI_Allreduce(&bad, &anyBad, 1, MPI_INT, MPI_MAX, MPI_COMM_WORLD);
231 long cnt[4] = {a.nbFull, a.nbStencil, a.ghFull, a.ghStencil}, tot[4];
232 MPI_Allreduce(cnt, tot, 4, MPI_LONG, MPI_SUM, MPI_COMM_WORLD);
236 std::printf(
" %-36s np=%d iters:", c.name, size);
237 for (std::size_t s = 0; s < a.iters.size(); ++s)
238 std::printf(
" %d/%d", a.iters[s], h.iters[s]);
239 std::printf(
" x %s nbrs full/stencil %ld/%ld ghosts %ld/%ld %s\n",
240 sameX ?
"bitwise" :
"DIFFERS", tot[0], tot[1], tot[2], tot[3],
241 anyBad ?
"FAIL" :
"ok");
246 MPI_Allreduce(&fail, &totalFail, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
249 std::printf(
"OK (np=%d): stencil halo == full halo, bitwise\n", size);
251 std::fprintf(stderr,
"FAILED (np=%d): %d case(s)\n", size, totalFail);
255 return totalFail == 0 ? 0 : 1;
int solvePCG(CCField b, CCField x, CCField r, CCField p, CCField z, CCField Ap, int maxit, double rtol, int pre, int post, int bottom, const StarOverlay *star=nullptr, int nStar=0, C3 nnStar=C3{0, 0, 0})