[mpich-discuss] MPI_C_BOOL and bool

Torquil Macdonald Sørensen torquil at gmail.com
Fri Apr 8 13:13:50 CDT 2011


Ah, I see... Good to know. Much appreciated, Dave!

Thanks!
Torquil Sørensen

On Friday 08 April 2011 20:01:00 Dave Goodell wrote:
> You are misunderstanding the usage of "sizeof" and what MPI datatype
> handles are.  "MPI_C_BOOL" is a constant of type "MPI_Datatype", which is
> a typedef for "int" (4 bytes on most platforms).  However the type that
> "MPI_C_BOOL" is describing is C's "_Bool" type (available as "bool" when
> "stdbool.h" is included), which is typically 1 byte large.
> 
> In order to check the size of the data described by an MPI datatype, you
> should use the "MPI_Type_size" routine.
> 
> Also, the blog entry that you pointed out refers to the size in the
> "external32" representation rather than some sort of hard-coded size for
> the type in general.  Virtually nobody on Earth actually is affected by
> that last minute change, so I wouldn't worry about it.
> 
> -Dave
> 
> On Apr 8, 2011, at 11:40 AM CDT, Torquil Macdonald Sørensen wrote:
> > Hi all!
> > 
> > In my MPICH2 program, sizeof(MPI_C_BOOL) returns 4.
> > 
> > On the other hand, sizeof(bool) returns 1.
> > 
> > Does that mean that the following might result in a segfault?:
> > 
> > bool buf = false;
> > MPI_Bcast(&buf, 1, MPI_C_BOOL, 0, MPI_COMM_WORLD);
> > 
> > After all, MPICH then writes a 4 byte amount of data to the buffer, for
> > which only 1 byte is allocated. I'm using MPICH2 1.4rc1 at the moment.
> > 
> > I came over this message regarding the MPI2.2 standard:
> > 
> > http://www.unixer.de/blog/index.php/2009/07/30/the-mpi-standard-mpi-22-is
> > - fixed-now/
> > 
> > where it seems to be explained that MPI_C_BOOL is 4 bytes due to some
> > kind of oversight, and that it will be changed in an errata to the
> > MPI2.2 standard.
> > 
> > In conclusion, does all this mean that I cannot use 'bool' and MPI_C_BOOL
> > together until sometime in the future?
> > 
> > Thanks!
> > Torquil Sørensen
> > _______________________________________________
> > mpich-discuss mailing list
> > mpich-discuss at mcs.anl.gov
> > https://lists.mcs.anl.gov/mailman/listinfo/mpich-discuss
> 
> _______________________________________________
> mpich-discuss mailing list
> mpich-discuss at mcs.anl.gov
> https://lists.mcs.anl.gov/mailman/listinfo/mpich-discuss


More information about the mpich-discuss mailing list