问题描述
我试图将 2 个数组从我的主进程传递给从属进程。问题是当我通过数组时,我在里面得到了垃圾。有什么我不明白的地方?
master 之外的声明:
int how_much_word[2];
char file_name_and_number_words[2][50];
在 master 中,数组 file_name_and_number_words 由“mytext2.txt”和“mytext.txt”填充。 所以主站以这种方式在从站以 1 级发送这 2 个数组:
for (int tmp = 1; tmp<world_size;tmp++){
MPI_Send(file_name_and_number_words,2,MPI_CHAR,tmp,MPI_COMM_WORLD);
MPI_Send(how_much_word,MPI_INT,1,MPI_COMM_WORLD);
}
slave 是这样接收的:
MPI_Recv(file_name_and_number_words,MPI_COMM_WORLD,&status);
MPI_Recv(how_much_word,&status);
如果我尝试打印:file_name_and_number_words[0] 输出是:“my”,如果我打印 file_name_and_number_words 输出是:“�����b��>�6�9`”,我认为这是一个垃圾内存区。但错误在哪里?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)