用c++ MPI发送字符串

Sending a string in C++ MPI

本文关键字:字符串 MPI c++      更新时间:2023-10-16

TL;DR我认为我用MPI_Send错误地传输了一个字符串。发送字符串的最佳方式是什么?


我正在尝试从主进程发送一个字符串到从进程,但我认为它没有发送整个字符串或没有在从端正确地重建它。

主MPI_Send码:

MPI_Send(&parent, sizeof(char) * selection::target_length(), MPI_BYTE, i, MSEND, MPI_COMM_WORLD);

Slave MPI_Recv Code:

char parentChars [selection::target_length()];
MPI_Recv(&parentChars, sizeof(char) * selection::target_length(), MPI_BYTE, 0, MSEND, MPI_COMM_WORLD, &status);
parent = parentChars;

断言assert(target.length() == candidate.length());失败并给出以下结果:

weasel: weaselparallel.cpp:34: static int selection::fitness(std::string): Assertion `target.length() == candidate.length()' failed.

↑这是每个从属进程的输出

然后是分割错误我认为是由于错误传输字符串导致的:

mpiexec noticed that process rank 2 with PID 23531 on node node02.emperor exited on signal 11 (Segmentation fault).
6 total processes killed (some possibly by mpiexec during cleanup)
  • 检查MPI_Send和MPI_Recv的定义,我认为有问题
  • 尝试省略&符号(&)
  • 还检查从MPI_Recv返回的状态(特别是MPI_ERROR),以获得有关正在发生的事情的更多信息