[mpich-discuss] robust-ifying MPI_File_seek and negative offsets
Rob Latham
robl at mcs.anl.gov
Thu Apr 12 15:57:12 CDT 2012
Just spent a bit of time figuring out why an application was seeking
to a seemingly random spot in a file.
consider a big endian platform with a 32 bit integer and a 64 bit
MPI_Offset (did you guess bluegene? you win!)
This results in MPI_File_seek to a nonsense location:
MPI_File_seek(fd, -sizeof(int), MPI_SEEK_END);
Even though MPI_File_seek is prototyped to take an MPI_Offset, it
looks like the '-sizeof(int)' math is resulting in a sign-extended
number that is then jammed into 8 bytes. Instead of '-4' we get
4309034244.
Some casting makes it seek to the correct location:
MPI_File_seek(fd, -((MPI_Offset)sizeof(int)), MPI_SEEK_END);
Is there some C magic I don't know about that will make the compiler
properly handle '-sizeof(int)' ? The next time someone tries to "seek
backwards by 5 integers" into a file, I don't want them running into
this.
==rob
--
Rob Latham
Mathematics and Computer Science Division
Argonne National Lab, IL USA
More information about the mpich-discuss
mailing list