diff --git a/GenericIO.cxx b/GenericIO.cxx index 0d31bae4d213aad9b773a0a4a2727222f8630377..eb1fb18314881dc6c996990d1e6c1a486453ea74 100644 --- a/GenericIO.cxx +++ b/GenericIO.cxx @@ -122,8 +122,10 @@ void GenericFileIO_MPI::write(const void *buf, size_t count, off_t offset, if (MPI_File_write_at(FH, offset, (void *) buf, count, MPI_BYTE, &status) != MPI_SUCCESS) throw runtime_error("Unable to write " + D + " to file: " + FileName); - int scount; - (void) MPI_Get_count(&status, MPI_BYTE, &scount); + int scount = 0; + // On some systems, MPI_Get_count will not return zero even when count is zero. + if (count > 0) + (void) MPI_Get_count(&status, MPI_BYTE, &scount); count -= scount; buf = ((char *) buf) + scount; @@ -140,8 +142,10 @@ void GenericFileIO_MPICollective::read(void *buf, size_t count, off_t offset, if (MPI_File_read_at_all(FH, offset, buf, count, MPI_BYTE, &status) != MPI_SUCCESS) throw runtime_error("Unable to read " + D + " from file: " + FileName); - int scount; - (void) MPI_Get_count(&status, MPI_BYTE, &scount); + int scount = 0; + // On some systems, MPI_Get_count will not return zero even when count is zero. + if (count > 0) + (void) MPI_Get_count(&status, MPI_BYTE, &scount); count -= scount; buf = ((char *) buf) + scount;