How to extend maximum of main thread count over 1G?

I’m using: SWI-Prolog version (threaded, 64 bits, version 9.0.4)

I have quite lot of predicates, and I need more, but at a certain threshold the thing starts not working for me. (It does not send any message…) It seems I run out of “main threads”…

Presumably you’re reaching the stack size limit. You can confirm by running:

current_prolog_flag(stack_limit, Limit).

If that is the case, you can increase it:

https://www.swi-prolog.org/FAQ/StackSizes.html

Stack size, being 1G by default is also my impression. The report suggests otherwise though. Surely, the number of clauses is not limited other than by memory. I’ve used SWI-Prolog with enough clauses to fill about 200Gb :slight_smile:

Considering that CPU usage drops to zero, it seems to be wait for something. As all seems to be running in the main thread, try Control-C and if it prompts try g to get a backtrace.

Thank You everyone for the hints with stacksize extension. It helped me in some extent. I use now 500G stack size:

cll:- set_prolog_stack(global, limit(500 000 000 000)), set_prolog_stack(trail, limit(500 000 000 000)),
set_prolog_stack(local, limit(500 000 000 000)), sudoku.

sudoku:-
a11(A11),
a12(A12),A11==A12,
a13(A13),A13==A11,A13==A12,
a21(A21),A21==A11,A21==A12,A21==A13,
a22(A22),A22==A11,A22==A12,A22==A13,A22==A21,
a23(A23),A23==A11,A23==A12,A23==A13,A23==A21,A23==A22,
a31(A31),A31==A11,A31==A12,A31==A13,A31==A21,A31==A22,A31==A23, …

and it helped to extend the problem search space from f32, to almost the end of g33
but hier - I think I encountered a different limit… I attach an explanation…

so I am affraid… I have to find another solution… :frowning:

No clue what that means. The OP’s problem does not involve threads though.

Surely keeping locks for indefinite time can deadlock the system. This lock is (only) used to avoid a race condition when the log stream is opened lazily. Locks should typically not be the first choice. Also in this case, it might have been a better design to have a log thread that writes the file and send messages to this thread :slight_smile:

This prints :slight_smile:

77 ?- set_prolog_stack(global, limit(500 000 000 000)).
Warning: set_prolog_stack/2: limit(Size) sets the combined limit.
Warning: See https://www.swi-prolog.org/changes/stack-limit.html
true.

Library clpfd? See SWISH -- SWI-Prolog for SHaring

To some extend you can address it. In this case the server is addressed by the port it listens on. See e.g., http_workers/2.

The “hence” is a bit dubious. The above are barely useful for these purposes. For that there is the libssh based login, after which you can inspect and modify a lot. Note that SWI-Prolog provides safe hot reloading of code, i.e., you can reload source files that are at that moment actively used by the server threads as log as you do not change the predicate signatures (number or meaning of arguments). That means you can add, delete or modify clauses of any predicate. That allows for adding debug/3 statements. Only, all this stuff applies to all servers in the process as you address the (probably shared) code, not a particular server. But, you can debug and modify the code behind an HTTP location, you can add or remove locations, modify authentication, etc. All without restarting the server.

1 Like