c - MPI_Bcast 分段故障 139

标签 c mpi

我正在尝试 MPI_Bcast 将消息广播到多个节点,但遇到段错误,有时错误:139 或错误:255。以下是我的代码:

char proposal[20];
char rep;
int size, rank;
printf("1\n");
//Initialization
MPI_Init(&argc, &argv);

printf("init\n");
//Getting size and rank of processes
MPI_Comm_size(MPI_COMM_WORLD, &size);
printf("abc\n");
MPI_Comm_rank(MPI_COMM_WORLD, &rank);

printf("2\n");
//Proposal message for root node
if(rank == 0)
{
    printf("string copy\n");
    strcpy("Choose a or b\n", proposal);
}

printf("3\n");
//Broadcasting message
MPI_Bcast(proposal, 20, MPI_CHAR, 0, MPI_COMM_WORLD);
printf("broadcast\n");
printf("%s", proposal);

如果我能得到任何帮助,我将不胜感激。

最佳答案

strcpy 第一个参数是目标,第二个参数是源。你把它颠倒过来了。

关于c - MPI_Bcast 分段故障 139,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35656277/

相关文章:

mpi - 我可以在 Windows 7 Visual Studio 2010 中的非 GPU 计算机上运行 MPI 应用程序吗?

c - 通过 system() C/C+ 将 mpi 等级传递给 bash 脚本;奇怪的错误

c - C 语言中的 OpenMP + MPI 混合 - 编译困难

C NDK ndk-build 无法识别 header 错误 : undefined reference to 'cpBBTreeNew'

c - 为什么 pango_cairo_show_layout 在稍微错误的位置绘制文本?

c - 每次左子树遍历打印出 '0',每次右子树遍历打印出 '1'

c - 替代 LD_PRELOAD 或 LD_LIBRARY_PATH

c - 清理代码的最佳命令行工具是什么?

c++ - 有没有办法用详细的缓存/CPU 效率信息来分析 MPI 程序?

c - 如何使用 iso_c_binding 将 MPI 通信器句柄从 Fortran 传递到 C