L
lloyd
My program enumerates arrangements of a specified combinatorial
object, at different orders. It's recursive and has to go pretty deep.
If I invoke it with the "quick" flag, then instead of telling me how
many arrangements of the object there are at a particular order, it
just tells me as soon as it finds *any*, and exits--this gives me a
quick answer about existence, when I don't care how many solutions
there are (which is sometimes lengthy to compute). The way I
implemented this is by using the solution counter, which is a global
variable: I run a comparison at the head of each loop and if
num_solutions > 0 then I break, and the program surfaces from all the
recursed inner function calls that way.
At least that's how it's supposed to work. And I spent hours trying to
find why it didn't break out and end after finding a solution, as I
was sure my code was sound. In the end I happened to remember a
similar problem I'd had once, where compiling at a different
optimisation changed some detail of how the program worked, and when I
compiled it (with gcc) using -O2 it worked as it was supposed to. Very
frustrating!
I can't possibly paste the code here as it is too nasty, and it would
take a lot of work to get it down to minimum size. But I thought I'd
ask if anyone knows this issue, and whether it is likely to be a bug
in my code, or something badly phrased that -O2 somehow accidentally
fixes, or whether it's more likely to be a bug in gcc as invoked
without optimisation.
Thanks! --Lloyd
object, at different orders. It's recursive and has to go pretty deep.
If I invoke it with the "quick" flag, then instead of telling me how
many arrangements of the object there are at a particular order, it
just tells me as soon as it finds *any*, and exits--this gives me a
quick answer about existence, when I don't care how many solutions
there are (which is sometimes lengthy to compute). The way I
implemented this is by using the solution counter, which is a global
variable: I run a comparison at the head of each loop and if
num_solutions > 0 then I break, and the program surfaces from all the
recursed inner function calls that way.
At least that's how it's supposed to work. And I spent hours trying to
find why it didn't break out and end after finding a solution, as I
was sure my code was sound. In the end I happened to remember a
similar problem I'd had once, where compiling at a different
optimisation changed some detail of how the program worked, and when I
compiled it (with gcc) using -O2 it worked as it was supposed to. Very
frustrating!
I can't possibly paste the code here as it is too nasty, and it would
take a lot of work to get it down to minimum size. But I thought I'd
ask if anyone knows this issue, and whether it is likely to be a bug
in my code, or something badly phrased that -O2 somehow accidentally
fixes, or whether it's more likely to be a bug in gcc as invoked
without optimisation.
Thanks! --Lloyd