2"""Multi-GPU WEAK scaling of a periodic swarm of deformable bubbles (block VoF, momentum advection
3on, the case-A groups): a fixed box of cells per rank, tiled along x, then y, then z.
5 PYTHONPATH=<PECLET_FLOW_MPI build> \\
6 srun --mpi=pmix --ntasks=P --gpus-per-task=1 --gpu-bind=per_task:1 \\
7 python tests/study/vof_perf/weak_swarm.py N [--warm W] [--cells n] [--d-over-h D]
8 [--bubbles-per-axis B] [--rtol R] [--levels L] [--comm-avoiding MODE] [--single]
9 [--out FILE.json] [--tag T]
11The case is case A of the bubble-swarm validation (tests/study/case_a on branch case-a: Ar 29.9,
12Bo 2, rho_b/rho_l = mu_b/mu_l = 0.1, buoyancy with the mixture weight removed, the volume mean u_x
13held at 0 by set_superficial_velocity) with many bubbles instead of one, in CELL units as
14prof_mpi.py / run_peclet.build() (D = rho_l = g = 1, lengths scaled by S = d/h: mu' = S^2 mu,
15sigma' = S^3 sigma, g' = S g; test_vof_blocks_physical_units.py proves the physical domain equal
16to 1e-12). Gravity along -x, triply periodic, starting at rest.
18Per rank: an n^3 box (default 256^3) carrying B^3 bubbles (default 2^3 = 8) of diameter d/h cells
19(default 20) on a lattice of spacing n/B, each centre perturbed by up to +-PERTURB/2 of the free
20gap with the fixed seed SEED. The rank box is tiled (TX, TY, TZ) times, doubling x, then y, then z
21(P = 1, 2, 4, 8, 16, 32 -> (1,1,1), (2,1,1), (2,2,1), (2,2,2), (4,2,2), (4,4,2)); every tile carries
22the SAME perturbed bubble set, so every rank has the same work when the ORB blocks are the tiles.
24--levels L sets the pressure multigrid depth (set_pressure_multigrid(True, L), before the geometry);
25without it the solver default (4) is used. At 4 levels a 256^3 box keeps a 32^3-per-rank coarsest
26level, which goes to the host GraphAMG bottom (rebuilt every step under variable density).
28--comm-avoiding MODE sets diagnostics.set_comm_avoiding(MODE) ('both' | 'off' | 'momentum' |
29'pressure') before init_mpi; without it the solver default ('both') is used. The modes are
30bit-identical by construction: a measurement of the halo-exchange cost, not of the physics.
32At P = 1 the default is the DISTRIBUTED path (init_mpi at size 1, as prof_mpi.py); --single runs the
33single-rank solver instead (no mpi_block/init_mpi, as run_mpi.py), the honest one-GPU reference.
35W warm-up steps (default 5), then N timed steps, dt = 0.25 min(CFL, capillary) every step (case A).
36Rank 0 prints one `RESULT key=value ...` line and, with --out, writes the same numbers as JSON:
37ms/step (wall), max-rank step / projection / momentum / predictor / pressure-allreduce ms, pressure
38iterations, cells per rank, the ORB block sizes, setup seconds, and `hash`: SHA-256 over every
39rank's u, v, w, p, C (rank order) plus the timed dt and iteration sequences -- equal hashes at the
40same P are the bit-identity gate across MPI transports (PECLET_CORE_GPU_AWARE_MPI=0/1).
54def arg(name, default, cast=str):
55 return cast(A[A.index(name) + 1])
if name
in A
else default
59AR, BO, RHO_RATIO, MU_RATIO = 29.9, 2.0, 0.1, 0.1
60RHO_L, G, D = 1.0, 1.0, 1.0
61RHO_G = RHO_RATIO * RHO_L
62MU_L = np.sqrt(RHO_L * abs(RHO_G - RHO_L) * G * D ** 3) / AR
64SIGMA = abs(RHO_G - RHO_L) * G * D ** 2 / BO
65SEED, PERTURB = 20261024, 0.25
68WARM =
arg(
"--warm", 5, int)
69CELLS =
arg(
"--cells", 256, int)
70S =
arg(
"--d-over-h", 20.0, float)
71B =
arg(
"--bubbles-per-axis", 2, int)
72RTOL =
arg(
"--rtol", 1e-8, float)
73LEVELS =
arg(
"--levels",
None, int)
74CA =
arg(
"--comm-avoiding",
None)
75OUT =
arg(
"--out",
None)
78rank, size = comm.Get_rank(), comm.Get_size()
79SINGLE =
"--single" in A
80if SINGLE
and size != 1:
81 sys.exit(
"--single needs exactly one rank")
85 """Doubling x, then y, then z: p must be a power of two."""
87 sys.exit(f
"weak_swarm: {p} ranks is not a power of two")
90 while t[0] * t[1] * t[2] < p:
97NX, NY, NZ = TX * CELLS, TY * CELLS, TZ * CELLS
101 """One rank box's perturbed B^3 lattice (fixed seed), replicated over every tile; cell units."""
102 rng = np.random.default_rng(SEED)
106 sys.exit(f
"weak_swarm: bubbles (d/h {S}) do not fit a lattice spacing of {sp} cells")
111 c = (np.array([i, j, k]) + 0.5) * sp + (rng.random(3) - 0.5) * PERTURB * gap
117 o = np.array([tx, ty, tz]) * CELLS
118 out += [(float(c[0] + o[0]), float(c[1] + o[1]), float(c[2] + o[2]), 0.5 * S)
123t_setup0 = time.perf_counter()
127 org, siz = (0, 0, 0), (NX, NY, NZ)
129 org, siz = pf.mpi_block(NX, NY, NZ)
132 s.diagnostics.set_comm_avoiding(CA)
134 s.init_mpi(NX, NY, NZ)
135if LEVELS
is not None:
136 s.set_pressure_multigrid(
True, LEVELS)
138s.set_mu(S * S * MU_L)
139s.set_pressure_geometry(np.full(tuple(siz), 10.0, order=
"F"))
141s.set_vof(np.zeros(tuple(siz), order=
"F"))
143s.set_property_model(
"rho",
"linear",
"C", [RHO_L, RHO_G - RHO_L])
144s.set_property_model(
"mu",
"linear",
"C", [S * S * MU_L, S * S * (MU_G - MU_L)])
145s.set_surface_tension(S ** 3 * SIGMA)
147s.enable_vof_blocks(seeds)
148s.enable_vof_block_csf()
149vol = comm.allreduce(sum(b[
"volume"]
for b
in s.diagnostics.vof_block_stats()), op=MPI.SUM)
150alpha = vol / (NX * NY * NZ)
151rho_av = RHO_L + (RHO_G - RHO_L) * alpha
153s.set_property_model(
"force_x",
"linear",
"C",
154 [-S * (RHO_L - rho_av) * G, -S * (RHO_G - RHO_L) * G])
155s.set_superficial_velocity(
True,
"x", 0.0)
156s.set_pressure_pcg(
True, 800, RTOL)
159t_setup = comm.allreduce(time.perf_counter() - t_setup0, op=MPI.MAX)
161dts, iters, rows = [], [], []
162KEYS = (
"step",
"projection",
"momentum",
"predictor",
"pressure_allreduce")
166 lim = s.vof_step_limits()
167 dt = 0.25 * min(lim[
"cfl_dt"], lim[
"capillary_dt"])
169 t0 = time.perf_counter()
171 t1 = time.perf_counter()
173 tm = s.diagnostics.last_step_timers()
175 iters.append(s.diagnostics.last_pressure_iterations())
176 rows.append([t1 - t0] + [float(tm[k])
for k
in KEYS])
183 print(
"[weak_swarm] timed steps begin", file=sys.stderr, flush=
True)
184w0 = time.perf_counter()
188wall = time.perf_counter() - w0
192Rmax = np.empty_like(R)
193comm.Allreduce(R, Rmax, op=MPI.MAX)
194mean_ms = 1000.0 * Rmax.mean(axis=0)
197for f
in (s.get_u, s.get_v, s.get_w,
lambda: s.get_field(
"p"),
lambda: s.get_field(
"C")):
198 h.update(np.ascontiguousarray(f()).tobytes())
199digests = comm.gather(h.hexdigest(), root=0)
200blocks = comm.gather(
"x".join(map(str, siz)), root=0)
205 g.update(np.asarray(dts).tobytes())
206 g.update(np.asarray(iters, dtype=np.int64).tobytes())
207 ub = sorted(set(blocks))
209 "tag": TAG,
"np": size,
"path":
"single" if SINGLE
else "distributed",
210 "gpu_aware_env": os.environ.get(
"PECLET_CORE_GPU_AWARE_MPI",
"unset"),
211 "flow_module": os.path.dirname(pf.__file__),
"space": str(getattr(pf,
"execution_space",
"?")),
212 "grid": [NX, NY, NZ],
"tiles": [TX, TY, TZ],
"cells_per_rank": CELLS ** 3,
213 "blocks": ub,
"d_over_h": S,
"bubbles": len(seeds),
"alpha": alpha,
"rtol": RTOL,
214 "levels": LEVELS
if LEVELS
is not None else "default",
215 "comm_avoiding": s.diagnostics.comm_avoiding,
216 "warm": WARM,
"steps": N,
"setup_s": t_setup,
"wall_ms": 1000.0 * wall / N,
217 "step_ms": float(mean_ms[0]),
"timer_step_ms": float(mean_ms[1]),
218 "proj_ms": float(mean_ms[2]),
"momentum_ms": float(mean_ms[3]),
219 "predictor_ms": float(mean_ms[4]),
"allreduce_ms": float(mean_ms[5]),
220 "proj_frac": float(mean_ms[2] / mean_ms[0]),
221 "iters_mean": float(np.mean(iters)),
"iters_min": int(min(iters)),
222 "iters_max": int(max(iters)),
"dt_first": dts[0],
"dt_last": dts[-1],
223 "hash": g.hexdigest(),
226 if isinstance(v, float):
228 return ",".join(map(str, v))
if isinstance(v, list)
else str(v)
229 print(
"RESULT " +
" ".join(f
"{k}={fmt(v)}" for k, v
in res.items()
if k !=
"flow_module"),
232 with open(OUT,
"w")
as fo:
233 json.dump(res, fo, indent=1)
arg(name, default, cast=str)