使用gdb在多个屏幕窗口中调试MPI [英] Use gdb to debug MPI in multiple screen windows

查看:528
本文介绍了使用gdb在多个屏幕窗口中调试MPI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个我想用gdb调试的MPI程序,同时能够看到所有单独的进程的输出,我可以使用:

  mpirun -n  xterm -hold -e gdb -ex run --args ./program [arg1] [arg2] [...] 

当我有一个图形用户界面可以玩的时候,这非常好。但是情况并非总是如此。



是否有类似的设置可用于 screen ,这样每个进程都有自己的窗口?这对于在远程环境中进行调试非常有用,因为它允许我使用 Ctrl + an 来在输出之间切换。



一种方法是启动每个
进程都有一个单独的终端和gdb会话:

  mpirun -n  xterm -hold -e gdb -ex run --args ./program [arg1] [arg2] [...] 

其中 NP 是进程数量。

如果您不有一个图形用户界面方便?



(见下面的一个方便的脚本。)



这是基于timofiend的答案此处



分开mpi程序在其调试器中进行多次屏幕会话:

  mpirun -np 4屏幕-Ad​​mS mpi gdb ./parallel_pit_fill.exe一个保留./beauford.tif 500 500 

启动一个新的屏幕会话以访问调试器:

  screen -AdmS debug 

将调试器的屏幕会话加载到新的屏幕会话中

  screen -list | #获取屏幕会话列表
grep -E[0-9] +。mpi| #提取相关的
awk'{print NR-1,$ 1}'| #生成选项卡#和会话ID,删除字符串的其余部分
xargs -n 2 sh -c'
screen -S调试-X屏幕-t选项卡$ 0屏幕-r $ 1
'

跳转到新屏幕会话:

  screen -r debug 

我已经封装了上面的一个方便的脚本:

 #!/ bin / bash 
if [$#-lt 2]
然后
echoParallel Debugger Syntax:$ 0< NP>< PROGRAM> [arg1] [arg2] [...]
exit 1
fi

the_time =`date +%s`#使用这个,所以我们可以一次运行多个调试会话
#(假设我们只是每秒启动一次)

#第一个参数是进程数。其他一切都是我们希望
#运行的。为每个进程创建一个新的mpi屏幕。
mpirun -np $ 1屏幕-Ad​​mS $ {the_time} .mpi gdb$ {@:2}

#从
创建一个新的调试屏幕-Ad​​mS $ {the_time} .debug

#以下内容用于将调试器载入调试屏幕
firstpart =screen -S $ {the_time} .debug
secondpart =' -X屏幕-t选项卡$ 0屏幕-r $ 1'

screen -list | #获取mpi屏幕列表
grep -E[0-9] +。$ {the_time} .mpi| #提取相关的
awk'{print NR-1,$ 1}'| #生成选项卡#和会话标识符,删除字符串的其余部分
xargs -n 2 sh -c$ firstpart $ secondpart

screen -r $ {the_time} .debug #Enter调试屏幕


If I have an MPI program that I want to debug with gdb while being able to see all of the separate processes' outputs, I can use:

mpirun -n <NP> xterm -hold -e gdb -ex run --args ./program [arg1] [arg2] [...]

which is well and good when I have a GUI to play with. But that is not always the case.

Is there a similar set up I can use with screen such that each process gets its own window? This would be useful for debugging in a remote environment since it would allow me to flip between outputs using Ctrl+a n.

解决方案

How do you debug a C/C++ MPI program?

One way is to start a separate terminal and gdb session for each of the processes:

mpirun -n <NP> xterm -hold -e gdb -ex run --args ./program [arg1] [arg2] [...]

where NP is the number of processes.

What if you don't have a GUI handy?

(See below for a handy script.)

This is based on timofiend's answer here.

Spin up the mpi program in its debugger in a number of screen sessions:

mpirun -np 4 screen -AdmS mpi gdb ./parallel_pit_fill.exe one retain ./beauford.tif 500 500

Spin up a new screen session to access the debugger:

screen -AdmS debug

Load the debugger's screen sessions in to the new screen session

screen -list |                   #Get list of screen sessions
   grep -E "[0-9]+.mpi"  |       #Extract the relevant ones
   awk '{print NR-1,$1}' |       #Generate tab #s and session ids, drop rest of the string
   xargs -n 2 sh -c '
     screen -S debug -X screen -t tab$0 screen -r $1
   '

Jump into the new screen session:

screen -r debug

I've encapsulated the above in a handy script:

#!/bin/bash
if [ $# -lt 2 ]
then
  echo "Parallel Debugger Syntax: $0 <NP> <PROGRAM> [arg1] [arg2] [...]"
  exit 1
fi

the_time=`date +%s` #Use this so we can run multiple debugging sessions at once
                    #(assumes we are only starting one per second)

#The first argument is the number of processes. Everything else is what we want
#to run. Make a new mpi screen for each process.
mpirun -np $1 screen -AdmS ${the_time}.mpi gdb "${@:2}"

#Create a new screen for debugging from
screen -AdmS ${the_time}.debug

#The following are used for loading the debuggers into the debugging screen
firstpart="screen -S ${the_time}.debug"
secondpart=' -X screen -t tab$0 screen -r $1'

screen -list |                         #Get list of mpi screens
   grep -E "[0-9]+.${the_time}.mpi"  | #Extract the relevant ones
   awk '{print NR-1,$1}' |             #Generate tab #s and session ids, drop rest of the string
   xargs -n 2 sh -c "$firstpart$secondpart"

screen -r ${the_time}.debug            #Enter debugging screen

这篇关于使用gdb在多个屏幕窗口中调试MPI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆