Boost logo

Boost Users :

Subject: [Boost-users] Mersenne twister problem
From: ruya (rmlopes_at_[hidden])
Date: 2009-09-11 05:19:32


Hello

I've built a meta-heuristics library in which I use the boost random
library. I am using several independent generators through the application.
The problem is in the core of my library. The tricky part is that I have
three different algorithms using the core, all of them using the class where
a segmentation fault happens, but only one of them crashes when it tries to
use the class, the others run as expected. Gdb points to the boost library,
as you can see in the snippet bellow. I couldn't find any information on
this issue, and I cannot see something wrong with my code (the relevant part
is bellow).

The parent class where generators are declared:

template< class SType, typename MemP >
class SearchFunctor{
    (...)
  public:

    virtual SPtr operator()( SPtr s, int iter ) = 0;

    SearchFunctor(){
      (...)
      //This is how I initialize teh generators, being MASTER SEED 666
      generator1 = base_generator_type(MASTER_SEED*13);
      uni_dist1 = boost::uniform_real<>(0,1);
      uniEmp = new GeneratorI(generator1, uni_dist1);
      generator2 = base_generator_type(MASTER_SEED*17);
      uni_dist2 = boost::uniform_real<>(0,1);
      uniRes = new GeneratorI(generator2, uni_dist2);
    }
  protected:
    base_generator_type generator1, generator2;
    boost::uniform_real<> uni_dist1, uni_dist2;
    GeneratorI* uniEmp;
    GeneratorI* uniRes;
};

The derived class using the generators:

template< class SType, typename MemP >
struct SwapSearch : public SearchFunctor<SType,MemP>{
   typedef SearchFunctor<SType,MemP> Parent;
   (...)
    
  SPtr operator()( SPtr s, int iter ){
      assert(s != NULL);
      assert(s->GetDomain()!= NULL);
      assert(s->GetDomain()->GetTotalEntities()>1);
      (...)
      d1 = (*Parent::uniEmp)() * (s->GetDomain()->GetTotalEntities()-1);
      d2 = (*Parent::uniEmp)() * (s->GetDomain()->GetTotalEntities()-1);
      (...)
      return 0;
  }
};

The output of the debugger has a lot of lines because of meta-programming
but starts and finishes with this:
#0 0x08071a57 in brickheuristics::SwapSearch (...)
(...) at /usr/include/boost/random/mersenne_twister.hpp:279
279 UIntType z = x[i];

Thanks

-- 
View this message in context: http://www.nabble.com/Mersenne-twister-problem-tp25382114p25382114.html
Sent from the Boost - Users mailing list archive at Nabble.com.

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