Boost logo

Boost Users :

Subject: Re: [Boost-users] [multiindex] Ordered index corruption
From: Chris Jewell (chris.jewell_at_[hidden])
Date: 2011-07-26 09:18:40


Hi Joaquin,

>> I have a problem with a multiindex ordered_non_unique index
>> becoming corrupted :(
>>
>> I am working with a multiindex that stores class objects of type
>> Individual:
>>
>> class Individual
>> {
>> double I_;
>> double id_;
>> public:
>> double getId() const;
>
> I understand I_ is a std:string rather than a double, right?

Actually, id_ is a std::string. I_ is a double.

>> double getI() const;
>> void setId(const std::string id);
>> void setI(const double I);
>> }
>>
>> [...]
>>
>> I have an algorithm that works on these data, using Individual::I
>> to calculate a summary value across the
>> whole dataset. An Individual i is then chosen at random, and i.I
>> updated using the multiindex::modify
>> method with a functor:
>>
>> struct modifyI
>> {
>> modifyI(double newI) : newI_(newI) {}
>> void operator()(Individual& i)
>> {
>> i.setI(newI_);
>> }
>> private:
>> double newI_;
>> };
>>
>> This calculation is then repeated many times. The actual calculation
>> is done in parallel using MPI (Boost::MPI on top of OpenMPI), with the
>> final reduction being broadcast to all processes. This enables
>> each processor to make the same change to its copy of the multiindex.
>> In *theory* this should mean that each process has a complete
>> replicate of the multiindex.
>
> Everything about the scenario you describe looks perfectly
> normal except this. Are you sure no container instance is
> accessed simultaneously from two different threads?
>
> You can do the following sanity check: wrap each access to
> a container with a mutex guard and see whether the problem
> persists. If not, your assumption above is incorrect. If
> the sanity check unveils nothing I'll ask you for more info
> on your program.

Yes, I'm absolutely sure that I'm not getting a thread problem.

>
> Also, you can turn the so-called invariant-checking mode on:
>
> http://www.boost.org/libs/multi_index/doc/tutorial/debug.html#invariant_check
>
> This will hopefully locate the exact point where corruption
> occurs, which might help you find out what's going wrong.

I realised that I had a misbehaving function that was writing garbage to the multiindex, and appeared to be causing the corruption. I've yet to sort this out (for now, I've abandoned the function) because I've been busy doing other things, but I'll return to it soon and post some contextual info. Sorry for wasting time! I hope it's interesting that this phenomenon is occurring due to garbage being written...?

Thanks for your help!

Chris


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net