[Beowulf] Stupid MPI programming question

Joe Landman landman at scalableinformatics.com
Wed Sep 27 21:34:46 EDT 2006

Hi Brent

Clements, Brent M (SAIC) wrote:
> Hey Guys,
> I've been sitting here working for the past 48 hours and I'm fighting
> a stupid bug in some mpi code I'm working on
> How do I broadcast a char string to my slave mpi processes? And how
> do I receive that char string and print it out on my slave mpi
> process.
> This is what I have in my code(some things have been removed)
> #define MASTER_RANK 0
> char* mystring;

Hmmm....  This makes *mystring a string (ok, a character array), and
mystring a pointer to a character array.

> mystring = "some test";

ok ... I haven't played with "strings" recently in C, though I seem to
remember needing a "\0" at the end.  RGB is more likely a C language
guru/lawyer than I am, I don't remember off the top of my head if this
is strictly necessary.

> MPI_Bcast(&mystring, sizeof(basedir), MPI_CHAR, MASTER_RANK,

Lets put on our parser hat.  The first argument is

	pointer to (pointer to mystring)

mystring is a pointer, *mystring is the (technically) first character in
the array, and &mystring is a pointer to mystring, which is a pointer to
a pointer to the first character in the array.

Ok, if you want to see more of this sort of detail, have a look at
around page 62 for an example with BCast and Send/Recv pairs.  The files
for this lecture are in

> in my slave process code I have this
> printf("my string I received: %s", mystring);
> Am I doing something wrong? Or if someone has some sample code they
> can point me to on how to send a string to a slave mpi process and
> have that slave mpi process print out the string..that would be even
> better. That way..I relearn MPI basics 101

Lots of tutorials on the net, my course and material are up on the net


Joseph Landman, Ph.D
Founder and CEO
Scalable Informatics LLC,
email: landman at scalableinformatics.com
web  : http://www.scalableinformatics.com
phone: +1 734 786 8423
fax  : +1 734 786 8452 or +1 866 888 3112
cell : +1 734 612 4615
Beowulf mailing list, Beowulf at beowulf.org
To change your subscription (digest mode or unsubscribe) visit http://www.beowulf.org/mailman/listinfo/beowulf

More information about the Beowulf mailing list