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: User-Friendly Error #4156

Merged
merged 2 commits into from
Sep 18, 2024

Conversation

ax3l
Copy link
Member

@ax3l ax3l commented Sep 17, 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

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

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.
@WeiqunZhang
Copy link
Member

I thought it's going to say something like Couldn't open file: xxxx. Is that a python thing that the error message gets lost? Or is it you want ParmParse::addFile to be explicitly mentioned (instead of looking it up in Backtrace files)?

Anyway there is a function called amrex::FileExists that you can use. Also do we need bcast the information and print on all processes? If the I/O process aborts, it will abort other processes too.

@WeiqunZhang
Copy link
Member

So it could just

if (ParallelDescriptor::IOProcessor()) {
    AMREX_ALWAYS_ASSERT_WITH_MESSAGE(FileExists(filename), "xxxxxx");
}

@ax3l
Copy link
Member Author

ax3l commented Sep 18, 2024

Thanks! Yes the error message I got so far looks not as clean as it could be.

If we do the check & abort inside an if(IOProc) then technically another MPI process could front-run the check and maybe obfuscate the error message again at scale (or even trigger abort before the clear error messsage is thrown). The BCast is a bit safer... What do you think?

@AlexanderSinn
Copy link
Member

To prevent other errors later, a barrier should be enough.

@WeiqunZhang
Copy link
Member

There is already a barrier after this in reading and bcast the file, which also produce Couldn't open file: xxxx if I/O fails.

@WeiqunZhang
Copy link
Member

My point is the fewer lines of code, the better, unless the code is hard to read.

@WeiqunZhang WeiqunZhang merged commit 6c7668c into AMReX-Codes:development Sep 18, 2024
59 checks passed
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.

3 participants