Boost logo

Boost Users :

Subject: Re: [Boost-users] [multiindex] Ordered index corruption
From: Joaquin M Lopez Munoz (joaquin_at_[hidden])
Date: 2011-07-21 16:33:55

Chris Jewell <chris.jewell <at>> writes:

> Hi All,

Hello Chris,

> 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?

> 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.

Also, you can turn the so-called invariant-checking mode on:

This will hopefully locate the exact point where corruption
occurs, which might help you find out what's going wrong.


Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at