crash in MonteCarlo integration
Status: Beta
Brought to you by:
aerpenbeck
When using many iterations in MonteCarlo integration,
the program crashes from time to time:
---
p2 = Proc.new {|k, p|
p / (1.0 - cos(k[0]) * cos(k[1]) * cos(k[2]))
}
a = 1.0 / (M_PI * M_PI * M_PI)
dim = 3
f = Function.new dim, a, p2
plain = Plain.new dim
xl = [0.0, 0.0, 0.0]
xu = [M_PI, M_PI, M_PI]
calls = 10000
rng = Random::RNG.new
r = plain.integrate f, xl, xu, calls, rng
result = r[0]
abserr = r[1]
---
Crash occurs in Monte.c (MFunction_function) when the
call to the Proc object is made (rb_funcall).
I suspect it is something with the memory management.
Probably the COPYCARRAY/COPYRUBYARRAY macros
do some harm if called too often.
BTW: Could this be a Ruby problem (see attached file)?
Logged In: NO
I tried to reproduce this bug but cannot; I increased the
calls parameter to
10000000 (ten million) and still no crash. I wonder if it
works on my system
because I have the latest Ruby checked out from the CVS tree?
Logged In: YES
user_id=756654
BTW that above testing comment is by Rudi, me, I wasn't
logged in.
Logged In: YES
user_id=755035
It's strange, because sometimes it runs fine on my machines,
and sometimes it crashes. Also, if I put in some debug
output, it never crashes...
Maybe someone from the Ruby community knows some
help, I will check.
Logged In: YES
user_id=755035
I replaced the macro COPYCARRAY and now it seems to work.