Hi Jeffrey,

Thanks a lot for answering my message.
The &work io work thing escaped my attention.
(Usually the compiler catches these things but of course here any
pointer type should work.
I suppose with C++ MPI it's possible to enforce more strict type
checking using template or so.)

Anyway in the meantime I rewrote everything without this mistake, but still
wasn't aware of it.
Everything works as expected now.

thanks,

Peter

On 17 April 2012 22:15, Jeffrey Squyres <jsquy...@cisco.com> wrote:
> 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
> jsquy...@cisco.com
> For corporate legal information go to: 
> http://www.cisco.com/web/about/doing_business/legal/cri/
>
>
> _______________________________________________
> users mailing list
> us...@open-mpi.org
> http://www.open-mpi.org/mailman/listinfo.cgi/users



-- 
Peter Sels
www.LogicallyYours.com

Reply via email to