1. Translation error (out of memory)

From the book Puzzled Programmers: 15 Mind-Boggling Story Puzzles to Test Your Programming Prowess : Solutions in Basic, Pascal, and C Jun 1987 by Michael Wiesenberg

Find a series of numbers that add up to a specific number. In the book the number was 10000. With the slowest brute force solution it takes 0.00000 seconds. So I increased the number to 1234567890. That takes a lot longer (794.718 seconds).

Here's the program

atom sum, tstart = time() 
 
constant limit = 1_234_567_890 
 
for i = 1 to floor(limit/2) do 
    sum = 0 
    for j = i to floor(limit/2) + 1 do 
        sum += j 
        if sum > limit then 
            exit 
        elsif sum = limit then 
            printf(1, "from %d to %d adds up to %d\n", {i, j, limit}) 
        end if 
    end for 
end for 
printf(1, "%f seconds\n", time() - tstart) 
puts(1, "all done\n") 

I wanted to see how much of a speed increase I would get by compiling so I did
euc -gcc -con sumtest.ex
and ran it again.
I got the following result


from 102880652 to 102880663 adds up to 1234567890
couldn't alloc 16384 bytes

Fatal run-time error:
Your program has run out of memory.
One moment please...

The interpreted run had 4 more solutions after the one shown.
I tried looking at the C code from the translator but I couldn't really make head or tails of it. I don't understand why it would be allocating more memory, especially 16K. I tried rebooting to possibly remedy memory fragmentation that might have caused the problem but that didn't help any (I didn't really think it would). i tried increasing the stack size but it didn't help.
I messed around some with the target number and discovered that if the number is at or below the integer limit (2^30 - 1) then it completes the run. If it is at or above the integer limit it aborts.

Looking at the generated C code I did notice a difference in that there are a lot of binop and NewDouble calls. Is it possible there is a memory leak?

I changed the for-next loops to while loops and it completed.
I'm stumped.

Lonny

new topic     » topic index » view message » categorize

2. Re: Translation error (out of memory)

Your sum test code compiles and runs without fail on my Ubuntu 16.04 LTS system running OpenEuphoria 4.1.

Regards, Ken Rhodes

new topic     » goto parent     » topic index » view message » categorize

3. Re: Translation error (out of memory)

I wonder if Linux makes the difference or is it because you're running 4.1. What would also be interesting is to see if Linux and Windows generate the same C code for the same version of EU. I think I'll try looking at the code generated for a cross compile and look for a difference.

Thanks for your input.

Lonny

new topic     » goto parent     » topic index » view message » categorize

4. Re: Translation error (out of memory)

Hi Ken,

I installed Virtual Box and Ubuntu 16.04. Then I installed Euphoria 4.0.5. When I tried to compile the program I got an error 'file not found' sys/cdefs.h which is in the x86_64-linux-gnu directory. I made a sys directory in /usr/include and put a symlink to cdefs.h there. Then when I tried again I got 'file not found' bits/wordsize.h.

Is there a way to symlink the whole x86_64-linux-gnu directory or put in the include path so I don't have to trace these errors down 1 by 1.

  • Kirk voice "There must be a way" smile

Lonny

new topic     » goto parent     » topic index » view message » categorize

5. Re: Translation error (out of memory)

Sorry, Lonny, I haven't a clue about symlinks and such. Perhaps one of the Linux Guru's will catch the thread and chime in with a fix.

Good Luck

Lnettnay said...

Hi Ken,

I installed Virtual Box and Ubuntu 16.04. Then I installed Euphoria 4.0.5. When I tried to compile the program I got an error 'file not found' sys/cdefs.h which is in the x86_64-linux-gnu directory. I made a sys directory in /usr/include and put a symlink to cdefs.h there. Then when I tried again I got 'file not found' bits/wordsize.h.

Is there a way to symlink the whole x86_64-linux-gnu directory or put in the include path so I don't have to trace these errors down 1 by 1.

  • Kirk voice "There must be a way" smile

Lonny

new topic     » goto parent     » topic index » view message » categorize

6. Re: Translation error (out of memory)

Lnettnay said...

I wonder if Linux makes the difference or is it because you're running 4.1. What would also be interesting is to see if Linux and Windows generate the same C code for the same version of EU. I think I'll try looking at the code generated for a cross compile and look for a difference.

Thanks for your input.

Lonny

On 4.1 (the one with memstruct) euc -gcc -con sumtest.ex fails with dozens of errors (too much to be kept in the console buffer). Here are some:

main-.h:531:8: error: unknown type name 'uint8_t' 
 extern uint8_t *poke_addr; 
        ^~~~~~~ 
main-.h:532:8: error: unknown type name 'uint16_t' 
 extern uint16_t *poke2_addr; 
        ^~~~~~~~ 
main-.h:533:8: error: unknown type name 'uint32_t' 
 extern uint32_t *poke4_addr; 
        ^~~~~~~~ 
main-.h:534:8: error: unknown type name 'uint64_t' 
 extern uint64_t *poke8_addr; 
        ^~~~~~~~ 
main-.h:535:8: error: unknown type name 'uintptr_t' 
 extern uintptr_t *pokeptr_addr; 
        ^~~~~~~~~ 
In file included from struct.h:6:0, 
                 from init-.c:4: 
c:/euphoria/include/euphoria.h:30:8: error: redefinition of 'struct s1' 
 struct s1 { 
        ^~ 
In file included from struct.h:6:0, 
                 from init-.c:4: 
c:/euphoria/include/euphoria.h:37:8: error: redefinition of 'struct d' 
 struct d { 
        ^ 
In file included from struct.h:6:0, 
                 from init-.c:4: 
c:/euphoria/include/euphoria.h:42:8: error: redefinition of 'struct routine_list' 
 struct routine_list { 
        ^~~~~~~~~~~~ 
 
In file included from struct.h:6:0, 
                 from init-.c:4: 
c:/euphoria/include/euphoria.h:80:20: error: conflicting types for 'd_ptr' 
 typedef struct d  *d_ptr; 
                    ^~~~~ 
In file included from main-.h:1:0, 
                 from init-.c:2: 
c:/euphoria/include/euphoria.h:80:20: note: previous declaration of 'd_ptr' was here 
 typedef struct d  *d_ptr; 
                    ^~~~~ 
init-.c:1851:32: error: expected ')' before numeric constant 
     _360 = NewDouble((eudouble)4.29496729600000000000e+009L); 
                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
Couldn't compile file 'init-.c' 
Status: 1 Command: gcc  -DEWINDOWS -fomit-frame-pointer -c -w -fsigned-char -O2 
-m32 -Ic:/euphoria -ffast-math init-.c 

Jean-Marc

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu