我无法让MPI在MacBook Pro上运行。特别是,当我尝试调用MPI_Comm_rank()时,它会出现段错误。这是一个示例程序:
#include "mpi.h"
#include <iostream>
int main(int argc, char *argv[]) {
std::cout << "Entered main\n";
// Initialize parallel
int rank, numProcess;
MPI_Status status;
MPI_Init(&argc, &argv);
std::cout << "Init\n";
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
std::cout << "Rank\n";
MPI_Comm_size(MPI_COMM_WORLD, &numProcess);
std::cout << "Initialized MPI; rank " << rank << "\n";
MPI_Finalize();
return 0;
}
使用
mpic++ mpi_test.cpp -o mpi_test
可以正常编译,但是随后我尝试通过调用mpirun -np 2 ./mpi_test
来运行它,并得到以下错误:Entered main
Entered main
Init
Init
[Bens-MacBook-Pro:22004] *** Process received signal ***
[Bens-MacBook-Pro:22004] Signal: Segmentation fault: 11 (11)
[Bens-MacBook-Pro:22004] Signal code: Address not mapped (1)
[Bens-MacBook-Pro:22004] Failing at address: 0x10000004c
[Bens-MacBook-Pro:22004] [ 0] 0 libsystem_platform.dylib 0x00007fffc0118b3a _sigtramp + 26
[Bens-MacBook-Pro:22004] [ 1] 0 ??? 0x0000000113f92978 0x0 + 4630063480
[Bens-MacBook-Pro:22004] [ 2] 0 mpi_test 0x00000001078e40d1 main + 81
[Bens-MacBook-Pro:22004] [ 3] 0 libdyld.dylib 0x00007fffbff09235 start + 1
[Bens-MacBook-Pro:22004] *** End of error message ***
[Bens-MacBook-Pro:22005] *** Process received signal ***
[Bens-MacBook-Pro:22005] Signal: Segmentation fault: 11 (11)
[Bens-MacBook-Pro:22005] Signal code: Address not mapped (1)
[Bens-MacBook-Pro:22005] Failing at address: 0x10000004c
[Bens-MacBook-Pro:22005] [ 0] 0 libsystem_platform.dylib 0x00007fffc0118b3a _sigtramp + 26
[Bens-MacBook-Pro:22005] [ 1] 0 ??? 0x000000004fc26c50 0x0 + 1338141776
[Bens-MacBook-Pro:22005] [ 2] 0 mpi_test 0x000000010ffd90d1 main + 81
[Bens-MacBook-Pro:22005] [ 3] 0 libdyld.dylib 0x00007fffbff09235 start + 1
[Bens-MacBook-Pro:22005] [ 4] 0 ??? 0x0000000000000001 0x0 + 1
[Bens-MacBook-Pro:22005] *** End of error message ***
-------------------------------------------------------
Primary job terminated normally, but 1 process returned
a non-zero exit code. Per user-direction, the job has been aborted.
-------------------------------------------------------
--------------------------------------------------------------------------
mpirun noticed that process rank 1 with PID 0 on node Bens-MacBook-Pro exited on signal 11 (Segmentation fault: 11).
--------------------------------------------------------------------------
请注意,它经过MPI_Init(),但在MPI_Comm()中失败。
当我(i)从git下载最新的OpenMpi库并直接安装它,以及(ii)通过brew安装OpenMPI时,出现了相同的错误。
最佳答案
该问题似乎是由于$ PATH中的OpenMPI版本冲突。当我重置$ PATH变量并专门使用brew安装进行编译和运行时,一切正常。那时,我从设备上卸载并删除了所有mpi库,然后重新安装并链接了brew版本。现在一切正常。以防万一其他人发帖。
关于c++ - 使用brew,git或内置mpi的MPI_Comm_rank()中的MPI Seg错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48573602/