我正在尝试使用mpi在Linux上为C++程序设置我的VScode调试器。虽然编译和运行工作正常,但我很难让调试器在mpi代码的情况下添加命令行参数。argv
数组只保存垃圾。此外,调试器不会启动在launch.json文件中使用-np
选项指定的进程数。如果我只是使用mpirun -np 2 code.exe arg1 arg2...
手动运行代码,一切都很正常
任何帮助都是感激的。
以下是我的.vscode文件:
tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "mpicxx build active file",
"command": "/usr/bin/mpicxx",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
字符串
launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "MPI Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}.exe",
"args": [
"-np", // should govern number of processes launched
"1", // by mpi
"${fileDirname}/${fileBasenameNoExtension}.exe",
"0", // these arguments are additional arguments
"0.01", // used by the program
"5",
"10"
],
"stopAtEntry": true,
"cwd": "${fileDirname}",
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"preLaunchTask": "mpicxx build active file",
"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
}
],
}
]
}
型
要找到mpi头,还需要一个c_cpp_properties.json:
{
"configurations": [
{
"name": "linux-gcc-x64",
"includePath": [
"${workspaceFolder}/**",
"/usr/lib/x86_64-linux-gnu/openmpi/include/"
],
"compilerPath": "/usr/bin/gcc",
"cStandard": "${default}",
"cppStandard": "${default}",
"intelliSenseMode": "linux-gcc-x64",
"compilerArgs": [
""
]
}
],
"version": 4
}
型
1条答案
按热度按时间fjnneemd1#
我是这样做的:
首先,OpenMPI的网站上有一段描述了如何在所有MPI进程中构建断点并将GDB附加到每个进程。
使用VSCode,我将以下配置添加到
launch.json
:字符串
例如,如果我运行
mpirun -np 4 ./ComputeInverseSquare_x64
,其中ComputeInverseSquare
看起来像这样:型
然后,在VSCode中,当点击f5或启动“(gdb)Attach”配置时,
command:pickProcess
将被触发,我可以搜索名称为ComputeInverseSquare
的可执行文件,我会看到其中4个具有不同PID的文件,我可以附加和调试。希望能帮上忙。
其他信息:
1.如何在Windows上使用GDB