Open MPI logo

Open MPI User's Mailing List Archives

  |   Home   |   Support   |   FAQ   |   all Open MPI User's mailing list

Subject: Re: [OMPI users] Missmatch between sent and recieved data
From: Alexey Sokolov (gabbear_at_[hidden])
Date: 2009-07-27 07:11:33


Hi, Prasadcse and Jody.

Eeeh, the answer was on the top and it's name is my own inattention.

Thank you for pointing it out and for your spent time. Gonna be more
attentive next time.

Alexey.

On Mon, 2009-07-27 at 16:25 +0530, Prasadcse Perera wrote:
> Hi Alexey,
> I tried the same line of codes in my free time and what I could see is
> that when you perform strcpy the string was copied with '/0' but
> since you only receive 4 characters it can only receive the 'asdf'
> but not '/0' which seems a bit strange in the nature. I think this is
> because the MPI_Send/Recev isn't defined to send and recieve 'strings'
> but only character buffers. So when you recieve the buffer only with
> 'asdf' printf tends to print asdf + some garbage characters since
> theres no termination for the string (I also saw +3 garbage
> charactors :)). So the solution is to make sure you send strlen() + 1
> and recieve strlen() + 1. If you arent sure about the receiving
> length, do a MPI_Probe and allocate the necessary buffer. So its
> really important to have enough space in the send buffer to hold the
> "asdf' which is strlen('asdf') + 1, and on the receive side, recieve
> from a strlen('asdf') + 1 buffer. I guess this is the difference of
> sending character buffers from sending 'strings' using MPI_Send/Recv.
> Correct me someone if I'm wrong!
> PS: I think reboot is just a trick that won't yeild to a solution :).
>
> On Mon, Jul 27, 2009 at 1:43 PM, jody <jody.xha_at_[hidden]> wrote:
> Hi Alexey
> No, strlen() does not include the '\0' - this is what 'man
> strlen' says:
>
> STRLEN(3) Linux Programmer’s Manual
> STRLEN(3)
>
> NAME
> strlen - calculate the length of a string
>
> SYNOPSIS
> #include <string.h>
>
> size_t strlen(const char *s);
>
> DESCRIPTION
> The strlen() function calculates the length
> of the
> string s, not
> including the terminating ’\0’ character.
>
> RETURN VALUE
> The strlen() function returns the number of
> characters in s.
>
> If your code worked after reboot, you were just lucky that a
> 0-character
> followed our string. The problem may appear again anytime if
> you don't
> increase your message length to strlen(chdata[i])+1.
>
> Jody
>
>
>
>
> On Mon, Jul 27, 2009 at 9:57 AM, Alexey
> Sokolov<gabbear_at_[hidden]> wrote:
> > Hi
> >
> > Thank you for advising, but my problem disappeared after
> rebooting as it
> > has never been. I really don't know why it was in this way,
> but I didn't
> > change anything and now it works correctly. May be it was
> connected with
> > system update without rebooting after it (I use Fedora 10),
> don't truly
> > know.
> >
> > Anyway thank you for your help and paying me attention.
> >
> > PS: I typed you a little bit wrong code. In the original
> code i get the
> > string length with strlen(chdata[i]), so the null-terminator
> should be
> > counted.
> >
> > Sincerely yours, Alexey.
> >
> > On Fri, 2009-07-24 at 16:47 +0200, Dorian Krause wrote:
> >> Hi,
> >>
> >> you do not send the trailing '0' which is used to determine
> the
> >> stringlength. I assume that chdata[i] has at least length 5
> (otherwise
> >> you overrun your memory). Replace the "4" by "5" in
> MPI_Isend and
> >> MPI_Recv and everything should work (If I get the problem
> right).
> >>
> >> Dorian.
> >>
> >>
> >> Alexey Sokolov wrote:
> >> > Hi
> >> >
> >> > I'm sorry if the answer to my question is very simple,
> but I'm really
> >> > confused with this situation.
> >> >
> >> > I got a program that now contains 1 master and 1 slave
> processes. Master
> >> > process sends few similar chars to the slave process with
> this:
> >> >
> >> > for (unsigned i = 0; i < SomeVariable; i++) {
> >> > strcpy(chdata[i], "asdf");
> >> > MPI_Isend(chdata[i], 4, MPI_CHAR, SLAVE, 1,
> MPI_COMM_WORLD,
> >> > &req[i]);
> >> > }
> >> >
> >> > And the slave process receives them with this:
> >> >
> >> > for (unsigned i = 0; i < SomeVariable; i++) {
> >> > char * buf = new char[10];
> >> > MPI_Recv(buf, 4, MPI_CHAR, MASTER, 1,
> MPI_COMM_WORLD, &stat);
> >> > printf("Received data [%s] of length %d\n",
> buf, strlen(buf));
> >> > }
> >> >
> >> > As I understand output should be "Received data [asdf] of
> length 4", but
> >> > instead of this I got my 'asdf' with additional 3 random
> ANSI characters
> >> > in string of length 7.
> >> >
> >> > I've already spent few hours to find the mistake out but
> unsuccessfully.
> >> > I do successfully transfer int data in the similar way,
> but this case
> >> > make me crazy. Could you help me to find out where did I
> fail in this?
> >> >
> >> > Sincerely yours, Alexey.
> >> >
> >> > _______________________________________________
> >> > users mailing list
> >> > users_at_[hidden]
> >> > http://www.open-mpi.org/mailman/listinfo.cgi/users
> >> >
> >> >
> >>
> >> _______________________________________________
> >> users mailing list
> >> users_at_[hidden]
> >> http://www.open-mpi.org/mailman/listinfo.cgi/users
> >
> > _______________________________________________
> > users mailing list
> > users_at_[hidden]
> > http://www.open-mpi.org/mailman/listinfo.cgi/users
> >
>
> _______________________________________________
> users mailing list
> users_at_[hidden]
> http://www.open-mpi.org/mailman/listinfo.cgi/users
>
>
>
>
> --
> http://www.codeproject.com/script/Articles/MemberArticles.aspx?amid=3489381
> _______________________________________________
> users mailing list
> users_at_[hidden]
> http://www.open-mpi.org/mailman/listinfo.cgi/users