1. Translation error (out of memory)
- Posted by Lnettnay Aug 30, 2017
- 1984 views
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...
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
2. Re: Translation error (out of memory)
- Posted by Senator Aug 31, 2017
- 1862 views
Your sum test code compiles and runs without fail on my Ubuntu 16.04 LTS system running OpenEuphoria 4.1.
Regards, Ken Rhodes
3. Re: Translation error (out of memory)
- Posted by Lnettnay Aug 31, 2017
- 1926 views
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
4. Re: Translation error (out of memory)
- Posted by Lnettnay Sep 04, 2017
- 1809 views
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"
Lonny
5. Re: Translation error (out of memory)
- Posted by Senator Sep 05, 2017
- 1802 views
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
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"
Lonny
6. Re: Translation error (out of memory)
- Posted by jmduro Sep 05, 2017
- 1800 views
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
7. Re: Translation error (out of memory) [long post ahead]
- Posted by Lnettnay Dec 14, 2017
- 1605 views
Hi peoples,
I'm back. This has been driving me nuts.
This is what I think I know.
I made a few changes while testing
-- call this s1.ex atom sum, exits, tstart = time() constant limit = 1_073_741_825 -- power(2, 30) + 1 exits = 0 for i = 1 to limit do exits += 1 sum = 0 for j = i to limit do sum += j if sum > limit then -- prints out every 1000 times through the loop if remainder(exits, 1000) = 0 then ? exits end if 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")
That works when compiled. euc -gcc -con -makefile s1.ex I put the -makefile so I could look at the generated code without having to cd to the source directory.
-- call this one s2.ex atom sum, exits, tstart = time() constant limit = 1_073_741_825 -- power(2, 30) + 1 exits = 0 for i = 1 to limit do exits += 1 sum = 0 -- change the loop to limit + 0 for j = i to limit + 0 do sum += j if sum > limit then -- prints out every 1000 times through the loop if remainder(exits, 1000) = 0 then ? exits end if 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 compiled it using euc -gcc -con -makefile s2.ex
And it gives me the same error:
couldn't alloc 16384 bytes Fatal run-time error: Your program has run out of memory. One moment please...
The only difference is adding 0 to the limit (I also tried multiplying by 1). So I looked at the generated code.
/** for j = i to limit do*/ //line below in main-.c for s2.ex _11 = NewDouble(DBL_PTR(_1limit_144)->dbl + (double)0);
Looking at the Windows task manager the memory used goes up until it hits 2000M and then it crashes. The number of exits printed is ~131M which is about 16 bytes per exit.
I also don't understand this
/** exit*/ goto L4; // [83] 117 goto L6; // [85] 110
If i comment out this line
_11 = NewDouble(DBL_PTR(_1limit_144)->dbl + (double)0);and change the test here
if (binary_op_a(GREATER, _1j_150, _11)){ to if (binary_op_a(GREATER, _1j_150, _1limit_144)){it runs correctly.
Or if I move this
DeRef1(_11); _11 = NOVALUE;from its original location after the L2: label to the L4: label and compile it works also.
I have no idea how to fix this in the translator. I can't even find a file that looks like it compiles to euc.exe
That's all folks, Lonny