简体   繁体   English

我如何调试 C++ MPI 代码?

[英]How could I debug C++ MPI code?

My Boost MPI code compiles with no problem:我的Boost MPI代码编译没有问题:

But when running, I have issues.但是在运行时,我有问题。 I am not sure which line in my code causes this problem.我不确定我的代码中的哪一行导致了这个问题。 What could I do?我能做什么?

[dhcp-18-189-36-128:80590] *** Process received signal ***
[dhcp-18-189-36-128:80590] Signal: Floating point exception: 8 (8)
[dhcp-18-189-36-128:80590] Signal code: Integer divide-by-zero (7)
[dhcp-18-189-36-128:80590] Failing at address: 0x10e4cab9f
[dhcp-18-189-36-128:80590] [ 0] 0   libsystem_platform.dylib            0x00007fff8d0185aa _sigtramp + 26
[dhcp-18-189-36-128:80590] *** End of error message ***

My recommendation would be to put unit tests around your code to verify it functions correctly in a context smaller than your entire application.我的建议是对您的代码进行单元测试,以验证它在小于整个应用程序的上下文中是否正确运行。 If you are new to unit testing and test-driven development, you can look at my tutorial on test-driven development from C++ Now!如果您不熟悉单元测试和测试驱动开发,可以立即查看我的C++ 测试驱动开发教程! 2014 . 2014 年

To elaborate further: when faced with a bug, I try to write a failing unit test that demonstrates the bug.进一步详细说明:当遇到错误时,我尝试编写一个失败的单元测试来演示该错误。 It's hard to make a specific recommendation of what test to write without seeing any code, but I suggest you start by running your code in the debugger and setting the debugger to treat any floating point exception signal as a breakpoint.在没有看到任何代码的情况下很难对要编写的测试提出具体建议,但我建议您首先在调试器中运行代码并将调试器设置为将任何浮点异常信号视为断点。 When the breakpoint is hit due to the signal, examine the call stack at that point.当由于信号命中断点时,检查该点的调用堆栈。 Then you will know what code is causing the signal.然后你就会知道是什么代码导致了信号。 Then you can write a unit test that calls that code with the same arguments.然后您可以编写一个单元测试,使用相同的参数调用该代码。 Your unit test should now fail by reproducing the problem and causing the same divide-by-zero signal.您的单元测试现在应该通过重现问题并导致相同的除以零信号而失败。 Then you can change your implementation and re-run the test to verify that the signal is no longer caused.然后您可以更改您的实现并重新运行测试以验证不再引起信号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM