Sorry for the delay in replying; I was out last week.
MPI_SEND and MPI_RECV take pointers to the buffer to send and receive, respectively.
When you send a scalar variable, like an int, you get the address of the buffer via the & operator (e.g., MPI_Send(&i, ...)). When you send a new'ed/malloc'ed array, you only need to send the pointer value -- i.e., the address pointing to the buffer. Don't send the address of the pointer, because then you're telling MPI to overwrite the pointer itself. I.e.,:
work = new char[...];
MPI_Send(work, ...)
not
work = new char[...];
MPI_Send(&work, ...);
More below.
On Apr 11, 2012, at 3:03 PM, Peter Sels wrote:
> Probably a buffer overrun or so, but I cannot see where.
The buffer overrun is where you specify &array in your MPI_SEND/MPI_RECV calls.
> On linux I get: Segmentation fault (11)
>
> Increasing the length gives more problems...
>
> How can I get this code stable?
> What am I doing wrong?
> Is there a maximum length to MPI messages?
No.
> For sending a string, do I use MPI_CHARACTER or MPI_BYTE or ...?
MPI_BYTE. MPI_CHARACTER is for Fortran CHARACTERs.
> How come I cannot assert that my messages end in '\0' when received?
> And how come that when I print them, I also get a segmentation fault?
I think these two issues are symptoms of (work) vs. (&work), from above.
> Can I send two subsequent messages using MPI_Send, or do I have to do
Sure.
> the first as MPI_Isend and then do a MPI_Wait before the next
> MPI_Send?...
You can do multiple Isend's and then a Waitall, if you want.
> Why do I not find code online for receiving the length first and then
> allocating a buffer of this size and then receiving the next message?
I don't know. Perhaps you didn't google enough? :-)
FWIW, the new MPI-3 functions MPI_MPROBE and MPI_IMPROBE will help with unknown-length messages, too. We have that implemented on the Open MPI SVN trunk, but they are not yet available in a stable release. They'll debut in OMPI v1.7.
--
Jeff Squyres
jsquyres_at_[hidden]
For corporate legal information go to: http://www.cisco.com/web/about/doing_business/legal/cri/
|