Archives


- Beowulf
- Beowulf Announce
- Scyld-users
- Beowulf on Debian

[Beowulf] Stupid MPI programming question

Many of your questions may have already been answered in earlier discussions or in the FAQ. The search results page will indicate current discussions as well as past list serves, articles, and papers.

Search

Vincent Diepeveen diep at xs4all.nl
Thu Sep 28 06:54:08 PDT 2006


----- Original Message ----- 
From: "Joe Landman" <landman at scalableinformatics.com>
To: "Clements, Brent M (SAIC)" <brent.clements at bp.com>
Cc: <beowulf at beowulf.org>
Sent: Thursday, September 28, 2006 2:34 AM
Subject: Re: [Beowulf] Stupid MPI programming question


> 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.

If we move to C++ then you have more ways to mess up,
but also methods similar to the above.

Actually in C it would be

#include <string.h>
..

char mystring[1024];
strcpy(mystring,"some test");



>>
>> MPI_Bcast(&mystring, sizeof(basedir), MPI_CHAR, MASTER_RANK,
>> MPI_COMM_WORLD);
>
> 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
> http://course.scalableinformatics.com/lectures/lecture-5/lecture-5.pdf
> around page 62 for an example with BCast and Send/Recv pairs.  The files
> for this lecture are in
> http://course.scalableinformatics.com/lectures/lecture-5/source/
>
>>
>> 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
> above.
>
> Joe
>
> -- 
> 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