我在小型 Raspberry PI 集群上工作,我的主机程序创建 IP 数据包片段并将它们发送到多个中继程序。中继接收这些数据包片段并使用原始套接字将它们转发到目的地。由于原始套接字,我的中继程序必须在 sudo 权限下运行。我的设置涉及 RPi 3 B v2 和 RPi 2 B v1。 SSH 已经设置好,节点可以在没有密码的情况下通过 SSH 登录,尽管我必须在每个节点上运行 ssh-agent 和 ssh-add 我的 key 。我已经设法运行从一个节点到另一个节点(2 个不同的 RPis)发送等级的程序。我以 MPMD 方式运行 MPI 程序,因为我只有 2 个 RPis,我在节点 #1 上运行主机和中继,并在节点 #2 上中继。主机程序将文件路径作为命令行参数发送。
如果我运行:
mpirun --oversubscribe -n 1 --host localhost /home/pi/Desktop/host /some.jpeg : -n 2 --host localhost,rpi2 /home/pi/Desktop/relay
它运行了,但显然程序失败了,因为中继无法在没有 sudo 许可的情况下打开原始套接字。
如果我运行:
mpirun --oversubscribe -n 1 --host localhost /home/pi/Desktop/host /some.jpeg : -n 2 --host localhost,rpi2 sudo /home/pi/Desktop/relay
中继报告世界大小:1 并且宿主程序挂起。
如果我运行:
mpirun --oversubscribe -n 1 --host localhost sudo /home/pi/Desktop/host /some.jpeg : -n 2 --host localhost,rpi2 sudo /home/pi/Desktop/relay
所有中继和主机报告世界大小 1。
我在这里发现了类似的问题:OpenMPI / mpirun or mpiexec with sudo permission
在我运行的简短回答之后:
mpirun --oversubscribe -n 1 --host localhost /home/pi/Desktop/host /some.jpeg : -n 2 --host localhost,rpi2 sudo -E /home/pi/Desktop/relay
结果是:
[raspberrypi:00979] OPAL ERROR: Unreachable in file ext2x_client.c at line 109
[raspberrypi:00980] OPAL ERROR: Unreachable in file ext2x_client.c at line 109
*** An error occurred in MPI_Init
*** An error occurred in MPI_Init
*** on a NULL communicator
*** MPI_ERRORS_ARE_FATAL (processes in this communicator will now abort,
*** and potentially your MPI job)
[raspberrypi:00979] Local abort before MPI_INIT completed completed successfully, but am not able to aggregate error messages, and not able to guarantee that all other processes were killed!
*** on a NULL communicator
*** MPI_ERRORS_ARE_FATAL (processes in this communicator will now abort,
*** and potentially your MPI job)
[raspberrypi:00980] Local abort before MPI_INIT completed completed successfully, but am not able to aggregate error messages, and not able to guarantee that all other processes were killed!
--------------------------------------------------------------------------
Primary job terminated normally, but 1 process returned
a non-zero exit code. Per user-direction, the job has been aborted.
--------------------------------------------------------------------------
--------------------------------------------------------------------------
mpirun detected that one or more processes exited with non-zero status, thus causing
the job to be terminated. The first process to do so was:
Process name: [[32582,1],1]
Exit code: 1
--------------------------------------------------------------------------
我运行了 sudo visudo,我在两个节点上的文件如下所示:
# User privilege specification
root ALL=(ALL:ALL) ALL
pi ALL = NOPASSWD:SETENV: /etc/alternatives/mpirun
pi ALL=NOPASSWD:SETENV: /usr/bin/orterun
pi ALL=NOPASSWD:SETENV: /usr/bin/mpirun
当我在一个节点上运行所有东西时,它就可以正常工作:
sudo mpirun --alow-run-as-root --oversubscribe -n 1 --host localhost/home/pi/Desktop/host/some.jpeg : -n 2 --host localhost,localhost/主页/pi/桌面/中继
//主机
int main(int argc, char *argv[]) {
MPI_Init(&argc, &argv);
int world_size = []() {
int size;
MPI_Comm_size(MPI_COMM_WORLD, &size);
return size;
}();
int id = []() {
int id;
MPI_Comm_rank(MPI_COMM_WORLD, &id);
return id;
}();
if (argc != 2) {
std::cerr << "Filepath not passed\n";
MPI_Finalize();
return 0;
}
const std::filesystem::path filepath(argv[1]);
if (not std::filesystem::exists(filepath)) {
std::cerr << "File doesn't exist\n";
MPI_Finalize();
return 0;
}
std::cout << "World size: " << world_size << '\n';
MPI_Finalize();
return 0;
}
//relay
int main(int argc, char *argv[]) {
MPI_Init(&argc, &argv);
int world_size = []() {
int size;
MPI_Comm_size(MPI_COMM_WORLD, &size);
return size;
}();
int id = []() {
int id;
MPI_Comm_rank(MPI_COMM_WORLD, &id);
return id;
}();
std::cout << "World size: " << world_size << '\n';
MPI_Finalize();
return 0;
}
如何配置节点以允许它们使用 sudo 运行 MPI 程序?
最佳答案
解决这个问题最简单的方法是设置文件的权限,它仍然会带来安全问题,但没有设置程序的suid为root那么严重。设置允许打开原始套接字的程序的能力:setcap program cap_net_raw,cap_net_admin+eip
。
关于linux - 在集群上以 sudo 权限运行 MPI 程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56943467/