OpenMPI分段故障:未映射的地址

时间:2017-06-11 10:51:21

标签: c mpi openmpi

在开发基于OpenMPI的程序期间,我有时会遇到分段错误:

[11655] *** Process received signal ***
[11655] Signal: Segmentation fault (11)
[11655] Signal code: Address not mapped (1)
[11655] Failing at address: 0x10
[11655] [ 0] /usr/lib/libpthread.so.0(+0x11940)[0x7fe42b159940]
[11655] [ 1] /usr/lib/openmpi/openmpi/mca_btl_vader.so(mca_btl_vader_alloc+0xde)[0x7fe41e94717e]
[11655] [ 2] /usr/lib/openmpi/openmpi/mca_btl_vader.so(mca_btl_vader_sendi+0x22d)[0x7fe41e949c5d]
[11655] [ 3] /usr/lib/openmpi/openmpi/mca_pml_ob1.so(+0x806f)[0x7fe41e30806f]
[11655] [ 4] /usr/lib/openmpi/openmpi/mca_pml_ob1.so(mca_pml_ob1_send+0x3d9)[0x7fe41e308f29]
[11655] [ 5] /usr/lib/openmpi/libmpi.so.12(MPI_Send+0x11c)[0x7fe42b3df1cc]
[11655] [ 6] project[0x400e41]
[11655] [ 7] project[0x401429]
[11655] [ 8] project[0x400cdc]
[11655] [ 9] /usr/lib/libc.so.6(__libc_start_main+0xea)[0x7fe42adc343a]
[11655] [10] project[0x400b3a]
[11655] *** End of error message ***
[11670] *** Process received signal ***
[11670] Signal: Segmentation fault (11)
[11670] Signal code: Address not mapped (1)
[11670] Failing at address: 0x1ede1f0
[11670] [ 0] /usr/lib/libpthread.so.0(+0x11940)[0x7fc5f8c13940]
[11670] [ 1] /usr/lib/openmpi/openmpi/mca_btl_vader.so(mca_btl_vader_poll_handle_frag+0x14c)[0x7fc5ec458aac]
[11670] [ 2] /usr/lib/openmpi/openmpi/mca_btl_vader.so(+0x3c9e)[0x7fc5ec458c9e]
[11670] [ 3] /usr/lib/openmpi/libopen-pal.so.13(opal_progress+0x4a)[0x7fc5f836814a]
[11670] [ 4] /usr/lib/openmpi/openmpi/mca_pml_ob1.so(mca_pml_ob1_recv+0x255)[0x7fc5ebe171c5]
[11670] [ 5] /usr/lib/openmpi/libmpi.so.12(MPI_Recv+0x190)[0x7fc5f8e917d0]
[11670] [ 6] project[0x400d94]
[11670] [ 7] project[0x400e8a]
[11670] [ 8] /usr/lib/libpthread.so.0(+0x7297)[0x7fc5f8c09297]
[11670] [ 9] /usr/lib/libc.so.6(clone+0x3f)[0x7fc5f894a25f]

从这些消息中,我认为我使用MPI_Send和(对应?)MPI_Recv时出现了一些错误。我使用这样的包装器:

void mpi_send(int *buf, int to, int tag) {
    int msg[2];
    msg[0] = l_clock++;
    msg[1] = *buf;
    MPI_Send(msg, 2, MPI_INT, to, tag, MPI_COMM_WORLD);
}

int mpi_rcv(int *buf, int source, int tag, MPI_Status *status) {
    int msg[2];
    MPI_Recv(msg, 2, MPI_INT, source, tag, MPI_COMM_WORLD, status);
    int r_clock = msg[0];
    *buf = msg[1];

    if (r_clock > l_clock) {
        l_clock = r_clock + 1;
        return 1;
    }
    if (r_clock == l_clock) {
        return rank < status->MPI_SOURCE;
    }
    return 0;
}

此处托管完整代码。

我看不出我在这里犯的错误。任何帮助将不胜感激。

编辑: 现在我注意到,段错误有时会提到MPI_Barrier。这对我来说完全没有意义。这是否意味着我的OpenMPI实现有问题?我正在使用Manjaro Linux和openmpi,它来自arm额外的存储库。

1 个答案:

答案 0 :(得分:4)

堆栈跟踪中有第二个线程,暗示在线程程序中使用MPI。快速查看完整代码即可确认。为了在这种情况下使用MPI,必须通过调用MPI_Init_thread()而不是MPI_Init()来正确初始化MPI。如果您想同时从不同的线程进行多个MPI调用,则传递给MPI_Init_thread的线程级别应为MPI_THREAD_MULTIPLE

int provided;
MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE, &provided);
if (provided < MPI_THREAD_MULTIPLE) {
   // Error - MPI does not provide needed threading level
}

任何低于provided的线程级别(在MPI_THREAD_MULTIPLE中返回)都不会对您的情况有效。

支持MPI_THREAD_MULTIPLE是Open MPI中的构建时选项。检查Manjaro包是否已相应编译。 Arch Linux中的那个不是:

$ ompi_info
...
     Thread support: posix (MPI_THREAD_MULTIPLE: no, OPAL support: yes,
                            ^^^^^^^^^^^^^^^^^^^^^^^
                     OMPI progress: no, ORTE progress: yes, Event lib:
                     yes)
...

您可能需要从源代码构建Open MPI并启用对MPI_THREAD_MULTIPLE的支持。