C++ mpi hello world上的valgrind seg故障

C++ mpi hello world上的valgrind seg故障,c++,mpi,valgrind,C++,Mpi,Valgrind,我将valgrind应用于一个非常简单的MPI程序时出现seg故障: #include "mpi.h" #include <iostream> #include<stdio.h> #include<stdlib.h> int main(int argc, char *argv[]) { // Initialize parallel int rank, numProcess; MPI_Status status; MPI_Ini

我将valgrind应用于一个非常简单的MPI程序时出现seg故障:

#include "mpi.h"
#include <iostream>
#include<stdio.h>
#include<stdlib.h>

int main(int argc, char *argv[])
{
    // Initialize parallel
    int rank, numProcess;
    MPI_Status status;
    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &numProcess);

    std::cout << "Hello world, - Rank " << rank << "\n";

    MPI_Finalize();
    return 0;
}

我怀疑Valgrind和您的操作系统可能有问题

因为我可以在Linux上编译和运行您的程序而不会出现任何问题:

tb-xps ../tmp$ mpicxx -o h2 h2.cpp
tb-xps ../tmp$ mpirun -n 1 ./h2
Hello world, - Rank 0
tb-xps ../tmp$ mpirun -n 1 valgrind ./h2
==3544== Memcheck, a memory error detector
==3544== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==3544== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==3544== Command: ./h2
==3544== 
==3544== Thread 3:
==3544== Syscall param epoll_pwait(sigmask) points to unaddressable byte(s)
==3544==    at 0x5F5AFE6: epoll_pwait (in /usr/lib/libc-2.26.so)
==3544==    by 0x6536DDC: ??? (in /usr/lib/openmpi/libopen-pal.so.40.0.0)
==3544==    by 0x653AEDA: opal_libevent2022_event_base_loop (in /usr/lib/openmpi/libopen-pal.so.40.0.0)
==3544==    by 0x90CA0CE: ??? (in /usr/lib/openmpi/openmpi/mca_pmix_pmix2x.so)
==3544==    by 0x5C4E08B: start_thread (in /usr/lib/libpthread-2.26.so)
==3544==    by 0x5F5AE7E: clone (in /usr/lib/libc-2.26.so)
==3544==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
==3544== 
Hello world, - Rank 0
==3544== 
==3544== HEAP SUMMARY:
==3544==     in use at exit: 1,899 bytes in 44 blocks
==3544==   total heap usage: 17,910 allocs, 17,866 frees, 3,993,061 bytes allocated
==3544== 
==3544== LEAK SUMMARY:
==3544==    definitely lost: 372 bytes in 4 blocks
==3544==    indirectly lost: 1,288 bytes in 34 blocks
==3544==      possibly lost: 0 bytes in 0 blocks
==3544==    still reachable: 239 bytes in 6 blocks
==3544==         suppressed: 0 bytes in 0 blocks
==3544== Rerun with --leak-check=full to see details of leaked memory
==3544== 
==3544== For counts of detected and suppressed errors, rerun with: -v
==3544== ERROR SUMMARY: 39 errors from 1 contexts (suppressed: 0 from 0)
tb-xps ../tmp$ uname -a
Linux tb-xps 4.15.3-1-ARCH #1 SMP PREEMPT Mon Feb 12 23:01:17 UTC 2018 x86_64 GNU/Linux

也因为我不是C++程序员,我会去掉IoShand,只使用PrimTf,我也会重新排列我的包含并添加一些空白:

#include <stdio.h>
#include <stdlib.h>
#include <mpi.h> 

您有权使用其他机器吗?你能问一下Valgrind邮件列表吗?

include/usr/local/include/mpi.h哎哟,真的吗?在我看来,这只是不兼容。@LightnessRacesinOrbit我不懂?包括路径以确保我使用的mpi.h与我的mpi编译器兼容。它实际上是指向brew安装它的/usr/local/cillar的指针。就兼容性而言,valgrind是否仅与某些类型的mpi编译器兼容,或者您指的是其他类型的编译器?在include指令中编写绝对路径是非常单调的,会使您的程序具有较短的保存期限。如果您需要一个非标准的include路径,那么您应该在编译命令中传递-I/usr/local/cillar,并像往常一样包含mpi.h。mpi方法是包含并使用mpi{cc,cpc,fort}包装器,这样您就不必担心include和library路径,也不必担心应该链接哪个库。是的,我在集群上成功地编译并运行了它,您让它工作了,所以它对我的机器来说非常特殊。将尝试删除邮件列表。
#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>