0

I am just simply trying to scatter some strings to nodes and then receive them back in a new array. When I print the new array the terminal will output

    name1
    (empty line) 
    (empty line)
    (empty line)

Here is my scatter:

    std::string files[4] = {"name1", "name2", "name3", "name4"};
    std::string recArr[4];


    MPI_Scatter(files, 5, MPI_CHAR, recArr, 5, MPI_CHAR, 0, world);


    for(int i = 0; i < 4; i++) std::cout << recArr[i]  << "\n";

1 Answers1

0

The problem is that you're only sending the first 5 characters of your array. Remember than an MPI_CHAR is not the same thing as a string. You have to pass in a character array and tell MPI how many characters are in the array. Add up the lengths of all of the strings and try again.

Wesley Bland
  • 8,816
  • 3
  • 44
  • 59
  • My thought was I had to specify how many characters each string object was for it to be properly sent to each process. –  Mar 15 '14 at 16:29
  • No, you're specifying how many of the specified datatype you'll be sending. You said you're sending `MPI_CHAR`s so MPI will end `count` `MPI_CHAR`s. You can find out more here: http://stackoverflow.com/questions/20620421/how-to-send-and-recieve-string-using-mpi – Wesley Bland Mar 15 '14 at 16:31