SWI-Prolog sometimes allocates more global stack than specified with the -G option.
For example, with euler_172.pl on a 64-bit machine (tested with Debian 8.1 and OSX Yosemite), I get:
$ swipl -f euler_172.pl -G5M
Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 7.3.2)
Copyright (c) 1990-2015 University of Amsterdam, VU Amsterdam
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.
For help, use ?- help(Topic). or ?- apropos(Word).
?- run(7), statistics.
len_num(7, 8754480).
% Started at Tue Jul 14 23:24:16 2015
% 2.500 seconds cpu time for 13,823,938 inferences
% 6,860 atoms, 4,208 functors, 3,250 predicates, 57 modules, 153,713 VM-codes
%
% Limit Allocated In use
% Local stack: 268,435,456 61,440 1,832 Bytes
% Global stack: 5,242,8806,287,344 1,344 Bytes
% Trail stack: 268,435,456 2,095,096 2,632 Bytes
%
% 130 garbage collections gained 148,676,256 bytes in 0.471 seconds.
% Stack shifts: 2 local, 11 global, 10 trail in 0.001 seconds
% 1 threads, 0 finished threads used 0.000 seconds
len_num(18, 227485267000992000).
% Started at Mon Jul 13 11:42:12 2015
% 35257.269 seconds cpu time for 113,872,091,044 inferences
% 6,174 atoms, 3,962 functors, 3,205 predicates, 52 modules, 147,218 VM-codes
%
% Limit Allocated In use
% Local stack: 268,435,456 126,976 1,792 Bytes
% Global stack: 27,917,287,42434,359,734,256 14,435,913,504 Bytes
% Trail stack: 4,294,967,296 4,294,965,240 2,256 Bytes
%
% 589 garbage collections gained 1,465,242,723,928 bytes in 13010.921 seconds.
% Stack shifts: 2 local, 32 global, 27 trail in 0.411 seconds
% 1 threads, 0 finished threads used 0.000 seconds
Such exceeding allocations can lead to unexpected OS swapping and also to unexpected termination of the process (or other processes) even in situations where there would have been enough RAM to perform the intended computation within the specified stack limits.
If possible, please throw a Prolog exception instead of exceeding the specified limits. Thank you!
SWI-Prolog sometimes allocates more global stack than specified with the -G option.
For example, with euler_172.pl on a 64-bit machine (tested with Debian 8.1 and OSX Yosemite), I get:
A slightly more extreme example is:
Yielding:
Such exceeding allocations can lead to unexpected OS swapping and also to unexpected termination of the process (or other processes) even in situations where there would have been enough RAM to perform the intended computation within the specified stack limits.
If possible, please throw a Prolog exception instead of exceeding the specified limits. Thank you!