2012-05-17 4 views
1

내가 엉망입니다. all_gather은 프리미티브 (예 : int)에서 작동하지만 간단한 STL 컨테이너에서도 실패합니다. valgrind는 컨테이너가 할당되지 않았거나 초기화되지 않았다고 주장하지만 올바르게 보이지 않습니다. 요약C++ boost MPI & threading - 직렬화 오류 : 주소가 매핑되지 않았습니다.

:

  • 나는 스레딩 멀티 OpenMP를 선택한 다음에 스레드에 다시 몇 가지 않습니다.
  • 연속적으로, 나는 boost :: mpi :: all_gather를 사용하여 all_gather 간단한 std::map을 시도한다. MPI 순위는 이 아니고 스레드입니다. (2 개의 MPI 랭크가 있고 각 MPI 랭크는 4 개의 스레드를가집니다.)
  • 그런 다음 좀 더 (격리 된) 멀티 스레딩을하려고합니다.

여기에 어떤 일이 일어날 수 있을까요?

MAIN.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의 불평 잘못된 읽기의 vectormap의 결과가. 그러나이 vectorall_gather 호출 바로 전에 생성되었으므로 분명히 범위 내에 있고 병렬 스레드 영역에는 없습니다. 선택 Valgrind의 오류 출력 : 나는 부스트help page의 추천에 따라 MPI_Init_thread를 사용

==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 *** 

.

위에서 말했듯이지도 대신 프리미티브 (예 : uint)를 사용하면 all_gather이 정상적으로 작동합니다. 왜지도가 실패해야합니까? boost serialize 이미 STL 컨테이너를 직렬화하는 방법이있다, 그래서는 문제가되지 않습니다 ...

참고 또한 모든 값을 보유 할 벡터가 자동으로 all_gather에 크기가 조정되는 큰 될 (나는 all_gather의 구현을 확인) 모든 것을 담을만큼 충분합니다. 비록 내가 직접 초기화하더라도, 여전히 실패합니다.

마지막으로, 예전의 배열 (적절하게 할당 됨)을 사용하더라도. std::map<uint,uint> *, 같은 문제가 발생합니다.

+1

나는'boost :: mpi'가 C MPI API에서 만들어졌고 더 이상 사용되지 않으며 MPI v3.0에서 삭제 될 C++이 아니기를 바랍니다. –

답변

2

글쎄, 당황 스럽네. 다른 사람이 같은 이상한 오류가있는 경우를 대비하여 질문을 떠날 것입니다.

내 코드의 문제점은 실제로 makefile에 있습니다. MPI 용 부스트 라이브러리에 링크하는 것을 잊었습니다.

-I$(BOOST_INCLUDE)  -lboost_serialization -lboost_mpi 

은 분명히 그 라인이 프로그램을 컴파일하고 실행할 수 있도록 충분한 정보를 포함하고 있지만 런타임 오류가 발생합니다 :

잘못된 메이크 플래그.

올바른 메이크 플래그 :

-L$(BOOST_LIB) -ldl -Wl,-rpath,$(BOOST_LIB) -lboost_serialization -lboost_mpi 

이 (플래그를 연결하는 라이브러리의 추가를 주목하라).

+0

LIBRARY_PATH 환경에서 부스트 라이브러리를 설정하는 방법은 무엇입니까? 각 국기의 기능을 설명해 주시겠습니까? – William