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
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 8 additions & 0 deletions vlsv_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <mpi.h>

#include "vlsv_common.h"

Expand Down Expand Up @@ -152,5 +153,12 @@ namespace vlsv {
break;
}
}

const std::string getMPIErrorString(const int err) {
char s[MPI_MAX_ERROR_STRING];
int len;
MPI_Error_string(err, s, &len);
return std::string(s, len);
}

} // namespace vlsv
2 changes: 2 additions & 0 deletions vlsv_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ namespace vlsv {
double convReal8(const char* const ptr,const bool& swapEndian=false);

std::string printDataRate(const uint64_t& bytes,const double& t);

const std::string getMPIErrorString(const int err);
} // namespace vlsv

#endif
17 changes: 11 additions & 6 deletions vlsv_reader_parallel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ 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};
this->comm = comm;
this->masterRank = masterRank;
MPI_Comm_rank(comm,&myRank);
Expand All @@ -430,10 +430,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;
int err {MPI_File_open(comm,const_cast<char*>(fileName.c_str()),accessMode,mpiInfo,&filePtr)};
Copy link
Contributor

Choose a reason for hiding this comment

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

"While valid, this is stupid." :) Initializers do have their uses but let's be realistic, here it's just odd. (TBH is odd also on line 420 since it's just a single variable)

if (err == MPI_SUCCESS) {
parallelFileOpen = true;
} else {
success = false;
cerr << "Failed to open parallel file with MPI error " << getMPIErrorString(err) << endl;
}

// Only master process reads file footer and endianness. This is done using
// VLSVReader open() member function:
Expand Down Expand Up @@ -512,7 +515,9 @@ namespace vlsv {
}

MPI_Status status;
if (MPI_File_read_at_all(filePtr,start+counter*maxBytes,pos,readSize,MPI_BYTE,&status) != MPI_SUCCESS) {
int err {MPI_File_read_at_all(filePtr,start+counter*maxBytes,pos,readSize,MPI_BYTE,&status)};
if (err != MPI_SUCCESS) {
cerr << "Failed to read data with MPI error " << getMPIErrorString(err) << endl;
success = false;
}

Expand Down
30 changes: 23 additions & 7 deletions vlsv_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,14 @@ namespace vlsv {
// possibly caused by MPI_File_delete call, that's the reason for the barrier.
int accessMode = (MPI_MODE_WRONLY | MPI_MODE_CREATE);
if (dryRunning == false) {
if (myrank == masterRank && append == false) MPI_File_delete(const_cast<char*>(fname.c_str()),mpiInfo);
if (myrank == masterRank && append == false) {
MPI_File_delete(const_cast<char*>(fname.c_str()),mpiInfo);
}
MPI_Barrier(comm);
if (MPI_File_open(comm,const_cast<char*>(fileName.c_str()),accessMode,mpiInfo,&fileptr) != MPI_SUCCESS) {
int err {MPI_File_open(comm,const_cast<char*>(fileName.c_str()),accessMode,mpiInfo,&fileptr)};
if (err != MPI_SUCCESS) {
fileOpen = false;
cerr << "Failed to open parallel file with MPI error " << getMPIErrorString(err) << endl;
return fileOpen;
}
}
Expand Down Expand Up @@ -311,8 +315,16 @@ namespace vlsv {
ptr[0] = detectEndianness();
const double t_start = MPI_Wtime();
if (dryRunning == false) {
if (MPI_File_write_at(fileptr,0,&endianness,1,MPI_Type<uint64_t>(),MPI_STATUS_IGNORE) != MPI_SUCCESS) success = false;
if (MPI_File_write_at(fileptr,8,&endianness,1,MPI_Type<uint64_t>(),MPI_STATUS_IGNORE) != MPI_SUCCESS) success = false;
int err {MPI_File_write_at(fileptr,0,&endianness,1,MPI_Type<uint64_t>(),MPI_STATUS_IGNORE)};
if (err != MPI_SUCCESS) {
cerr << "Failed to write endianness MPI error " << getMPIErrorString(err) << endl;
success = false;
}
err = MPI_File_write_at(fileptr,8,&endianness,1,MPI_Type<uint64_t>(),MPI_STATUS_IGNORE);
if (err != MPI_SUCCESS) {
cerr << "Failed to write endianness MPI error " << getMPIErrorString(err) << endl;
success = false;
}
}
writeTime += (MPI_Wtime() - t_start);
offset += 2*sizeof(uint64_t); //only master rank keeps a running count
Expand Down Expand Up @@ -344,9 +356,13 @@ namespace vlsv {
* @param newSize New size.
* @return If true, output file was successfully resized.*/
bool Writer::setSize(MPI_Offset newSize) {
int rvalue = MPI_File_set_size(fileptr,newSize);
if (rvalue == MPI_SUCCESS) return true;
return false;
int err = MPI_File_set_size(fileptr,newSize);
if (err != MPI_SUCCESS) {
cerr << "Failed to resize output with MPI error " << getMPIErrorString(err) << endl;
return false;
} else {
return true;
}
}

/** Start dry run mode. In this mode no file I/O is performed, but getBytesWritten()
Expand Down