Skip to content

amrex::FileStream #4550

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

Draft
wants to merge 12 commits into
base: development
Choose a base branch
from
Draft

Conversation

WeiqunZhang
Copy link
Member

Implement our own file stream class that is somewhat similar to std::fstream. It can be used by amrex::NFilesIter in mesh and particle data I/O. By default amrex::NFilesIter still uses std::fstream. To use amrex::FileStream, one needs to use USE_OWN_FILE_STREAM=TRUE for GNU Make and AMReX_OWN_FILE_STREAM=ON for CMake.

amrex::FileStream::Read has not been tested and currently it is not being used for reading MultiFab and particles.

@WeiqunZhang WeiqunZhang requested a review from BenWibking July 4, 2025 02:28
This tries to fix the following error reported by @BenWibking

    Writing checkpoint chk02500
    amrex::UtilCreateDirectory:: path errno:  chk02500 :: File exists
    amrex::UtilCreateDirectory:: path errno:  chk02500/Level_2 :: Input/output error
    amrex::Error::0::Couldn't create directory: chk02500/Level_2 !!!
Implement our own file stream class that is somewhat similar to
std::fstream. It can be used by amrex::NFilesIter in mesh and particle data
I/O. By default amrex::NFilesIter still uses std::fstream. To use
amrex::FileStream, one needs to use `USE_OWN_FILE_STREAM=TRUE` for GNU Make
and `AMReX_OWN_FILE_STREAM=ON` for CMake.

amrex::FileStream::Read has not been tested and currently it is not being
used for reading MultiFab and particles.
throw std::runtime_error("FileStream::write: bad file descriptor or bad state");
}

if (m_buffer_mode == BufferMode::Read) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From a quick skim of the code, I don't really understand the motivation for BufferMode or how it works. Is there a reason to have separate modes implemented by the same function, or can different modes have separate implementations in separate functions? I can go back and read it more carefully with more context.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently we only need to open a stream for either write or read, but not both. If we want to support both, we will need to know the current mode of the buffer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants