Skip to content

[LinearSystem] Contributions to the global matrix in the order of the scene graph traversal - #6426

Open
fredroy wants to merge 5 commits into
sofa-framework:masterfrom
fredroy:deterministic_matrix_assembly
Open

fredroy wants to merge 5 commits into
sofa-framework:masterfrom
fredroy:deterministic_matrix_assembly

Conversation

@fredroy

@fredroy fredroy commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Fix

Before, the containers of the components (and of the pairs of mechanical states) of the assembly were ordered by addresses
Now they are ordered by the paths of the components in the scene graph, thus allowing deterministic results
(really poor results)

Now the contributions follow the order of the scene graph traversal:
- IndependentContributors stores vectors filled by visiting m_forceFields, m_masses and m_mechanicalMappings (collected in traversal order)
- the shared mapped matrices are created, and projected, in the order in which their pair of mechanical states is first encountered
- the duplicated mechanical states of a component are removed without sorting them by address

EDIT: add the benchmark scene

[with-all-tests]


By submitting this pull request, I acknowledge that
I have read, understand, and agree SOFA Developer Certificate of Origin (DCO).


Reviewers will merge this pull-request only if

  • it builds with SUCCESS for all platforms on the CI.
  • it does not generate new warnings.
  • it does not generate new unit test failures.
  • it does not generate new scene test failures.
  • it does not break API compatibility.
  • it is more than 1 week old (or has fast-merge label).

@fredroy
fredroy requested a review from alxbilger October 20, 2026 23:04
@fredroy fredroy added pr: fix Fix a bug pr: status to review To notify reviewers to review this pull-request pr: AI-aided Label notifying the reviewers that part or all of the PR has been generated with the help of an AI labels Oct 20, 2026
@fredroy
fredroy force-pushed the deterministic_matrix_assembly branch from 26c651a to 82d7d3c Compare October 21, 2026 00:56

@alxbilger alxbilger 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.

The only concern is the loss of performances. Otherwise 👍

@fredroy

fredroy commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor Author

The only concern is the loss of performances. Otherwise 👍

You were right to be concerned, with a specially crafted scene (long graph depth and very long path name)

master: 200 iterations done in 7.45178 s ( 26.8392 FPS)
PR with paths: 200 iterations done in 438.29 s ( 0.456319 FPS).
😅

@fredroy
fredroy force-pushed the deterministic_matrix_assembly branch from b9f3f8c to af9d2fd Compare October 28, 2026 01:30
@fredroy

fredroy commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

The only concern is the loss of performances. Otherwise 👍

You were right to be concerned, with a specially crafted scene (long graph depth and very long path name)

master: 200 iterations done in 7.45178 s ( 26.8392 FPS) PR with paths: 200 iterations done in 438.29 s ( 0.456319 FPS). 😅

PR with new containers: 200 iterations done in 7.01615 s ( 28.5056 FPS).

@fredroy fredroy added the pr: based on previous PR PR based on a previous PR, therefore to be merged ONLY subsequently label Oct 28, 2026
@fredroy fredroy changed the title [LinearSystem] Contributions to the global matrix in the order of the paths of the components [LinearSystem] Contributions to the global matrix in the order of the scene graph traversal Oct 28, 2026
fredroy and others added 5 commits October 30, 2026 15:49
…of the components

The force fields are allocated in an order and added to the scene graph in
the reverse order, so that the expected order (the scene graph) differs from
the order of their addresses.
… scene graph

Before, the contributors of the assembly were iterated in the order of the
std::map containing them, i.e. ordered by addresses: the rounding of the sums
of contributions to the same entries depended on where the components were
allocated, which changes from one run to another.

Now the contributions follow the order of the scene graph traversal:
- IndependentContributors stores vectors filled by visiting m_forceFields,
  m_masses and m_mechanicalMappings (collected in traversal order)
- the shared mapped matrices are created, and projected, in the order in which
  their pair of mechanical states is first encountered
- the duplicated mechanical states of a component are removed without sorting
  them by address

The containers used for lookups are still keyed by pointers.
Co-authored-by: Hugo <hugo.talbot@sofa-framework.org>
@fredroy
fredroy force-pushed the deterministic_matrix_assembly branch from cb554f5 to 033a103 Compare October 30, 2026 06:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: AI-aided Label notifying the reviewers that part or all of the PR has been generated with the help of an AI pr: based on previous PR PR based on a previous PR, therefore to be merged ONLY subsequently pr: fix Fix a bug pr: status to review To notify reviewers to review this pull-request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants