c++ boost MPI & threading - 序列化错误:地址未映射
c++ boost MPI & threading - serialize errors: Address not mapped
我被难住了。 all_gather
适用于原语(例如 int
(,但即使对于简单的 STL 容器也会失败。 Valgrind声称容器没有被分配/初始化,但这似乎不对。
总结:
- 我使用 openMP 执行一些多线程处理,然后重新加入线程。
- 在串行中,我尝试使用"boost::mpi::all_gather"
all_gather
一个简单的std::map
。 MPI 等级不是线程。(有 2 个 MPI 等级,每个 MPI 等级有 4 个线程(。 - 然后我打算做更多(隔离的(多线程。
看起来很简单...这里可能发生了什么?
主.cpp
#include <openmpi/mpi.h>
#include <omp.h>
#include <boost/mpi.hpp>
#include "globals.h"
int main(int argc, char* argv[])
{
int provided_MPI;
MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE, &provided_MPI );
boost::mpi::environment my_boost_mpi_env(argc, argv);
boost::mpi::communicator world_MPI_boost;
world_MPI_boost_ptr = &world_MPI_boost;
// ^^^ global variable of type boost::mpi::communicator *
perform_complete_variable_elimination_schedule();
//...
}
Conn_Comp.cpp
#include <boost/mpi.hpp>
#include <boost/mpi/collectives.hpp>
#include <boost/serialization/serialization.hpp>
#include <boost/serialization/vector.hpp>
#include <boost/serialization/map.hpp>
#include "globals.h"
...
void perform_complete_variable_elimination_schedule()
{
// isolated work in parallel using OpenMP
#pragma omp parallel
{
//work
}
// SERIAL REGION (with respect to threading).
std::map<uint,uint> my_map;
std::vector< std::map<uint,uint> > vec_of_my_maps;
boost::mpi::all_gather< std::map<uint,uint> >
(*world_MPI_boost_ptr,
my_map,
vec_of_my_maps); // <--- line 293 (referenced by valgrind)
// more isolated work in parallel using OpenMP
#pragma omp parallel
{
//work
}
}
Valgrind抱怨map
的vector
导致无效读取。 但是这个vector
是在all_gather
调用之前创建的 - 所以它显然在范围内,而不是在并行线程区域中。选定的瓦尔格林德错误输出:
==12665== Use of uninitialised value of size 4
==12665== at 0x41C8D7A: boost::archive::detail::basic_iarchive::get_library_version() const (basic_iarchive.cpp:575)
==12665== by 0x41C92C6: boost::archive::detail::basic_iarchive::load_object(void*, boost::archive::detail::basic_iserializer const&) (basic_iarchive.cpp:399)
==12665== by 0x80F5696: void boost::mpi::all_gather<std::map<unsigned int, unsigned int, std::less<unsigned int>, std::allocator<std::pair<unsigned int const, unsigned int> > > >(boost::mpi::communicator const&, std::map<unsigned int, unsigned int, std::less<unsigned int>, std::allocator<std::pair<unsigned int const, unsigned int> > > const&, std::vector<std::map<unsigned int, unsigned int, std::less<unsigned int>, std::allocator<std::pair<unsigned int const, unsigned int> > >, std::allocator<std::map<unsigned int, unsigned int, std::less<unsigned int>, std::allocator<std::pair<unsigned int const, unsigned int> > > > >&) (iserializer.hpp:387)
==12665== by 0x80DEC83: Conn_Comp::perform_complete_variable_elimination_schedule() (Conn_Comp.cpp:**293**)
==12665== by 0x80C840A: main (main.cpp:695)
==12665==
==12665== Invalid read of size 2
==12665== at 0x41C8D7A: boost::archive::detail::basic_iarchive::get_library_version() const (basic_iarchive.cpp:575)
==12665== by 0x41C92C6: boost::archive::detail::basic_iarchive::load_object(void*, boost::archive::detail::basic_iserializer const&) (basic_iarchive.cpp:399)
==12665== by 0x80F5696: void boost::mpi::all_gather<std::map<unsigned int, unsigned int, std::less<unsigned int>, std::allocator<std::pair<unsigned int const, unsigned int> > > >(boost::mpi::communicator const&, std::map<unsigned int, unsigned int, std::less<unsigned int>, std::allocator<std::pair<unsigned int const, unsigned int> > > const&, std::vector<std::map<unsigned int, unsigned int, std::less<unsigned int>, std::allocator<std::pair<unsigned int const, unsigned int> > >, std::allocator<std::map<unsigned int, unsigned int, std::less<unsigned int>, std::allocator<std::pair<unsigned int const, unsigned int> > > > >&) (iserializer.hpp:387)
==12665== by 0x80DEC83: Conn_Comp::perform_complete_variable_elimination_schedule() (main.cpp:**293**)
==12665== by 0x80C840A: main (main.cpp:695)
==12665== Address 0x3580bece is not stack'd, malloc'd or (recently) free'd
==12665==
[drosphila:12665] *** Process received signal ***
[drosphila:12665] Signal: Segmentation fault (11)
[drosphila:12665] Signal code: Address not mapped (1)
[drosphila:12665] Failing at address: 0x3580bece
[drosphila:12665] [ 0] /lib/i686/cmov/libpthread.so.0(+0xe500) [0x44f8500]
[drosphila:12665] [ 1] /usr/lib/libboost_serialization.so.1.42.0(_ZN5boost7archive6detail14basic_iarchive11load_objectEPvRKNS1_17basic_iserializerE+0x1b7) [0x41c92c7]
[drosphila:12665] [ 2] ./detect_NAHR(_ZN5boost3mpi10all_gatherISt3mapIjjSt4lessIjESaISt4pairIKjjEEEEEvRKNS0_12communicatorERKT_RSt6vectorISD_SaISD_EE+0x587) [0x80f5697]
[drosphila:12665] [ 3] ./detect_NAHR(_ZN9Conn_Comp46perform_complete_variable_elimination_scheduleEv+0x534) [0x80dec84]
[drosphila:12665] [ 4] ./detect_NAHR(main+0xf5b) [0x80c840b]
[drosphila:12665] [ 5] /lib/i686/cmov/libc.so.6(__libc_start_main+0xe6) [0x4519ca6]
[drosphila:12665] [ 6] ./detect_NAHR() [0x80c73e1]
[drosphila:12665] *** End of error message ***
我根据提升帮助页面的建议使用MPI_Init_thread。
正如我在顶部所说,如果我使用原始(即只是uint
(而不是地图,那么all_gather
工作正常。 为什么地图会失败? boost serialize
已经有了序列化 STL 容器的方法,所以这不是问题......
另请注意,将保存所有值的向量会自动调整all_gather
大小(我检查了all_gather
的实现(以足够大以容纳所有内容。 无论如何,即使我自己初始化它,它仍然失败。
最后,即使我使用普通的旧数组(正确分配(,例如 std::map<uint,uint> *
,我遇到了同样的问题。
嗯,这很尴尬。我将把这个问题留下来,以防其他人有同样的奇怪错误。
我的代码的问题实际上出在生成文件中。我忘了链接到 MPI 的提升库。
不正确的生成文件标志:
-I$(BOOST_INCLUDE) -lboost_serialization -lboost_mpi
显然,该行包含的信息刚好足以允许程序编译和运行,但会导致运行时错误。
更正生成文件标志:
-L$(BOOST_LIB) -ldl -Wl,-rpath,$(BOOST_LIB) -lboost_serialization -lboost_mpi
(请注意库链接标志的添加(。
相关文章:
- 为什么我在leetcode上收到AddressSanitizer:地址0x602000000058上的堆缓冲区溢出错误
- 地址的奇怪错误
- 为什么我得到以下代码地址清理器:未知地址错误的SEGV
- 运行时错误:引用绑定到类型"int"的未对齐地址0xbebebebebebebec6,这需要 4 个字节对齐 (stl_vector.h)
- 我有一个线程 1:EXC_BAD_ACCESS(代码 = 1,地址 = 0x8)错误.我认为这是由于内存管理不好.我可以
- Assimp 库错误:获取打包成员的地址
- 运行时错误地址清理器:LEETCODE 中的致命信号
- 瓦尔格林德错误 - 地址0x0不是堆叠的 malloc'd 或自由的
- 获取未知分段错误"(地址)在 std::__cxx11::basic_string<char, std::char_traits<char>,..., std::分配器<cha
- 来自简单循环的 OpenAcc 错误:内核执行期间的非法地址
- 带有 NORM 的 ZeroMQ - 地址已在使用 错误被抛出在第二个 .bind() 上 - 为什么?
- 重载新返回错误的地址
- 线程 1:xcode 中出现EXC_BAD_ACCESS(代码 = 1,地址 = 0x0)错误
- C++带有 CMakeList 的地址清理器.txt会导致 asan 错误
- 为什么这段代码给出错误......'a'是指针到字符指针,应该存储's'的地址,因为s是指向数组的第一个元素的指针
- C++ 临时地址不会导致生成错误
- 为什么 LeetCode 给出错误:地址清理器:堆缓冲区溢出
- 分段错误:地址未映射/地址失败:(无)
- 为什么在递增后使用 [] 运算符访问指针数组会返回错误地址的当前内存位置
- 绑定错误:地址已在使用中