On Fri, 21 May 2004, Ligia M. Mateiu wrote:
> Does somebody has any nice idea for broadcasting a c++ string?
There's several options here -- I think that this may have been discussed
on this mailing list before...? You might want to search through the
archives and see.
In short, MPI only sends *data*. C++ class instances are unfortunately a
bit more than just plain data. There are two main options:
1. Send two messages; the first with a single int containing the lenght of
the string, and a second message with the string itself (e.g.,
my_string.c_str()).
2. Send just one message (my_string.c_str()), and have the receiver post a
large receive -- with a buffer/size that you can guarantee will be bigger
than any string that will be sent. This works because MPI allows you to
receive fewer bytes than you asked for (but receiving more bytes than you
asked for is a truncation error).
Hope that helps.
--
{+} Jeff Squyres
{+} jsquyres_at_[hidden]
{+} http://www.lam-mpi.org/
|