Skip to content

Add auto parallelization - #356

Draft
max-models wants to merge 14 commits into
develfrom
add-auto-parallelization
Draft

Add auto parallelization#356
max-models wants to merge 14 commits into
develfrom
add-auto-parallelization

Conversation

@max-models

@max-models max-models commented Aug 22, 2026

Copy link
Copy Markdown
Member

Usually, it seems like using (True, True, True) is the most efficient domain decomposition. But sometimes it isn't, for example when the number of elements in some direction is small. With this PR, I am trying out some automatic parallelization strategies. It's still a bit experimental.

The main idea is to run 1 timestep (or a few timesteps?) with a specific configuration, time it, then compare it to other configurations.

What could be automatically chosen?

  • Domain decomposition in each direction.
  • Number of domain clones
  • Particle sorting frequency
  • Sorting-box layout

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces experimental empirical autotuning utilities to help Struphy choose faster parallelization and particle-sorting configurations by timing short workload segments, and wires per-species sorting frequencies into the main simulation loop.

Changes:

  • Add struphy.topology autotuning utilities for integer parameters (including sorting frequency) and for MPI domain-decomposition + clone-count selection.
  • Update Simulation.run() to support per-particle sorting frequencies (with EnvironmentOptions.sort_step as an override).
  • Add unit tests and profiling benchmark scripts/examples to exercise and measure the new tuning helpers.

Reviewed changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/struphy/topology/tests/test_sorting_frequency.py Adds a unit test for empirical sorting-frequency selection.
src/struphy/topology/tests/test_domain_decomposition.py Adds unit tests for mask generation and decomposition/clone optimization.
src/struphy/topology/tests/init.py Declares the topology test package.
src/struphy/topology/domain_decomposition.py New helpers to enumerate and empirically optimize mpi_dims_mask and clone/decomposition combos.
src/struphy/topology/autotuning.py New generic integer-parameter optimizer and ternary-search helper (used for sorting frequency).
src/struphy/topology/init.py Exposes the new topology autotuning API via package exports.
src/struphy/simulation/sim.py Changes particle-sorting logic to support per-particle sorting frequencies and override behavior.
profiling/submit_vlasov_sorting_frequency.py Adds a launcher for the Vlasov sorting-frequency benchmark workflow.
profiling/submit_domain_decomposition.py Adds a launcher for the anisotropic domain-decomposition benchmark workflow.
profiling/examples/Vlasov/clone_decomposition/benchmark_vlasov_clones.py Adds a benchmark comparing clone/decomposition configurations and then tunes sorting frequency.
profiling/examples/ToyGyrokinetic/diocotron_instability/benchmark_domain_decomposition.py Adds a benchmark comparing mpi_dims_mask choices for an anisotropic ToyDrift case.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +771 to +778
for val in particle_objects:
# An explicit EnvironmentOptions.sort_step overrides the
# per-particle SortingParameters frequency. Otherwise,
# honor the frequency configured for this particle species.
frequency = self.env.sort_step or val.sorting_params.sorting_frequency
if frequency and int(self.time_state["index"][0]) % frequency == 0:
particles_to_sort.append(val)
sort_functions.append(val.do_sort)
Comment on lines +128 to +130
timings = tuple(timings_by_value.values())
best = min(timings, key=lambda timing: timing.seconds)
return ParameterOptimization(best_value=best.value, timings=timings)
Comment on lines +176 to +179
mask_pattern
Optional per-direction constraint. Use ``True`` or ``False`` to fix a
direction and ``"auto"`` to let the optimizer vary it, e.g.
``(True, "auto", "auto")``.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants