【问题标题】:How to run gdb in gnome-terminal from mpirun?如何从 mpirun 在 gnome-terminal 中运行 gdb?
【发布时间】:2019-10-11 15:56:57
【问题描述】:

我有一个使用 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 失败

--> 返回 "(null)" (-43) 而不是 "Success" (0)

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

*** MPI_Init 发生错误

*** 在 NULL 通信器上

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

*** 可能还有你的 MPI 工作)

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

[Inferior 1 (process 4169) exited with code 01]

在 2) 终端说:

为此终端创建子进程时出错

执行子进程“gdb app”失败(没有那个文件或目录)

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

我做错了什么?

编辑:事实证明,有问题的不是 xterm,而是带有 --tui 选项的 gdb。如果你的程序打印了一些东西,那么无论在哪个终端,gdb 窗口都会开始显示不正确的东西。

【问题讨论】:

    标签: bash gdb openmpi gnome-terminal


    【解决方案1】:

    问题是 gnome-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 运行它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-29
      相关资源
      最近更新 更多