Skip to content

ParmParse::addfile needs Init#3440

Merged
WeiqunZhang merged 1 commit intoAMReX-Codes:developmentfrom
ax3l:topic-amrex-addfile-init
Sep 18, 2023
Merged

ParmParse::addfile needs Init#3440
WeiqunZhang merged 1 commit intoAMReX-Codes:developmentfrom
ax3l:topic-amrex-addfile-init

Conversation

@ax3l
Copy link
Copy Markdown
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

@ax3l ax3l force-pushed the topic-amrex-addfile-init branch from aa4fd0c to 452a29b Compare July 21, 2023 21:26
@WeiqunZhang
Copy link
Copy Markdown
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
Copy Markdown
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?

@WeiqunZhang
Copy link
Copy Markdown
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
Copy Markdown
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.
@ax3l ax3l force-pushed the topic-amrex-addfile-init branch from 12d93dc to fced9ea Compare September 18, 2023 16:23
@WeiqunZhang WeiqunZhang enabled auto-merge (squash) September 18, 2023 17:26
@WeiqunZhang WeiqunZhang merged commit ad2a89a into AMReX-Codes:development Sep 18, 2023
@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: BLAST-WarpX/warpx#5283
BLAST-ImpactX/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