使用向量时出现奇怪的运行时错误
Strange runtime error when using vectors
当我与 mpi 并行运行时,我在运行时的代码遇到了一个非常奇怪的问题:
*** glibc detected *** ./QuadTreeConstruction: munmap_chunk(): invalid pointer: 0x0000000001fbf180 ***
======= Backtrace: =========
/lib/libc.so.6(+0x776d6)[0x7f38763156d6]
./QuadTreeConstruction(_ZN9__gnu_cxx13new_allocatorImE10deallocateEPmm+0x20)[0x423f04]
./QuadTreeConstruction(_ZNSt13_Bvector_baseISaIbEE13_M_deallocateEv+0x50)[0x423e72]
./QuadTreeConstruction(_ZNSt13_Bvector_baseISaIbEED2Ev+0x1b)[0x423c79]
./QuadTreeConstruction(_ZNSt6vectorIbSaIbEED1Ev+0x18)[0x4237d2]
./QuadTreeConstruction(_Z22findLocalandGhostCellsRK8QuadTreeRK6ArrayVIiES5_iRS3_S6_+0x849)[0x41dbbd]
./QuadTreeConstruction(main+0xa32)[0x41ca49]
/lib/libc.so.6(__libc_start_main+0xfe)[0x7f38762bcd8e]
./QuadTreeConstruction[0x41b029]
我的代码是 valgrind 清理 mpi 库内部的一些错误(我使用 OpenMpi,我以前见过很多次,但它们从未成为问题;见 http://www.open-mpi.org/faq/?category=debugging#valgrind_clean)。当我在串行中运行时,我没有任何问题。
我已经能够使用 gdb 将问题追踪到SIGABORT
系统调用,这是代码中断时的堆栈:
0 raise raise.c 64 0x7f4bd8655ba5
1 abort abort.c 92 0x7f4bd86596b0
2 __libc_message libc_fatal.c 189 0x7f4bd868f65b
3 malloc_printerr malloc.c 6283 0x7f4bd86996d6
4 __gnu_cxx::new_allocator<unsigned long>::deallocate new_allocator.h 95 0x423f04
5 std::_Bvector_base<std::allocator<bool> >::_M_deallocate stl_bvector.h 444 0x423e72
6 std::_Bvector_base<std::allocator<bool> >::~_Bvector_base stl_bvector.h 430 0x423c79
7 std::vector<bool, std::allocator<bool> >::~vector stl_bvector.h 547 0x4237d2
8 findLocalandGhostCells mpi_partition.cpp 249 0x41dbbd
9 main mpi_partition.cpp 111 0x41ca49
这听起来像是内存损坏,但我完全不知道是什么原因造成的。基本上,代码在看起来像这样的函数中中断:
void findLocalandGhostCells(){
std::vector<bool> foo(fooSize,false);
// do stuff with foo; nothing crazy -- I promise
return;
}
有人知道我现在应该做什么吗?:(
如果您非常确定向量操作本身是正确的且不疯狂的,请尝试逐步跟踪向量的成员。您的其他一些操作可能损坏了矢量的内存块。例如,入侵矢量记忆的memcpy。
相关文章:
- 删除指向指针的指针是运行时错误吗
- c++中的指针和运行时错误
- 无法理解此 return 语句的功能,没有它就会发生运行时错误
- 在同一模拟中使用静脉和静脉_ inet内容时出现运行时错误
- 对单向链表进行排序时出现运行时错误
- 为什么此代码存在运行时错误?
- 你能解释一下什么运行时错误是如何解决它的吗?
- 为什么程序在 c++ 中迭代 emtpy 向量时会抛出运行时错误
- 使用向量将给定表达式转换为波兰表示法时出现运行时错误
- 涉及向量的初学者代码,SEIGSEV运行时错误
- 类中向量的random_shuffle的c++运行时错误
- 在运行时C++将元素插入到向量中.引发运行时错误
- 使用向量时出现奇怪的运行时错误
- 显示向量 (C++) 时出现运行时错误
- 使用字符串向量初始值设定项时,我收到运行时错误"terminate called after throwing instance of `std::length_error`"
- 在SDL_blitsurface中使用 SDL_Rect 向量时出现 c++ 运行时错误
- Igraph 特征向量中心性运行时错误 c++
- 当索引超出向量类的范围时,没有编译错误或运行时错误
- 运行时错误与文件io和向量(c++)
- 向量迭代器擦除给我一个运行时错误