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

Rob Latham robl at mcs.anl.gov
Fri Apr 13 13:38:12 CDT 2012


On Fri, Apr 13, 2012 at 07:58:14AM -0500, Jed Brown wrote:
> $ gcc -Wall -Wextra b.c && ./a.out
> sizeof((unsigned char)4)=1      sizeof(-(unsigned char)4)=4     value as
> long=-4
> sizeof((unsigned short)4)=2     sizeof(-(unsigned short)4)=4    value as
> long=-4
> sizeof((unsigned int)4)=4       sizeof(-(unsigned int)4)=4      value as
> long=4294967292
> sizeof((unsigned long)4)=8      sizeof(-(unsigned long)4)=8     value as
> long=-4
> sizeof((unsigned long long)4)=8 sizeof(-(unsigned long long)4)=8
>  value as long=-4
> 
> If you want consistent results across sizes, be sure that the argument to
> unary - is always signed.

Jed, this is a fantastic level of detail.  Thanks.  

It sounds like there's no way I, as MPI implementor, can prevent users
from potentially passing in a bogus result.  

I was hoping there was a preprocessor magic, a directive or even a
pragma that would catch this sort of problem (seeking backwards is a
not uncommon operation) and handle the types and sign extensions
correctly.

I guess if I want to make this dummy-proof the only way to do so is
define two new 'whence' flags: MPI_SEEK_CUR_BACKWARDS and
MPI_SEEK_END_BACKWARDS which only take positive offsets.  Ok, well,
that's not going to happen.

Instead, let's just hope the next person who has this problem googles
"MPI_File_seek with negative offset" and finds this thread.

==rob


-- 
Rob Latham
Mathematics and Computer Science Division
Argonne National Lab, IL USA


More information about the mpich-discuss mailing list