Created
December 3, 2020 18:52
-
-
Save davetaflin/8841e22ad9cd7584249e613cadd3ea2f to your computer and use it in GitHub Desktop.
OpenMPI apparent bug in MPI_File_seek() using MPI_SEEK_END
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <mpi.h> | |
#include <string> | |
#include <vector> | |
#define DATA_SIZE (0x100000 + 20) | |
int main(int argc, char* argv[]) | |
{ | |
MPI_Init(&argc, &argv); | |
int commRank; | |
MPI_Comm_rank(MPI_COMM_WORLD, &commRank); | |
int commSize; | |
MPI_Comm_size(MPI_COMM_WORLD, &commSize); | |
MPI_File fileHandle; | |
MPI_File_open(MPI_COMM_WORLD, "fileseekbug.out", MPI_MODE_CREATE | MPI_MODE_WRONLY, MPI_INFO_NULL, &fileHandle); | |
MPI_Offset mpiOffset = (commRank - 1) * DATA_SIZE; | |
if (commRank == 0) | |
mpiOffset = (commSize - 1) * DATA_SIZE; | |
std::vector<char> data(DATA_SIZE, 0); | |
data[DATA_SIZE - 1] = 0x01; | |
MPI_File_seek(fileHandle, mpiOffset, MPI_SEEK_SET); | |
MPI_File_write(fileHandle, reinterpret_cast<void const*>(&data.front()), static_cast<int>(data.size()), MPI_CHAR, MPI_STATUS_IGNORE); | |
if (commRank == 0) | |
{ | |
#if defined THIS_WORKS | |
MPI_File_get_size(fileHandle, &mpiOffset); | |
MPI_File_seek(fileHandle, mpiOffset, MPI_SEEK_SET); | |
#else // This doesn't work: | |
mpiOffset = 0; | |
MPI_File_seek(fileHandle, mpiOffset, MPI_SEEK_END); | |
#endif | |
std::string message("This should be at the end of the file"); | |
MPI_File_write(fileHandle, reinterpret_cast<void const*>(message.c_str()), static_cast<int>(message.size() + 1), MPI_CHAR, MPI_STATUS_IGNORE); | |
} | |
MPI_File_close(&fileHandle); | |
MPI_Finalize(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run the sample code with 4 MPI ranks to demonstrate the bug. The output file should consist of all zeros except for a 1 at the end of each rank's data block, and the end of the file should have the message "This should be at the end of the file" The observed behavior is that the message is written to file position 0x400000, which is not the end of the file. This behavior was observed on Ubuntu 20.04 LTS with GCC 9.3.0, with both OpenMPI 3.1.5 and 4.0.5.