This module provides meta-predicates to distribute work over multiple threads. This module provides meta-predicates to distribute work over multiple threads. The simplest meta-predicate horde/[1,2] collects the results of the spawned threads and leaves the work distribution to the spawned threads itself. The other predicates distribute work items among the spawned threads, but do this only on a local scale.Example:
?- balance(between(1,10,X), Y is X*X). X = 1, Y = 1 ; X = 3, Y = 9 ; Etc..
The meta-predicates balance/[2,3] and setup_balance/[3,4] allow work distribution of a gen-erate and test. The meta-predicates might change the order of the result set. If the meta-predicates are cancelled by a cut such as in a surrounding \+/1 or once/1 they will automatically cancel each spawned thread.
The meta-predicates balance/[2,3] and setup_balance/[3,4] assume a side effect free interac-tion between the generate and test. The only channels are the variables in the intersection of the generate and test and the instantiations are copied. Currently the copying doesn't support attribute variables.
The setup in the meta-predicates setup_balance/[3,4] is executed once per spawned thread. The setup is executed before the test and attribute variables can communicate between the setup and the test. The setup can for example be used to build a CLP(FD) model and the model will be available in the test for labelling.
The following work distribution predicates are provided: