MPI Scatter仅发送第一个元素 [英] MPI Scatter only sending first element

查看:175
本文介绍了MPI Scatter仅发送第一个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是简单地尝试将一些字符串散布到节点上,然后以新数组的形式接收它们.当我打印新数组时,终端将输出

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)

这是我的分散信息:

    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";

推荐答案

问题是您只发送数组的前5个字符.请记住,MPI_CHAR与字符串不是同一回事.您必须传递一个字符数组,并告诉MPI数组中有多少个字符.累加所有字符串的长度,然后重试.

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.

这篇关于MPI Scatter仅发送第一个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆