[mpich-discuss] robust-ifying MPI_File_seek and negative offsets

Jeff Hammond jhammond at alcf.anl.gov
Thu Apr 12 17:00:21 CDT 2012


I believe that casting is the C magic you're looking for here.  Given
http://en.wikipedia.org/wiki/Sizeof#Implementation I do not think
there is anything you can do inside of MPI-IO to rectify an uncast
input.

Jeff

On Thu, Apr 12, 2012 at 3:57 PM, Rob Latham <robl at mcs.anl.gov> wrote:
> 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
> _______________________________________________
> mpich-discuss mailing list     mpich-discuss at mcs.anl.gov
> To manage subscription options or unsubscribe:
> https://lists.mcs.anl.gov/mailman/listinfo/mpich-discuss



-- 
Jeff Hammond
Argonne Leadership Computing Facility
University of Chicago Computation Institute
jhammond at alcf.anl.gov / (630) 252-5381
http://www.linkedin.com/in/jeffhammond
https://wiki.alcf.anl.gov/parts/index.php/User:Jhammond (in-progress)
https://wiki.alcf.anl.gov/old/index.php/User:Jhammond (deprecated)
https://wiki-old.alcf.anl.gov/index.php/User:Jhammond(deprecated)


More information about the mpich-discuss mailing list