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
Allow external initialization of MPI and p4est #14884
base: master
Are you sure you want to change the base?
Conversation
One thing I would like to add to the discussion is the fact that @sloede and @ranocha have first thought we might completely skip using Lines 780 to 828 in 03e8a82
Lines 963 to 999 in 03e8a82
|
The goal of xSDK is to be able to compile all the libraries together. That's it. Another solution would be to create a new class that only initializes/finalizes deal.II and let the user take care of initializing all the libraries they need. The advantage is that the code would be more clean (we don't have |
|
I agree, that would be awkward. So that makes me lean towards a different class/struct to collect the infrastructure needed by deal.II proper (maybe including Kokkos, maybe not), and let everything else like PETSc, p4est, MPI be handled by the user? |
Agreed. Something like |
@kronbichler yes, I like it better. I would let the user initialize Kokkos. When using the bundled version of Kokkos, we only enable the serial backend. So not only we don't need the code that Daniel added but you don't need to initialize Kokkos yourself (we safely do it for you). It's only when using OpenMP or a GPU backend that you need to do something special. If users are compiling their own Kokkos, we can let them initialize Kokkos themselves. |
I agree that the new initialization function shouldn't initialize |
I've followed the discussion here with great interest.
From a research software engineering perspective, this makes sense to me too. However, I have to admit that I am completely out of my depth with the proposed new approach, thus I am afraid I will not be able to implement this myself. I'd be happy to test drive an implementation from someone else for our application though, to give a user's perspective. |
How about a class Then the old |
AssertThrow(MPI_has_been_started == 0, | ||
ExcMessage("MPI error. You can only start MPI once!")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why you need to require an extra flag allow_external_initialization
. For example, the PETSc/SLEPC part can be initalized outside of this function and deal.ii does not complain. What is different for MPI?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently in master
, deal.II does not allow MPI to be initialized outside of deal.II:
Lines 753 to 757 in 3c37cfe
int MPI_has_been_started = 0; | |
ierr = MPI_Initialized(&MPI_has_been_started); | |
AssertThrowMPI(ierr); | |
AssertThrow(MPI_has_been_started == 0, | |
ExcMessage("MPI error. You can only start MPI once!")); |
I thus assumed that the design goals for this function were that any abnormal usage by the user should result in a fast and hard failure, even though in this case it would have been possible to, e.g., first check the current thread level and see if it is sufficient for deal.II. This makes sense to me - I have used the same approach many times before, assuming that if anything is happening out of the ordinary, the user should probably be informed immediately instead of potentially running an expensive simulation and failing after a couple of hours.
My approach in this PR was therefore motivated by wanting to keep this strict safety against user errors as the default. I therefore made them set a flag explicitly, which indicates to deal.II "I know what I'm doing" but also provides the feedback to the users "if you had to set a flag for this, you're probably in dragon land now".
However, I am not a regular committer to deal.II, so everything I wrote was based only on assumptions. I'd be more than happy to make this work without a flag, if this is so desired. However, from the convo in this PR, I already got the feeling that a very different approach is to be followed for allowing external initialization, so I don't know if this question will not be rendered moot anyway.
@@ -834,9 +844,19 @@ namespace Utilities | |||
// MPI_Comm_create_group (see cburstedde/p4est#30). | |||
// Disabling it leads to more verbose p4est error messages | |||
// which should be fine. | |||
sc_init(MPI_COMM_WORLD, 0, 0, nullptr, SC_LP_SILENT); | |||
if (sc_package_id >= 0 && allow_external_initialization) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
How do we want to proceed with this PR? Did #15572 address at least some parts of what you wanted to do? |
This PR allows some packages, namely MPI and p4est, to be initialized (and finalized) externally. That is, in the constructor for
Utilities::MPI_InitFinalize
, either library is only initialized if it has not already been initialized before. For consistency, if external initialization was detected, finalization in the destructor is also omitted.The motivation for this proposed change is a joint project with @kronbichler and @ranocha, where we use deal.II as a library and not as the main driver of a simulation. Since MPI and p4est are already initialized when deal.II is loaded, we need to be able to switch off the automatic initialization of third-party libraries.
An optional function parameter is added to the constructor of
Utilities::MPI_InitFinalize
that enables the new behavior. By default, everything remains as is, i.e., for existing codes nothing should change and, e.g., an already initialized MPI library will cause an error to be thrown as before.Please note that I am not an expert on the inner workings of deal.II, and that thus there might be smarter ways to achieve the same effect. Therefore, please view this PR not necessarily as the best possible implementation but rather as a means to get the discussion started.