访问 boost稀疏矩阵的元素似乎使程序停止运行

发布于 2024-08-03 10:27:39 字数 851 浏览 1 评论 0原文

我有一个奇怪的错误,我希望更有经验的程序员能够对此有所了解。我正在使用 boost ublas 稀疏矩阵,特别是mapped_matrix,并且最终会出现间歇性错误,但不会在程序的初始阶段出现。这是一个很大的程序,所以我不能发布所有代码,但核心思想是我调用属于特定类的函数:

bool MyClass::get_cell(unsigned int i, unsigned int j) const
{
    return c(i,j);
}

变量 c 被定义为该类的成员

boost::numeric::ublas::mapped_matrix<bool> c;

当错误发生时,程序似乎停止(但不会崩溃)。使用 Eclipse 进行调试,我可以看到程序进入了 boost Matrix 代码,并继续向下进入 std::map、std::_Rb_tree 和 std::less 几个级别。此外,程序有时会追溯到 std::map、std::_Rb_tree 和 std::_Select1st。当代码正在执行并且 _Rb_tree 中内存中的活动行发生变化时,执行似乎永远不会返回到 std::map 级别。程序卡在 std::map 中的行是以下函数的返回。

const_iterator
find(const key_type& __x) const
{ return _M_t.find(__x); }

在我看来,程序正在寻找 c 矩阵中的某些元素,但不知何故底层存储机制“放错了它”。但是,我不确定为什么或如何解决它。这也可能是完全错误的。

您能提供的任何帮助将不胜感激。如果我在这个问题中没有包含正确的信息,请告诉我我遗漏了什么。谢谢。

I've got a strange bug that I'm hoping a more experience programmer might have some insight into. I'm using the boost ublas sparse matrices, specifically mapped_matrix, and there is an intermittent bug that occurs eventually, but not in the initial phases of the program. This is a large program, so I cannot post all the code but the core idea is that I call a function which belongs to a particular class:

bool MyClass::get_cell(unsigned int i, unsigned int j) const
{
    return c(i,j);
}

The variable c is defined as a member of the class

boost::numeric::ublas::mapped_matrix<bool> c;

When the bug occurs, the program seems to stop (but does not crash). Debugging with Eclipse, I can see that the program enters the boost mapped_matrix code and continues several levels down into std::map, std::_Rb_tree, and std::less. Also, the program occasionally traces down to std::map, std::_Rb_tree, and std::_Select1st. While code is executing and the active line what's in memory changes in _Rb_tree, execution never seems to return in the level of std::map. The line in std::map the program is stuck on is the return of the following function.

const_iterator
find(const key_type& __x) const
{ return _M_t.find(__x); }

It seems to me that there is some element in the c matrix that the program is looking for but somehow the underlying storage mechanism has "misplaced it". However, I'm not sure why or how to fix it. That could also be completely off base.

Any help you can provide would be greatly appreciated. If I have not included the right information in this question, please let me know what I'm missing. Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

仅此而已 2024-08-10 10:27:39

尝试调试代码的一些事情(不一定是永久性更改):

  • c 的矩阵类型中的 bool 更改为 int,以查看矩阵是否需要数字类型。
  • 将矩阵类型更改为具有类似接口的另一种矩阵类型,可能是普通的旧矩阵。
  • Valgrind 该应用程序(如果您使用的是 Linux)来检查您没有损坏内存。

如果失败,您可以尝试在每次修改矩阵时调用 get_cell 以查看可能导致问题的原因。

如果做不到这一点,您可能必须尝试将问题减少到更小的代码子集,您可以将其发布在此处。

如果您告诉我们您正在使用什么编译器和操作系统,这可能会有所帮助。

Some things to try to debug the code (not necessarily permanent changes):

  • Change the bool to an int in the matrix type for c, to see if the matrix expects numeric types.
  • Change the matrix type to another with a similar interface, possibly plain old matrix.
  • Valgrind the app (if you're on linux) to check you're not corrupting memory.

If that fails, you could try calling get_cell every time you modify the matrix to see what might be causing the problem.

Failing that, you may have to try reduce the problem to a much smaller subset of code which you can post here.

It might help if you tell us what compiler and OS you're using.

看海 2024-08-10 10:27:39

这是多线程程序的一部分吗?

我之所以这么问,是因为通常当我在 STL 中看到问题时,最终都会发现是访问不同步的问题。

Is this part of a multithreaded program?

I ask, because usually when I see problems in STL, it ends up being a problem with unsynchronized access.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文