问题
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:
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.
来源:https://stackoverflow.com/questions/22425207/mpi-scatter-only-sending-first-element