tags:

views:

695

answers:

2

Edit: For those of you looking for an answer to the question as stated the standard limits the number of nested loops at compile time. At runtime this is a different issue as the only limit would be the size of the program segment.

Solved: I was looking too early on in the build process. The c file gets further preprocessing applied to it. Off to the subsequent steps.

I have a problem with c code generated via perl from a language that applies rules for generating pronunciation. In essense the input is a huge dictionary of exceptions for pronounciation rules. The code is riddled with gotos and it worked up until one of the exception dictionaries reached 23K rules.

The code is basically unreadable but I have managed to make the c code compile after removing what appears to be the 6200th nested loop:

for (dictionionary1=seed1;dicitonary1<limit1;dictionary1++)
{
    for (dictionionary2=seed2;dicitonary2<limit2;dictionary2++)
    {
           /* .... */
        for (dictionionary6199=seed6199;dicitonary6199<limit6199;dictionary6199++)
        {
               /* two hundred more removed adding one makes it not compile */

        }

    }
}

Both gcc and xlC are able to handle these but aCC 3.73 (on H11.23 PA RISC) is puking.

Compiling /home/ojblass/exception_dictionary_a.c...
Loading the kernel...
Pid 18324 killed due to text modification or page I/O error
/bin/ksh: 28004 Bus error(coredump)
*** Error exit code 138

I have found this link and tried many of the suggested fixes without success.

For legacy reasons I have to compile for 32 bit (it uses a 32 bit library that I have no 64 bit counterpart for).

maxdsiz = 256 MB (x10000000) tried up to 4 GB
maxssiz = 16 MB (x1000000) tried up to 100MB
maxtsiz = 256 MB (x10000000) tried up to 1 GB

Any suggestions at compiler settings or a good link for documetation for aCC 3.73? I am drowning in search results.

I have coded a workaround breaking the dictionary into two parts resulting in dictionary_an.c and dictionary_az.c. I have had to touch some core logic I don't feel comfortable touching in order to pull this off and I was hoping to back down to the original configuration.

+1  A: 

Pid 18324 killed due to text modification or page I/O error

Sounds like a stackoverflow^Wmemory error to me. That would mean it's a bug in the compiler. I don't speak HPUX so I might be wrong, but opening a ticket with HP might yield more information.

David Schmitt
+5  A: 

Wow - I know it's no help to you, but nesting 6199 levels deep is well in excess of what C or C++ require (15 for C90, 127 for C99 and 256 for C++).

What I'm curious about is how well that thing runs - if your dictionaries are of any size, the number of loop iterations must be astronomical. Say each dictionary size is 10: (10 ^ 6199) is quite a large number. Even if there are only 2 items per dictionary, (2 ^ 6199) is impressive as well.

Michael Burr
I cannot speak to this peice but the overall system generates speech at approximately 16 times realtime. In some analysis the sound selectin and wave smoothing of the final speech system dwarfs the runtime of the pronunciation component by a factor of 2400 to 1. I stripped a lot of code out (large number of goto statments) that probably decrease the complexity by a huge amount. Unfortunately I am sitting upon some things I don't quite get.
ojblass
Maybe the gotos and things mean it doesn't actually take terribly long. But it's ludicrous code, anyway.
Artelius
I don't envy you - trying to fix generated code or code generators can be a nightmare.
Michael Burr
I am curious about the 256 limit of C99 would that not imediately choke any sort of recursive algorithm that used for loops because calling a for loop in a nested function is no different than this in some sense.
ojblass
The limits given are the *minimums* the standards require that a compiler support. But in any case, they don't really apply to a program using recursion - that's a runtime thing, not a compile-time thing.
Michael Burr
You know what... there is another step in the build process... I think I am working with the wrong peice here...
ojblass
The end to end process works on gcc and xlC... maybe this part won't work on those compilers either?
ojblass
DOH! This is not the real problem... of to awk hell (serious awk hell (really serious awk hell (no really really serious awk hell)))
ojblass
@objblass: No, recursive algorithms are no problem. It is only the "syntactic" nesting depth that matters, basically how deep the parser is required to go when parsing a function. Whenever you call another function, the nesting depth becomes irrelevant (because the function you're calling is parsed separately, starting from a nesting depth of 0). So the limit only applies to how many loops can be nested directly inside each others inside a single function.
jalf
I think I knew that at some point... aik I am choking on labels :(
ojblass
wooohooo THANK YOU!
ojblass