Consider the following simple program which writes the rank of all processes whos rank is bigger than zero into a file:
#include <mpi.h>
int main() {
MPI_Init(NULL, NULL);
int world_rank, world_size;
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
MPI_Offset offset;
MPI_Status status;
MPI_File fh;
MPI_File_open(MPI_COMM_WORLD, "myfile", MPI_MODE_CREATE | MPI_MODE_WRONLY,
MPI_INFO_NULL, &fh);
offset = world_rank * sizeof(int);
if (world_rank > 0) {
MPI_File_write_at(fh, offset, &world_rank, 1, MPI_INT, &status);
}
MPI_File_close(&fh);
MPI_Finalize();
return 0;
}
we compiled and run it on 4 processes
mpic++ main.cpp
mpirun --oversubscribe -n 4 a.out
We check the written file with hexdump -C myfile
00000000 00 00 00 00 01 00 00 00 02 00 00 00 03 00 00 00 |................|
00000010
Now, I never made a write call to the first integer aka the first 4 bytes but they are zero.
Can I be sure that those are always zero?