Skip to content
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

ParmParse::addfile needs Init #3440

Merged
merged 1 commit into from
Sep 18, 2023

Conversation

ax3l
Copy link
Member

@ax3l ax3l commented Jul 21, 2023

Summary

ParmParse can be used before AMReX is initialized for most functionality, which is greatly helpful for us. One function that cannot be used before init is reading from a file, because it needs an MPI context to broadcast.

Add a clean error message instead of a segfault.

Additional background

cc @EZoni @RevathiJambunathan

Checklist

The proposed changes:

  • fix a bug or incorrect behavior in AMReX
  • add new capabilities to AMReX
  • changes answers in the test suite to more than roundoff level
  • are likely to significantly affect the results of downstream AMReX users
  • include documentation in the code and/or rst files, if appropriate

@WeiqunZhang
Copy link
Member

WeiqunZhang commented Jul 22, 2023

This does not work because amrex::Initialized() does not work during amrex::Initialize(). I think the way to do it is

#ifdef AMREX_USE_MPI
    AMREX_ALWAYS_ASSERT_WITH_MESSAGE(ParallelDescriptor::Communicator() != MPI_COMM_NULL, "error message goes here");
#endif

@ax3l
Copy link
Member Author

ax3l commented Aug 1, 2023

Agreed on the solution - but isn't the issue due to amrex::Error not working if AMReX is not initialized?

Src/Base/AMReX_ParmParse.cpp Outdated Show resolved Hide resolved
Src/Base/AMReX_ParmParse.cpp Outdated Show resolved Hide resolved
Src/Base/AMReX_ParmParse.cpp Outdated Show resolved Hide resolved
Src/Base/AMReX_ParmParse.cpp Outdated Show resolved Hide resolved
Src/Base/AMReX_ParmParse.cpp Outdated Show resolved Hide resolved
@WeiqunZhang
Copy link
Member

That's right. So there are two issues. We cannot call amrex::Initialized() and ParallelDescriptor::Abort() here. So maybe we can do

#ifdef AMREX_USE_MPI
    if (ParallelDescriptor::Communicator() == MPI_COMM_NULL) {
        std::cerr << "......" << std::endl;
        std::abort();
    }
#endif

@ax3l
Copy link
Member Author

ax3l commented Sep 18, 2023

Yes, but I would rather throw an exception.
This error is not fatal and one can recover in interactive contexts if we throw.

`ParmParse` can be used before AMReX is initialized for most
functionality, which is greatly helpful for us. One function that
cannot be used before init is reading from a file, because it needs
an MPI context to broadcast.

Add a clean error message instead of a segfault.
@WeiqunZhang WeiqunZhang enabled auto-merge (squash) September 18, 2023 17:26
@WeiqunZhang WeiqunZhang merged commit ad2a89a into AMReX-Codes:development Sep 18, 2023
66 checks passed
@ax3l ax3l mentioned this pull request Sep 17, 2024
5 tasks
WeiqunZhang pushed a commit that referenced this pull request Sep 18, 2024
## Summary

If a file added via `ParmParse:addFile` does not exist, we did not yet
receive a user-friendly error message. This fixes this in a way that
does not hammer the file system from all MPI ranks.

## Additional background

Follow-up to #2842 #2936 #3440

X-ref: ECP-WarpX/WarpX#5283
ECP-WarpX/impactx#704
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants