Properly serialize particle managers and generators. - #7099
Conversation
|
Part of #6744. |
| = Utilities::MPI::this_mpi_process(this->get_mpi_communicator()); | ||
|
|
||
| AssertThrow(rank_states.size() == n_processes, | ||
| ExcMessage("The number of MPI processes used to resume the " |
There was a problem hiding this comment.
Help me understand: does that mean we no longer support resuming with different number of ranks?
There was a problem hiding this comment.
With the current version of the patch that's correct. That's why I don't like it as it stands. We need one of the two solutions at the end of this post.
|
I apologize for not reading the whole pr description beforehand. I am fine with the current approach and would opt for simply not restoring the state if the number of ranks changes. This is not a problem because the simulation will be different regardless when running with a different number of ranks. |
|
would you be ok restoring the ability to resume with different number of ranks (even if random state is not restored)? |
|
Yes, I should have marked this as WIP. This was meant for discussion, not for merging. |
|
Let me close this. It's not the way I want to go. |
This is a difficult one, and it took me quite a lot of tokens to find and fix, and then brainpower to understand and revise. The key issue here is that the particle manager only saves the
ParticleHandlerclass during serialization. But it doesn't save the following:This patch addresses this, but the underlying issue is actually more complicated.
At its root, the issue is that we call the serialization functionality on all processes, but we only store the information on process zero. I don't recall the exact thought processes that led to this design decision, but I think that fundamentally it was about this:
All of this gets in trouble if you have a random number generator, for example for particle generation. In fact, the particle generation base class already provides a random number generator for all of its derived classes to use (see also #7097). The issue here is that on different ranks, we may be calling the random number generator a different number of times, and so the state of the RNG may be different on different ranks. If we really want to save the state of the simulator, we have to save the state from all ranks. That's what Copilot came up with: It collects the state from all ranks to rank zero, and saves that whole array. When we resume, each process picks its state out of the array and restores from that.
I'm not excited about this approach. I think memory is ok, since if we have many processes, we also have many solution vector elements to store and the addition of the state of an RNG per rank isn't going to make a difference. But it destroys our ability to restart with a different number of processes. This is in conflict with our goal that a resumed process results in exactly the same answer as the original process (which requires saving the state from all processes).
I can see two solutions here, neither of which is implemented in the current patch:
Thoughts?
Before your first pull request:
For all pull requests:
For new features/models or changes of existing features: