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

Actually tell why file read fails #51

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions vlsv_reader_parallel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,8 @@ namespace vlsv {
* @param mpiInfo Additional MPI info for optimizing file I/O. Must be the same value on all processes.
* @return If true, VLSV file was opened successfully. All processes return the same value.*/
bool ParallelReader::open(const std::string& fname,MPI_Comm comm,const int& masterRank,MPI_Info mpiInfo) {
bool success = true;
bool success {true};
int error {MPI_SUCCESS};
this->comm = comm;
this->masterRank = masterRank;
MPI_Comm_rank(comm,&myRank);
Expand All @@ -430,10 +431,13 @@ namespace vlsv {
// Attempt to open the given input file using MPI:
fileName = fname;
int accessMode = MPI_MODE_RDONLY;
if (MPI_File_open(comm,const_cast<char*>(fileName.c_str()),accessMode,mpiInfo,&filePtr) != MPI_SUCCESS) success = false;
else parallelFileOpen = true;

if (success == false) cerr << "Failed to open parallel file" << endl;
error = MPI_File_open(comm,const_cast<char*>(fileName.c_str()),accessMode,mpiInfo,&filePtr);
if (error == MPI_SUCCESS) {
parallelFileOpen = true;
} else {
success = false;
cerr << "Failed to open parallel file with MPI error " << error << endl;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this now a number, or some string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's an int. I suppose the proper way would be to have a function mapping error codes to descriptions of MPI errors but now it at least doesn't just gobble up the error code and spit out the non-answer of "there was an error".

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah that tracks, just needs a whopper to convert that from C-string to something sensible.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can't that be plonked to cerr? Or to a stringstreamstream and then that gets cerr'ed?

Copy link
Contributor Author

@lkotipal lkotipal Dec 4, 2023

Choose a reason for hiding this comment

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

Look at the function signature, the actual string "returned" is an argument. So the conversion is sth like:

char c[MPI_MAX_ERROR_STRING];
int len;
MPI_Error_string(err, c, &len);
std::string s (s, len);

}

// Only master process reads file footer and endianness. This is done using
// VLSVReader open() member function:
Expand Down