Segmentation fault in lagged fibonacci random number generator
Dear boost users, I have a very strange segmentation fault in lagged fibonacci and unfortunately, I was not able to reduce the problem to a simple example yet. I know that stinks of the problem coming from my code but please bear with me for a moment. I have two classes that both use the same other class for some random number generation. The two classes differ only in one unrelated function. If I run my program with one class everything works just fine, if I run it with the other after a few iterations the error occurs. I have no idea why, since they both use the exact same class from which the error occurs. I use the following code to get my generators: typedef boost::uniform_smallint<short unsigned> Small; typedef boost::variate_generator<rfn::RandGen&, Small> Small_Number; Small* _us_dist = new Small(1, 20); Small_Number* _len_gen = new Small_Number(rfn::Mutation::_parameters->rng(), *_us_dist); Where rfn::Mutation::_parameters->rng() gives me a reference from a lagged_fibonacci object held in that class. I then try to get a number in the following way: short unsigned length = (*_len_gen)(); I have attached a gdb run of the program crashing. If you have any ideas where I can look for this error please tell me. It's also no problem for me to send you the complete sources but it's a rather big project. Thank you for your help, Moritz
AMDG Moritz Beber wrote:
I have a very strange segmentation fault in lagged fibonacci and unfortunately, I was not able to reduce the problem to a simple example yet. I know that stinks of the problem coming from my code but please bear with me for a moment.
I have two classes that both use the same other class for some random number generation. The two classes differ only in one unrelated function. If I run my program with one class everything works just fine, if I run it with the other after a few iterations the error occurs. I have no idea why, since they both use the exact same class from which the error occurs.
Are you overflowing the stack? Pseudo-random number generators can be rather large. In Christ, Steven Watanabe
On 20/07/10 21:23, Steven Watanabe wrote:
AMDG
Moritz Beber wrote:
I have a very strange segmentation fault in lagged fibonacci and unfortunately, I was not able to reduce the problem to a simple example yet. I know that stinks of the problem coming from my code but please bear with me for a moment.
I have two classes that both use the same other class for some random number generation. The two classes differ only in one unrelated function. If I run my program with one class everything works just fine, if I run it with the other after a few iterations the error occurs. I have no idea why, since they both use the exact same class from which the error occurs.
Are you overflowing the stack? Pseudo-random number generators can be rather large.
In Christ, Steven Watanabe
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
@Matthias: I don't think that's the problem. First of all, it works perfectly in one case and second, rng() returns a reference to a static class member. @Steve: As usual you might be on to something. If this is off-topic, please tell me to go somewhere else with my question. Checking the program's size showed the values to be constant but nevertheless you did make me check it in valgrind which is where I found the error. Thank you both for your quick replies, Moritz
On 20 Jul 2010, at 13:08, Moritz Beber wrote:
Dear boost users,
I have a very strange segmentation fault in lagged fibonacci and unfortunately, I was not able to reduce the problem to a simple example yet. I know that stinks of the problem coming from my code but please bear with me for a moment.
I have two classes that both use the same other class for some random number generation. The two classes differ only in one unrelated function. If I run my program with one class everything works just fine, if I run it with the other after a few iterations the error occurs. I have no idea why, since they both use the exact same class from which the error occurs.
I use the following code to get my generators:
typedef boost::uniform_smallint<short unsigned> Small; typedef boost::variate_generator<rfn::RandGen&, Small> Small_Number;
Small* _us_dist = new Small(1, 20); Small_Number* _len_gen = new Small_Number(rfn::Mutation::_parameters->rng(), *_us_dist);
Where rfn::Mutation::_parameters->rng() gives me a reference from a lagged_fibonacci object held in that class.
I then try to get a number in the following way:
short unsigned length = (*_len_gen)();
I have attached a gdb run of the program crashing. If you have any ideas where I can look for this error please tell me. It's also no problem for me to send you the complete sources but it's a rather big project.
Could it be a lifetime problem, i.e. is the object returned by fn::Mutation::_parameters->rng() destroyed before your call? One way to check is to define Small_Number as boost::variate_generator<rfn::RandGen, Small> (note there is no & after RandGen). That way the generator is copied. Matthias
participants (3)
-
Matthias Troyer
-
Moritz Beber
-
Steven Watanabe