Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ackermann benchmark aborts #97

Open
doug719 opened this issue Apr 26, 2021 · 6 comments
Open

ackermann benchmark aborts #97

doug719 opened this issue Apr 26, 2021 · 6 comments

Comments

@doug719
Copy link

doug719 commented Apr 26, 2021

The highly recursive ackermann function is a standard lisp benchmark. (ack 2 5) runs on all of the scheme implementations that I have tried (about 7). I compiled a version of sbcl with
--dynamic-space-size=16Gb
and then compiled a version of shen.
With the release shen binary (22.2), and also my version of shen, (ack 2 5) results in
"
(3-) (ack 2 5)
INFO: Control stack guard page unprotected
Control stack guard page temporarily disabled: proceed with caution

debugger invoked on a SB-KERNEL::CONTROL-STACK-EXHAUSTED in thread
#<THREAD "main thread" RUNNING {1001720103}>:
Control stack exhausted (no more space for function call frames).
This is probably due to heavily nested or infinitely recursive function
calls, or a tail call that SBCL cannot or has not optimized away.

@tizoc
Copy link
Member

tizoc commented Apr 26, 2021

@doug719 being able to look at the code you are running would be helpful.

I'm almost sure SBCL supports TCO when compiled with the correct optimization settings (Shen/SBCL is compiled with (proclaim '(optimize (debug 0) (speed 3) (safety 3)))).

Have you tried with Shen/Scheme ? does it work?

@tizoc
Copy link
Member

tizoc commented Apr 26, 2021

There is some info here: https://0branch.com/notes/tco-cl.html#sec-2-2

I haven't tried the options, but if you compiler Shen yourself you can experiment with these settings by changing boot.lsp.

@doug719
Copy link
Author

doug719 commented Apr 26, 2021 via email

@tizoc
Copy link
Member

tizoc commented Apr 26, 2021

@doug719 just tried in Shen/Scheme and it works fine. But you may want to measure it anyway, it would be interesting to know how it compares to Chez Scheme (since it is the underlying compiler it uses).

The function is not fully tail-recursive, so that means that the real problem is that by default SBCL's stack size is too low (I checked, it is 2MB).

Try changing this on the shen-cl Makefile:

https:/Shen-Language/shen-cl/blob/c26776641fe4b63aacfbc6013fad9c1c16974a5e/Makefile#L166-L168

to

.PHONY: build-sbcl
build-sbcl:
	$(SBCL) --control-stack-size 8 --load boot.lsp

That will set the stack size to 8MB.

@tizoc
Copy link
Member

tizoc commented Apr 26, 2021

Btw, tested it myself and I was able to execute (ack 2 5) without a stack overflow on Shen/SBCL.

@doug719
Copy link
Author

doug719 commented Apr 26, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants