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<gabb...@niir.ru> 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
>> > us...@open-mpi.org
>> > http://www.open-mpi.org/mailman/listinfo.cgi/users
>> >
>> >
>>
>> _______________________________________________
>> users mailing list
>> us...@open-mpi.org
>> http://www.open-mpi.org/mailman/listinfo.cgi/users
>
> _______________________________________________
> users mailing list
> us...@open-mpi.org
> http://www.open-mpi.org/mailman/listinfo.cgi/users
>

Reply via email to