我有一个使用mpi的程序。要调试它,我可以使用mpirun -np 2 xterm -e gdb myprog

但是,xterm在我的机器上出了问题。我想尝试 gnome-terminal ,但我不知道要输入什么。我试过了:

1)mpirun -np 2 gnome-terminal -- gdb myprog

2)mpirun -np 2 gnome-terminal -- "gdb myprog"

3)mpirun -np 2 gnome-terminal -- bash -c "gdb myprog"

4)mpirun -np 2 gnome-terminal -- bash -c "gdb myprog; exec bash"

但这些似乎都不起作用; 1),3),4)在gdb中的run之后说:

看起来MPI_INIT由于某种原因失败了;你的并行过程是   可能会中止。并行过程可以有很多原因   在MPI_INIT期间失败;其中一些是由于配置或环境   问题。这种失败似乎是内部失败;这是一些   附加信息(可能仅与Open MPI相关   开发者):

 

ompi_mpi_init:ompi_rte_init失败

 

--& gt;返回"(null)" (-43)而不是"Success" (0)

 

-------------------------------------------------------------------------

 

*** MPI_Init中发生错误

 

***在NULL通讯器上

 

*** MPI_ERRORS_ARE_FATAL(此通信器中的进程现在将中止,

 

***并且可能是你的MPI工作)

 

[oleg-VirtualBox: 4169] MPI_INIT完成之前的本地中止成功完成,但无法聚合错误消息,并且无法保证所有其他进程都被杀死!

 

[Inferior 1(程序4169)退出,代码为01]

在2)terminal说:

There was an error creating the child process for this terminal

Failed to execute child process “gdb app” (No such file or directory)

顺便说一句,我使用的是Ubuntu 18.04.02 LTS。

我做错了什么?

EDIT:事实证明,它不是xterm,它是错误的,它是带有 --tui 选项的gdb。如果您的程序打印出某些内容,gdb窗口将开始显示不正确的内容,无论是哪个terminal

分析解答

问题是 gnome-terminal 将请求的程序移交给terminal服务器,然后立即退出。然后mpirun看到已启动的程序已退出,并破坏MPI运行时环境。当MPI程序真正启动时,mpirun已经退出。据我所知,没有办法让 gnome-terminal 等到给定的命令结束。

有一个解决方法:而不是直接用mpirun启动 gnome-terminal ,而是有两个包装脚本。第一个是由mpirun开始的。它创建一个临时文件,告诉 gnome-terminal 启动第二个包装器脚本,然后等待,直到临时文件消失。第二个包装器脚本运行您实际想要运行的命令,例如gdb myprog,等待它结束,然后删除临时文件。此时,第一个包装器注意到临时文件消失并退出。然后mpirun可以安全地破坏MPI环境。

从脚本本身可能更容易理解。

debug.sh:

#!/bin/bash
# This is run outside gnome-terminal by mpirun.

# Create a tmp file that we can wait on.
export MY_MPIRUN_TMP_FILE="$(mktemp)"

# Start the gnome-terminal. It will exit immediately.
# Call the wrapper script which removes the tmp file
# after the actual command has ended.
gnome-terminal -- ./helper.sh "$@"

# Wait for the file to disappear.
while [ -f "${MY_MPIRUN_TMP_FILE}" ] ; do
    sleep 1
done

# Now exit, so mpirun can destroy the MPI environment
# and exit itself.

helper.sh

#!/bin/bash
# This is run by gnome-terminal.

# The command you actually want to run.
"$@"

# Remove the tmp file to show that the command has exited.
rm "${MY_MPIRUN_TMP_FILE}"

mpirun debug.sh gdb myproc运行它。