New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feature request] very basic support for MPI debugging multiple processes at the same time #1723
Comments
@davydden I don't think the UI would support what you are proposing. Unfortunately, VS Code will only allow one debug instance, so even if we attach to 4 separate processes (which we can't because VS Code won't spawn the debug adapter 4 times) there isn't a UI to allow this change. With the way the debugAdapter is authored, it is a one to one relationship with the debuggee. Your feature request would need to start with VS Code for them to allow simultaneous multi-process debugging. |
@pieandcakes EDIT: i guess the only way to hack this is separate attach configs:
|
@davydden Even then, you can only attach one process at a time so it won't get you too far. Once you have started debugging, you can't really debug again. |
I see, thanks for clarifying. |
@pieandcakes I was said upstream that the support for multiple processes is already there:
do you think it's possible for |
based on the discussion in
Personally, I have no idea how one would pause[1] processes to wait until debugger is attached, but apart from this technical issue, this should be doable and everything is there in VSCode to support it. [1] without injecting any code like
|
@davydden we can take that as a suggested feature request. Can you provide a project with a repro? I don't have experience with mpirun. |
@pieandcakes sure, here's a simple example
on macOS you can use homebrew or spack to build any MPI providers i.e. OpenMPI (do not confuse with OpenMP, those are different things). On Linux you can get MPI from standard repositories (i.e. Let me know if I could further help somehow, though I have no experience whatsoever with p.s. this is of course a personal opinion, but I think VS Code could attract a fair amount of computational scientists with this feature as not all universities have licenses for dedicated commercial debuggers, that cost upwards from around 700$. It's probably also not something an individual would buy himself. A good summary of debugger options for MPI is in this stackoverflow post and also in deal.II FAQ wiki. |
Thanks @davydden. We played around with this a bit and I think I could see how we someone could make this work. Below is a basic outline in case anyone wants to try and take this on. In the interest of full disclosure, this is enough work that we would need to see significant interest in using this from the MPI community before we would take on this work. At any rate, here is how we think it could work:
A few other notes:
|
@WardenGnaw thanks entertaining the idea, appreciate it.
That's perfectly understandable. I will ping a few folks in case the want to add something on the prospect of debugging MPI with GUI in Visual Studio Code @alalazo @bangerth @tjhei @BarrySmith @tgamblin @goxberry @jthies . |
Thanks for the ping @davydden! I agree with both of the statements @davydden mentioned re: market:
and scoping a "parallel debugging" feature:
The two most important things that make dedicated commercial debuggers (e.g., TotalView) easier to use are:
It's possible to do many of the same sorts of things that these debuggers do by spawning multiple debugger instances in separate windows, but it's a kludgy setup that tends to reduce productivity because a user has to spend time figuring out which context (i.e., which window) they want to operate on. If VS Code were able to toggle among MPI processes in a single window and display the appropriate debugging info, it would be a killer feature for developers who don't have access to dedicated commercial debuggers, and it would make it easier to demo and explain to beginners how to debug parallel programs that use MPI. |
I agree with @davydden. We pay lot of money for site licenses of parallel debuggers. Often it's sufficient for many users to debug with few mpi processes. If parallel debugging feature will be available, me (and my colleagues) will definitely give a try! |
That will be a very practical feature for daily use before jumping to more sophisticated debuggers. |
Have you talked to the Microsoft HPC/MPI developers? I thought they developed exactly this kind of functionality (on the MPI side) several years ago. I could be wrong -- I don't follow the Microsoft side of HPC very much. Best to check with them to see exactly what they did. Additionally, be aware that the MPI community defined a mechanism for the MPI implementation and a tool (e.g., a debugger) to attach to each other -- it's called the MPIR process acquisition interface. Both Open MPI and MPICH have supported MPIR for... er... I don't know offhand, but it's measured in decades. It's the same mechanism that is used by DDT, TotalView, ...etc. If you're going to make new tools that attach to MPI processes, you might as well use the pre-existing infrastructure for it. That being said, Open MPI is deprecating its MPIR interface and is (literally) in the middle of replacing it with a more modern/flexible PMIx interface for tool attachment. MPIR is fine, but it's showing its age; PMIx is the New Hotness. That might be worth investigating, too. Just my $0.02. |
Also, debugging a parallel application is quite different than debugging several independant processes actions (continue, step, next, ...) and breakpoints/watchpoints/tracepoints should be set on all the tasks, a subset of tasks (e.g. communicator/group) or an individual task. automatically attaching to several independant processes is obviously better than nothing, especially if it is free (as in beer), but I am afraid it is a bit too rusty to be effective. Obviously, a parallel debugger is not a trivial development. |
This would be extremely useful too. For people who can't purchase something that's about $1000 to use at research projects or at home, and there is quite a few that I know of personally, this would be an amazing feature. |
@TheMeh I had listed a description on what needs to be done in this comment. Creating a VSCode extension can be found here. |
@WardenGnaw My Application: Normal behavior without gdb (for reference):
What works when launched with gdb in vscode:
.
|
Any update on this? This is still the top result on google for "debug mpi in vscode", so it seems this has significant interest. As a stop-gap solution, has anyone been able to successfully create a launch.json file to launch and automatically attatch to eg the first mpi rank? Naively, it seems to me that this should be significantly more doable, and still extremely usefull... |
Debugging would be fantastic, but I can't figure out how to include the "mpiexec -n " prefix in launch.json. Surely there is some way to do this, yes? I tried adding it as a prelaunch task but the system requires that I include it as a prefix to running the a python script. Any help would be greatly appreciated. |
Tangentially related: have a look at |
Hi, I've written a program I call but then seems to hang almost immediately. Without vs-code, this finishes nearly instantaneously. I had to do some hacky things in the {
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "mpigdb",
"logging": { "engineLogging": true, "trace": true, "traceResponse": true },
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/play/build/crash",
"args": ["${workspaceFolder}/play/build/crash"],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "/home/runderwood/.cargo/bin/mpigdb",
"miDebuggerArgs": "--mpigdb_verbose -np 4 -- ${workspaceFolder}/play/build/crash",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
}
]
} Here is the debug console output: debug.txt |
It's not an integrated solution, but the way I debug MPI programs with vscode is using mpidb. It automates the spawning of gdbserver instances with some customization and prints the information required to attach with gdb. You can pipe this information into a helper tool that generates a launch.json file for vscode. It includes a compound configuration that lets you debug the specified MPI ranks as a "multi-process" debugging session. |
Are there any updates regarding this? Do we finally have MPI debugging support in VScode that allows us to switch MPI process from the UI? |
@mredenti, I've used the technique from |
I figured it out (no special VS Code extensions or other tools required): Example with two MPI ranks:
mpiexec -n 1 gdbserver :20000 ./my_prog : -n 1 gdbserver :20001 ./my_prog
{
"version": "0.2.0",
"compounds": [
{
"name": "connect C++ (NProcs=2)",
"configurations": [
"_rank0",
"_rank1"
],
"stopAll": true
}
],
"configurations": [
{
"name": "_rank0",
"type": "cppdbg",
"request": "launch",
"program": "/abs/path/to/my_prog",
"miDebuggerServerAddress": "localhost:20000",
"MIMode": "gdb",
"miDebuggerPath": "/abs/path/to/gdb",
"cwd": "${workspaceRoot}"
},
{
"name": "_rank1",
"type": "cppdbg",
"request": "launch",
"program": "/abs/path/to/my_prog",
"miDebuggerServerAddress": "localhost:20001",
"MIMode": "gdb",
"miDebuggerPath": "/abs/path/to/gdb",
"cwd": "${workspaceRoot}"
}
]
} Works like a charm. You can also use other debuggers, if remote debugging is supported by both the debugger in general and the VS Code implementation. I tried debugpy, which works perfectly fine for me. The mpiexec -n 1 python -m debugpy --listen :10000 --wait-for-client my_script.py : -n 1 python -m debugpy --listen :10001 --wait-for-client my_script.py You can even combine Python and C++ debugging, if you start the servers like this: mpiexec -n 1 gdbserver :20000 python -m debugpy --listen :10000 my_script.py : -n 1 gdbserver :20001 python -m debugpy --listen :10001 my_script.py |
This is actually what mpigdb does internally when in vscode mode. Last time I checked (a few months ago) I've found some edge cases with some of the more exotic features. |
It would be good to have a very basic support of debugging MPI programs.
Outside of VSCode I can attach a debugger to each terminal via
and then do the standard serial debugging in each terminal window.
Alternative is to hack-in into the source a piece of code which prints process ID and waits so that a user can attach a debugger to some/all processes, see https://www.open-mpi.org/faq/?category=debugging#serial-debuggers .
With
vscode-cpptools
one can already adopt the latter vialaunch.json
and its"processId": "${command:pickProcess}"
option.It would be great, if
vscode-cpptools
goes one step further by extending the launch config withand in the background simply attach
gdb/lldb
debugger for each MPI process and perhaps append a number to the"name": "(lldb) Attach",
so that one can use the available GUI.One would, of course, need to manually switch between debuggers for each process in the GUI but this should be fine for up to 4-8 processes, which is often enough to find bugs in MPI programs.
p.s. AFAIK the only other non-commerical project with MPI debugger is Eclipse PTP, but last time I checked it was limited to Linux.
The text was updated successfully, but these errors were encountered: