2"""The bubble-column step from ckpt_t43 on the DISTRIBUTED solver (init_mpi, any np): prof.py's case
3and protocol on this rank's ORB block, for the np-gates of doc/vof_projection_distributed_design.md
4ยง8 (G-DD3: 'auto' / forced 'fp32' against 'fp64' at the same np, G-NUM-P 1-3; G-DD4: projection
7The case is run_peclet.build()'s, block by block (as ~/Codes/bubble_column_perf/run_mpi.py): the
8global arrays of the checkpoint are sliced to the rank's block, the VoF markers are passed as the
9global list, the column is closed by the device set_superficial_velocity (rank-aware). W warm-up
10steps (not timed, default 5), then N timed steps with prof.py's dt rule. Unlike prof.py the flux
11closure is always the device one (prof.py's default host shift is single-rank).
14 PYTHONPATH=<PECLET_FLOW_MPI build> OMP_NUM_THREADS=2 OMP_PROC_BIND=false \\
15 mpirun -np P --bind-to none python tests/study/vof_perf/prof_mpi.py N [--pcg|--fcg]
16 [--rtol R] [--vcycle-precision auto|fp64|fp32] [--initial-guess MODE]
17 [--warm W] [--dump out.npz] [--ckpt PATH] [--case-dir DIR] [--tile TX[,TZ]]
19 --tile periodic replication of the checkpoint TX times along x and TZ times along z (both
20 periodic; the -y/+y walls are kept): global grid (TX NX, NY, TZ NZ), u/v/w/p tiled, each
21 VoF block marker copied once per tile with its box shifted by whole periods (a weak-
22 scaling column at constant cells per rank; default 1,1 = the checkpoint itself)
24 --dump rank 0 saves the GATHERED u, v, w, p, C, the timed steps' dt, pressure iterations
25 (iters), max_open_divergence_projected() (div) and projection ms (proj_ms, the max
26 over ranks of diagnostics.last_step_timers()['projection'])
27Prints one line on rank 0: np, block, ms/step, projection ms/step (mean and min), iterations, the
28precision the last solve used; then one machine-readable `RESULT key=value ...` line with the same
29numbers, the global grid and the requested --vcycle-precision. Rank 0 writes `[prof_mpi] timed steps
30begin` to stderr before the first timed step, so restarts in the timed window are the warning lines
31after it. An 'auto' FP64 restart prints its own warning line on rank 0's
32stderr (no Python counter exists, design Q-4).
44def arg(name, default, cast=str):
45 return cast(A[A.index(name) + 1])
if name
in A
else default
48CASE_DIR =
arg(
"--case-dir", os.path.expanduser(
49 "~/Codes/peclet-examples/benchmarks/bubble-column/scripts"))
50CKPT =
arg(
"--ckpt", os.path.expanduser(
"~/Codes/bubble_column_perf/ckpt_t43.npz"))
51sys.path.insert(0, CASE_DIR)
54import run_peclet
as rp
57WARM =
arg(
"--warm", 5, int)
58RTOL =
arg(
"--rtol", 1e-10, float)
59DUMP =
arg(
"--dump",
None)
61rank, size = comm.Get_rank(), comm.Get_size()
63_tile = [int(x)
for x
in arg(
"--tile",
"1,1").split(
",")]
64TX, TZ = _tile[0], (_tile[1]
if len(_tile) > 1
else 1)
65NX, NY, NZ = TX * case.NX, case.NY, TZ * case.NZ
67step, t, blocks, vel, pres, series = rp.load_ckpt(CKPT)
69 vel = [np.asfortranarray(np.tile(a, (TX, 1, TZ)))
for a
in vel]
70 pres = np.asfortranarray(np.tile(pres, (TX, 1, TZ)))
72 for box, col
in blocks:
73 sx = -(box[0] // case.NX) * case.NX
74 sz = -(box[2] // case.NZ) * case.NZ
77 ox, oz = sx + i * case.NX, sz + k * case.NZ
78 tiled.append(([box[0] + ox, box[1], box[2] + oz, box[3] + ox, box[4], box[5] + oz],
81org, siz = pf.mpi_block(NX, NY, NZ)
82sl = tuple(
slice(o, o + n)
for o, n
in zip(org, siz))
86s.set_mu(S * S * case.MU_L)
88s.set_domain_bc(
"-y",
"wall", (0, 0, 0))
89s.set_domain_bc(
"+y",
"wall", (0, 0, 0))
90s.set_pressure_geometry(np.full(tuple(siz), 10.0, order=
"F"))
92s.set_vof(np.zeros(tuple(siz), order=
"F"))
93s.set_property_model(
"rho",
"linear",
"C", [case.RHO_L, case.RHO_G - case.RHO_L])
94s.set_property_model(
"mu",
"linear",
"C", [S * S * case.MU_L, S * S * (case.MU_G - case.MU_L)])
95s.set_surface_tension(S ** 3 * case.SIGMA)
96s.set_pressure_pcg(
True, 800, 1e-8)
97s.enable_vof_blocks_from_colors([b
for b, _
in blocks], [c
for _, c
in blocks])
98s.enable_vof_block_csf()
99vol = comm.allreduce(sum(b[
"volume"]
for b
in s.diagnostics.vof_block_stats()), op=MPI.SUM)
100alpha = vol / (NX * NY * NZ)
101rho_av = case.RHO_L + (case.RHO_G - case.RHO_L) * alpha
102s.set_property_model(
"force_x",
"linear",
"C",
103 [S * (case.RHO_L - rho_av) * case.G, S * (case.RHO_G - case.RHO_L) * case.G])
104s.set_superficial_velocity(
True,
"x", 0.0)
106 s.set_pressure_pcg(
True, 800, RTOL)
108 s.set_pressure_fcg(
True, 800, RTOL)
109if "--vcycle-precision" in A:
110 s.diagnostics.set_pressure_vcycle_precision(
arg(
"--vcycle-precision",
"fp64"))
111if "--initial-guess" in A:
112 s.diagnostics.set_pressure_initial_guess(
arg(
"--initial-guess",
"zero"),
113 arg(
"--guess-history", 2, int))
114for c, a
in enumerate(vel):
115 s.set_velocity(c, np.asfortranarray(a[sl]))
116s.set_field(
"p", np.asfortranarray(pres[sl]))
117s.diagnostics.set_vof_step_parity(step)
119iters, divs, dts, projs, steps = [], [], [], [], []
123 L = s.vof_step_limits()
124 dt = min(0.25 * L[
"cfl_dt"], 0.25 * L[
"capillary_dt"])
126 t0 = time.perf_counter()
128 t1 = time.perf_counter()
131 iters.append(s.diagnostics.last_pressure_iterations())
132 divs.append(comm.allreduce(float(s.max_open_divergence_projected()), op=MPI.MAX))
133 projs.append(comm.allreduce(float(s.diagnostics.last_step_timers()[
"projection"]),
135 steps.append(comm.allreduce(t1 - t0, op=MPI.MAX))
142 print(
"[prof_mpi] timed steps begin", file=sys.stderr, flush=
True)
143w0 = time.perf_counter()
147wall = time.perf_counter() - w0
151 parts = comm.gather((org, siz, np.asarray(a)), root=0)
154 g = np.zeros((NX, NY, NZ), order=
"F")
155 for o, n, b
in parts:
156 g[o[0]:o[0] + n[0], o[1]:o[1] + n[1], o[2]:o[2] + n[2]] = b
160fields = {k:
gather(f())
for k, f
in ((
"u", s.get_u), (
"v", s.get_v), (
"w", s.get_w),
161 (
"p",
lambda: s.get_field(
"p")),
162 (
"C",
lambda: s.get_field(
"C")))}
163prec = s.diagnostics.pressure_vcycle_precision()
165 pm = 1000 * np.asarray(projs)
166 print(f
"np {size} block {list(siz)} steps {N} wall {1000 * wall / N:.2f} ms/step "
167 f
"(step max-rank mean {1000 * np.mean(steps):.2f}) projection mean {pm.mean():.2f} "
168 f
"min {pm.min():.2f} ms/step | pressure iters mean {np.mean(iters):.2f} min "
169 f
"{min(iters)} max {max(iters)} | last precision {prec} | load "
170 f
"{os.getloadavg()[0]:.1f}", flush=
True)
171 print(f
"RESULT np={size} grid={NX}x{NY}x{NZ} block={'x'.join(map(str, siz))} "
172 f
"mode={arg('--vcycle-precision', 'default')} precision={prec} steps={N} "
173 f
"proj_ms={pm.mean():.4f} proj_min_ms={pm.min():.4f} iters={np.mean(iters):.3f} "
174 f
"step_ms={1000 * np.mean(steps):.4f} wall_ms={1000 * wall / N:.4f}", flush=
True)
176 np.savez(DUMP, **fields, dts=np.array(dts), iters=np.array(iters, dtype=np.int64),
177 div=np.array(divs), proj_ms=pm)
178 print(
"dumped", DUMP, flush=
True)
arg(name, default, cast=str)
static std::vector< double > slice(const std::vector< double > &g, int ox, int oy, int oz, int lnx, int lny, int lnz)