nvalchemi.distributed.system_sum#
- nvalchemi.distributed.system_sum(vals, idx, n, scope=Scope.OWNED)[source]#
Sum per-node values into per-system totals, without double-counting.
Each rank holds neighbor copies of atoms it does not own, so a plain
scatter_addover all rows would over-count. This sums only this rank’s owned rows and (forScope.OWNED) all-reduces across the mesh to the true global per-system total. In single-process it is a plainscatter_addover all rows.Under compile it masks the ghost / dead rows by the routing’s n_owned tensor (a tensor mask, not a dynamic slice, so the partition can drift without forcing a recompile) and reduces over all rows. A wrapper calls it the same way in both modes.
- Parameters:
vals (torch.Tensor) –
(n_rows, *F)per-node values with owned rows first.idx (torch.Tensor) –
(n_rows,)integer system index for each row, in[0, n).n (int) – Number of systems in the (global) batch.
scope (Scope, default
Scope.OWNED) –OWNED→ owned-only sum + cross-rank all-reduce (global total on every rank).LOCAL→ this rank’s owned-only partial with no all-reduce (the framework’s output consolidation finishes it).
- Returns:
(n, *F)per-system totals (replicated on every rank forOWNED; a per-rank partial forLOCAL).- Return type: