MPI Scatter only sending first element

十年热恋 提交于 2020-01-06 14:07:51

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!