Skip to content

Iterate over GhostingFunctor* in vectors, not sets #4213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: devel
Choose a base branch
from

Conversation

roystgnr
Copy link
Member

It's entirely fair for GhostingFunctor subclasses to want to do parallel operations in e.g. mesh_reinit(), but we can't do that if they're not executed in the same order on all processors, and a set of pointers is definitely not guaranteed to be in the same order on all processors.

I think I may have actually fixed this bug before anyone got bitten by it (while investigating other issues, though).

This is technically an API change, but hopefully everybody uses "auto" for any ugly iterators that they have to declare, in which case this won't be an API change that breaks anyone's compile.

It's entirely fair for GhostingFunctor subclasses to want to do parallel
operations in e.g. mesh_reinit(), but we can't do that if they're not
executed in the same order on all processors, and a set of pointers
is definitely not guaranteed to be in the same order on all processors.

I think I may have actually fixed this bug before anyone got bitten by
it (while investigating other issues, though).

This is technically an API change, but hopefully everybody uses "auto"
for any ugly iterators that they have to declare, in which case this
won't be an API change that breaks anyone's compile.
@roystgnr roystgnr force-pushed the vector_gf_containers branch from 7ef74b8 to d7a753c Compare July 15, 2025 23:29
@moosebuild
Copy link

moosebuild commented Jul 16, 2025

Job Coverage, step Generate coverage on 600f950 wanted to post the following:

Coverage

5868ff #4213 600f95
Total Total +/- New
Rate 64.28% 64.29% +0.01% 100.00%
Hits 75108 75133 +25 40
Misses 41736 41736 - 0

Diff coverage report

Full coverage report

This comment will be updated on new commits.

@jwpeterson
Copy link
Member

I think I'm OK with the API change, however I would like to get a coupon for one free future API change of mine to be redeemed later 😆

Any idea if the MOOSE test failures here are real/actually due to this PR?

[1.303s]     FAIL dgkernels/2d_diffusion_dg.proper_ghosting_with_action_serial FAILED (CRASH)
[1.835s]     FAIL dgkernels/2d_diffusion_dg.proper_ghosting_with_action_parallel FAILED (CRASH) [min_cpus=2]

@jwpeterson
Copy link
Member

BTW, would it make sense to put a public typedef on MeshBase like:

typedef std::vector<GhostingFunctor *>::const_iterator GhostingFunctorIterator;

This would give people something to use in cases where it's not possible to use auto, and would also make the next diff smaller in case it changes to a std::list or something in the future.

@roystgnr
Copy link
Member Author

The failures are definitely real - using set was automatically correcting double-insertions, and MOOSE was depending on that in more than one code path. I'm going to restore support for that behavior.

If I can find all the other points where MOOSE was depending on that support, then I'll mark the revised support for it as deprecated for now, but if not then I'll just leave it supported indefinitely. Supporting it with vector instead of set gets us from O(log(N)) to O(N), but here N is the tiny number of ghosting functors and we're already unavoidably O(N*N_elem) when we actually query ghosting functors elsewhere.

I thought about adding that typedef but decided to be lazy. Thanks for calling me on it; my superego now feels vindicated and my id chastened.

Comment on lines 2038 to 2041
_coupling_functors.erase
(std::remove(_coupling_functors.begin(),
_coupling_functors.end(),
&coupling_functor));
Copy link
Member

Choose a reason for hiding this comment

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

std::vector::erase(pos) erases only the element at pos... are you trying to erase all the elements that get std::removed here?

https://en.cppreference.com/w/cpp/container/vector/erase.html

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.

3 participants